I'm doing a controller spec in Rails 4, and I'm wanting to test the attributes of a record created by a controller action. How do I find the newly created record?
For example, what could I do instead of
it 'Marks a new user as pending' do
post :create, params
# I don't want to use the following line
user = User.last
expect(user).to be_pending
end
The Rails guides only briefly talks about controller tests, where it mentions testing that Article.count
changes by 1, but not how to get a new ActiveRecord model.
The question Find the newest record in Rails 3 is about Rails 3.
I'm reluctant to use User.last
, because the default sorting may be by something other than creation date.