1

我正在尝试将额外的参数传递给 rspec 测试,因此(额外的参数是两个数组,guest_value 和 bar_value):

        it "should create an outing" do 
            lambda do 
                post :create, :outing => FactoryGirl.attributes_for(:outing), :guest_value => [55,66], :bar_value => [66,77]
            end.should change(Outing, :count).by(1)
        end 

但是,我的测试完全忽略了它们,就好像它们甚至不存在一样。

此外,语法:

                post :create, :outing => { FactoryGirl.attributes_for(:outing), :guest_value => [55,66], :bar_value => [66,77] }

引发错误:

NoMethodError:
   undefined method `each' for nil:NilClass

这是我的控制器代码的结果:

def create
@outing = Outing.new(params[:outing])

@outing.user_id = @user.id

if @outing.save 

    params[:guestvalue].each do |guest_id|
        @outing.add_guest(guest_id)
    end 

    params[:barvalue].each do |bar_id|
        @outing.add_bar(bar_id)
    end 

    TimeRange.create(:element_id => @outing.id, :element_type => 'outing', :start_time => params[:day][:start_time], :end_time => params[:day][:end_time])  

    flash[:notice] = "Outing created successfully!" 

    redirect_to @outing
else 
    flash[:notice] = "Error creating outing!"
    @outing = Outing.new
    render(new_outing_path)
end

结尾

4

1 回答 1

2

那么你肯定需要花括号来让命令做你想做的事情(将数组传递给 factorygirl 函数)。发布错误,也许我可以提供更多帮助?

里根

于 2012-07-10T00:39:40.217 回答