I am trying to write an Rspec test to test one of my controllers in Rails but I am having a problem getting the correct params hash.
My create method in my Activities Controller looks like this(The update method is identical). As you can see the params hash it receives has an :activity, :start_time, and :end_time hash.
def create
@activity = Activity.new(params[:activity])
@activity.start_time = to_interval(params[:start_time])
@activity.end_time = to_interval(params[:end_time])
respond_to do |format|
....
The rspec activities controller spec looks like
it "redirects to the activity" do
activity = Activity.create! valid_attributes
put :update, :id => activity.id, :activity => valid_attributes
response.should redirect_to(activity)
end
The second line calls valid attributes
def valid_attributes
FactoryGirl.attributes_for(:activity)
end
which returns a hash
{"id"=>"1", "name"=>"Some Activity1"}
and when the controller receives it the hash looks like
{"activity"=>{"id"=>"1", "name"=>"Some Activity1"}, "controller"=>"activities", "action"=>"create"}
As you can see the :start_time and :end_time hashes are missing. In the end I need a hash which looks like
{"activity"=>{"id"=>"1", "name"=>"Some Activity1"}, "start_time"=>{"hours"=>"1", "minutes"=>"0"}, "end_time"=>{"hours"=>"1", "minutes"=>"0"}, "controller"=>"activities", "action"=>"create"}
I cannot figure out the correct syntax for adding the :start_time and :end_time hashes to the params hash. I cannot combine it with the hash returned from FactoryGirl because the create method combines the three hashes into the form below which is incorrect because now :start_time and :end_time are embedded in the :activities hash.
{"activity"=>{"id"=>"1", "name"=>"Some Activity1", "start_time"=>{"hours"=>"1", "minutes"=>"0"}, "end_time"=>{"hours"=>"1", "minutes"=>"0"}}, "controller"=>"activities", "action"=>"create"}
Any help or hints are appreciated and I thank you for you time and help!!