[rspec-users] Testing Model Attributes That Are Updated In a Controller

Tyler DeWitt tyler.scott.dewitt at gmail.com
Wed Mar 21 01:01:08 UTC 2012

I've got a controller that updates some attributes of a model:

def confirmation
    @cart = current_cart
    customer = Stripe::Customer.create(description: current_user.email, card: params[:stripeToken])
    current_user.update_attributes(stripe_customer_id: customer.id)

In my spec, how can I ensure the current_user has a stripe_customer_id after this controller is run?

I have this:

it "should create a stripe customer and save that to the stripe_customer_id of the user" do
  @user.stripe_customer_id.should_not be_nil

But it doesn't work (I tried @user.reload because the database is being updated by the call to current_user.update_attributes).

@user is a FactoryGirl created object further up in the test.


More information about the rspec-users mailing list