So I'm testing one of my controller in RSPEC and I'm trying to test the whole update shenanigans. This is what i have in the RSPEC
describe 'PUT update' do
before :each do
@user = Factory(:user,name: "Lawrence Smith")
end
context "valid attributes" do
it "located the requested @user" do
put :update, :id => @user, user: Factory.attributes_for(:user)
assigns(:user).should eq(@user)
end
it "changes @user's attributes" do
put :update, :id=> @user.id, user: Factory.attributes_for(:user, name: "Larry Smith")
@user.reload
@user.name.should eq("Larry Smith")
end
end
And this is what i have in the controller
def update
#update and save
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
sign_in @user
format.json{render :json => @user ,:status => :created, :location => @user }
else
format.json { render :json => @user.errors, :status => :unprocessable_entity }
end
end
end So apparently the the @user.reload doesn't really refresh the ActiveRecord, as my errors showed that the name has not been changed at all. Any idea what is wrong?