1

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

1
  • 1
    Couldn't be that your calling :guest_value and :bar_value while your controller is checking params[:guestvalue] and params[:barvalue] (no underscore), could it? Commented Jul 10, 2012 at 0:53

1 Answer 1

2

Well you definitely need the curly braces for the command to do what you want (pass the arrays to the factorygirl function). Post the error and maybe I can help more?

reagan

Sign up to request clarification or add additional context in comments.

1 Comment

either :barvalue or guestvalue doesn't have the method .each, and I'm assuming it's because in the test you name them :bar_value and :guest_value. hope that helps

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.