RSpec tests fails without factory_girl reload

I was having trouble getting one of my spec tests to pass until I forced a reload on the user object after an activation. I'm fairly new to BDD and rails, am I completely misusing factory girl in this instance? Should I have mocked something instead?

For reference I am using the sorcery gem for user activation.

describe "GET activate" do
  context "with valid attributes" do
    it "activates a new user" do
      user = FactoryGirl.create(:pending_user)
      expect {
        get :activate, id: user.activation_token
      }.to change{user.activation_state}.from("pending").to("active")


I think what's confusing here is how you are triggering activate vs. how you are trying to verify that it worked.

You're activating via the controller get :activate, but then validating via the model user.activation_state. reload is necessary in this case, because you have to reload the attributes from the database in order to see that activation_state has been changed from pending to active. get :activate has no affect on your user instance.

To make it more clear you could:

  1. Check for an activation result on the page that activate responds with or check a controller instance variable (there's probably an @user)
  2. Perform the activation from the model instead. I assume this could be a unit test that instead calls some user.activate(activation_token) method. Then, checking the user instance without reload will work.

Need Your Help

How to dump CALayer into CGImageRef?

objective-c cocoa core-animation core-graphics

I have some custom, CoreAnimation based UI. I'd like to implement mouse dragging of certain CALayers and I'd like to stick an image of dragged layer to the cursor. The problem is, that I can't get ...

inserting values in database sql server 2008 in mvc through javascript/


I want to insert the values in database in my MVC application but I am getting the values through javascript.Please tell me how shall I do ,is there any way through which we can handle javascript i...