0

This should be very simple to test, but for some reason my test is failing, please consider the following, model bit:

class User < ActiveRecord::Base def active! update_attribute(:active, true) end end 

controller :

def activate user = User.find_by_uuid(params[:id]) user.active! puts "id #{user.id}" end 

test :

describe 'activate user' do let(:user) { FactoryGirl.create(:user) } before do sign_in user visit activate_user_path(id: user.uuid) puts "id #{user.id}" end it 'should be true' do save_and_open_page user.active.should be_true end end 

This test fails :

expected: true value got: false 

But when I do it with browser, the user gets activated without problems. What am I doing wrong? This really looks like a sily test but still doesn't pass, I've spend more than one hour trying out different stuff, none of which worked.

1 Answer 1

2

The problem is that the spec still holds the User in the user variable that was created via FactoryGirl and does not know that is was changed in the database. Just reload the user and it should work:

it 'should be true' do save_and_open_page user.reload.active.should be_true end 

Btw. if active is a boolean you can also spec it this way (what reads much nicer):

user.reload.should be_active 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.