{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"open","user":{"avatar_url":"https://secure.gravatar.com/avatar/bdee7e947b5da3020c8badf7cda67bfd?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"bdee7e947b5da3020c8badf7cda67bfd","url":"https://api.github.com/users/xlprojects","login":"xlprojects","id":34569},"milestone":null,"labels":[],"assignee":null,"updated_at":"2011-11-13T17:00:23Z","comments":6,"closed_at":null,"url":"https://api.github.com/repos/NoamB/sorcery/issues/150","body":"Hey there, hope someone can help me.\r\n\r\nI've created a change password method for the User model as follow\r\n\r\n```ruby\r\ndef update_password(current_password, new_password, new_password_confirmation)\r\n  if new_password == new_password_confirmation\r\n    if !User.authenticate(self.username, current_password).nil?\r\n      return self.change_password!(new_password)\r\n    else\r\n      return false\r\n    end\r\n  else\r\n    return false\r\n  end\r\nend\r\n```\r\n\r\nHere is my User factory\r\n\r\n```ruby\r\n  FactoryGirl.define do\r\n    factory :user do\r\n      first_name            \"Bob\"\r\n      last_name             \"Sinclar\"\r\n      date_of_birth         \"03/12/1982\"\r\n      genre                 \"M\"\r\n      sequence(:username)   { |n| \"bsinclar#{n}\" }\r\n      email                 { \"#{username}@example.com\" }\r\n      password              \"secret\"\r\n      salt                  \"asdasdastr4325234324sdfds\"\r\n      activation_state      \"active\"\r\n      admin                 false\r\n      \r\n      after_build do |u|\r\n        u.crypted_password = Sorcery::CryptoProviders::BCrypt.encrypt(u.password, u.salt)\r\n      end\r\n      \r\n      factory :admin_user do\r\n        admin true\r\n      end\r\n    end\r\n  end\r\n```\r\n\r\nHere are my rspec tests\r\n\r\n```ruby\r\nrequire 'spec_helper'\r\n\r\ndescribe User do\r\n  subject { Factory(:user) }\r\n  \r\n  describe :update_password do\r\n    let!(:bob) {Factory(:user, password: \"password\", password_confirmation: \"password\" )}\r\n    \r\n    it \"updates the password if everything is passed correctly\" do\r\n      bob.update_password(\"password\",\"new_pass\",\"new_pass\").should be_true\r\n    end\r\n    \r\n    it \"throws an error if you enter the incorrect current password\" do\r\n      bob.update_password(\"bad_password\",\"new_pass\",\"new_pass\").should be_false\r\n    end\r\n    \r\n    it \"throws an error if the new password isn't confirmed properly\" do\r\n      bob.update_password(\"password\",\"new_pass\",\"bad_new_pass\").should be_false\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nI obtain F.. but in fact it seems like even if I try to authentify with the password \"password\", it complains that the password is not valid.\r\nUsing pry, I was able to investigate about the user object in the test (here 'bob') and it seems that the salt gets changed upon user creation... I am not sure why or how... This is what I get with some tryouts:\r\n\r\n```ruby\r\npry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> bob\r\n=> #<User id: 39, first_name: \"Bob\", last_name: \"Sinclar\", date_of_birth: \"03/12/1982\", genre: \"M\", username: \"bsinclar1\", email: \"bsinclar1@example.com\", crypted_password: \"$2a$10$2c6n5H5g7jNpvUX50iXcdeAfOLdaC8TnhcHQddeClkFh...\", salt: \"7a5c5bfa820ba61284e614c6098ea6709eb385bf\", admin: false, created_at: \"2011-11-12 04:47:30\", updated_at: \"2011-11-12 04:47:30\", remember_me_token: nil, remember_me_token_expires_at: nil, activation_state: \"pending\", activation_token: \"4c78a2f8f9c157c9dd7706f8aa21749ccd1ba2d9\", activation_token_expires_at: nil, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, failed_logins_count: 0, lock_expires_at: nil, last_login_at: nil, last_logout_at: nil, last_activity_at: nil>\r\npry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> bob.salt\r\n=> \"7a5c5bfa820ba61284e614c6098ea6709eb385bf\"\r\npry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> bob.crypted_password\r\n=> \"$2a$10$2c6n5H5g7jNpvUX50iXcdeAfOLdaC8TnhcHQddeClkFhpnm9Zr4MC\"\r\npry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> Sorcery::CryptoProviders::BCrypt.encrypt(\"password\", bob.salt)\r\n=> \"$2a$10$RekZ5aMdXRK8zGKk7N5QQuMXDKzEQ.UGm9LhA2KvQe9jAd58X1RkG\"\r\npry(#<RSpec::Core::ExampleGroup::Nested_1::Nested_1>)> Sorcery::CryptoProviders::BCrypt.encrypt(\"password\", \"asdasdastr4325234324sdfds\")\r\n=> \"$2a$10$RFsoUOAiernoegn1ibftzuF5w.rlVtXZoyTQ9iwHda8jDQb5FUOcq\"\r\n```\r\n\r\nI'm quite confused and would appreciate any help to help me debug my test suite... the change password functionality works fine.... I just want it tested thoroughly but FactoryGirl seems to not cope nicely with sorcery... thoughts?","html_url":"https://github.com/NoamB/sorcery/issues/150","title":"Issue testing password change implementation using FactoryGirl","number":150,"id":2216011,"created_at":"2011-11-12T05:34:39Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/bdee7e947b5da3020c8badf7cda67bfd?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"bdee7e947b5da3020c8badf7cda67bfd","url":"https://api.github.com/users/xlprojects","login":"xlprojects","id":34569},"updated_at":"2011-11-13T17:00:23Z","url":"https://api.github.com/repos/NoamB/sorcery/issues/comments/2723165","body":"I do have the password confirmation in my factory:\r\n\r\n```ruby\r\nFactoryGirl.define do\r\n  factory :user do\r\n    first_name            \"Bob\"\r\n    last_name             \"Sinclar\"\r\n    date_of_birth         \"03/12/1982\"\r\n    genre                 \"M\"\r\n    sequence(:username)   { |n| \"bsinclar#{n}\" }\r\n    email                 { \"#{username}@example.com\" }\r\n    password              \"password\"\r\n    password_confirmation \"password\"\r\n    activation_state      \"active\"\r\n    admin                 false\r\n    \r\n    factory :admin_user do\r\n      admin true\r\n    end\r\n  end\r\nend\r\n```\r\nI tried as you said but without success...\r\n\r\n```ruby\r\ndef update_password(current_password, new_password, new_password_confirmation)\r\n    if new_password == new_password_confirmation\r\n      if !User.authenticate(self.username, current_password).nil?\r\n        self.password_confirmation = new_password_confirmation\r\n        return self.change_password!(new_password)\r\n      else\r\n        return false\r\n      end\r\n    else\r\n      return false\r\n    end\r\n  end\r\n```\r\nOn thing I notice using pry, is that when I look at the user bob created with my factory, the activation state is set to \"pending\" (see the last code bit on my first post)... even though I set it explicitly to \"active\" in my factory... do you think the user_activation module could be interfering?\r\n\r\nThanks for the help by the way, I really appreciate...","id":2723165,"created_at":"2011-11-13T17:00:23Z"}}