Reloading an object not working in rspec
- by Eric Baldwin
I am trying to test a controller method with the following code:
it "should set an approved_at date and email the campaign's client" do
@campaign = Campaign.create(valid_attributes)
post :approve, id: @campaign.id.to_s
@campaign.reload
@campaign.approved_at.should_not be(nil)
end
However, when I run this test, I get the following error:
Failure/Error: @campaign.reload
ActiveRecord::RecordNotFound:
Couldn't find Campaign without an ID
When I run the analagous lines in the rails console, the reload works and the value is set as I need it to be. Why isn't reload working for me when I run the code in an rspec test?