Reloading an object not working in rspec
Posted
by
Eric Baldwin
on Stack Overflow
See other posts from Stack Overflow
or by Eric Baldwin
Published on 2013-07-01T00:40:40Z
Indexed on
2013/07/01
4:21 UTC
Read the original article
Hit count: 152
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?
© Stack Overflow or respective owner