Skip to content

Instantly share code, notes, and snippets.

@kshsieh
Created June 27, 2013 18:06
Show Gist options
  • Save kshsieh/5878822 to your computer and use it in GitHub Desktop.
Save kshsieh/5878822 to your computer and use it in GitHub Desktop.
false positive
# test in users controller spec
# testing update with a guest account
context "updating guest account" do
before :each do
email = "guest@example.com"
User.check_and_create_guest(email)
user = User.find_by_email(email)
controller.stub :current_user => user
end
it "should promote to Guest and create User" do
put :update, {:user => {:password => 'mynewpassword'} }
debugger
User.find_by_email("guest@example.com").type.should == nil
end
end
# just wanted to see if this works
def update
respond_to do |format|
if @user.update_attributes(params[:user])
if @user.guest?
@user.promote_to_user
end
if params[:user][:password].present?
# this logic needed b/c devise wants to log us out after password changes
user = User.reset_password_by_token(params[:user])
@user = current_user
sign_out(@user)
sign_in(@user, :event => :authentication)
end
flash[:notice] = I18n.t("account_updated")
format.html { redirect_to account_url(anchor: 'account') }
format.js
else
format.html { render 'edit' }
format.js
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment