On 21-Mar-2012, at 6:31 AM, Tyler DeWitt wrote: > 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) > end > > 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.reload > @user.stripe_customer_id.should_not be_nil > end > > 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. > > Thanks, > Tyler > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
It looks like that ought to work. The first thing I'd suggest is to ensure that your request is actually succeeding and not erroring out or getting redirected due to authentication. response.should be_ok Next, I'd confirm that the two users are the same (in spec & in the controller) by 'puts'ing the ids or something. Could you confirm that those two fairly common reasons these sorts of things usually fail for me don't apply? Then we can start looking at other possible issues. Also, I would probably be more specific in my assertion by doing @user.stripe_customer.should == Stripe::Customer.last.id Thanks, Srushti http://c42.in _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users