I'm trying to pass extra parameters to an rspec test, as such (the extra paramaters are two arrays, guest_value and 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 However, my test completely ignores them, as though they're not even there.
Additionally, the syntax:
post :create, :outing => { FactoryGirl.attributes_for(:outing), :guest_value => [55,66], :bar_value => [66,77] } kicks up an error:
NoMethodError: undefined method `each' for nil:NilClass which is a result of my Controller code:
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 end
:guest_valueand:bar_valuewhile your controller is checkingparams[:guestvalue]andparams[:barvalue](no underscore), could it?