我正在尝试将额外的参数传递给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
端
答案 0 :(得分:2)
嗯,你肯定需要花括号来执行你想要的命令(将数组传递给factorygirl函数)。发布错误,也许我可以提供更多帮助?
里根