From 7ff103a4307ec66295113533562bb8261870756f Mon Sep 17 00:00:00 2001 From: Mike Slemmer Date: Thu, 13 Dec 2012 09:15:47 -0800 Subject: [PATCH] more work --- lib/jam_ruby/constants/validation_messages.rb | 3 +++ lib/jam_ruby/models/user.rb | 9 +++++++++ spec/jam_ruby/models/user_spec.rb | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/jam_ruby/constants/validation_messages.rb b/lib/jam_ruby/constants/validation_messages.rb index a6e08575b..6a541c3db 100644 --- a/lib/jam_ruby/constants/validation_messages.rb +++ b/lib/jam_ruby/constants/validation_messages.rb @@ -19,4 +19,7 @@ module ValidationMessages INSTRUMENT_LIMIT_EXCEEDED = "No more than 5 instruments are allowed." INSTRUMENT_MINIMUM_NOT_MET = "At least 1 instrument is required." + # user + OLD_PASSWORD_DOESNT_MATCH = "Your old password is incorrect." + end \ No newline at end of file diff --git a/lib/jam_ruby/models/user.rb b/lib/jam_ruby/models/user.rb index 8421873b9..0638f4697 100644 --- a/lib/jam_ruby/models/user.rb +++ b/lib/jam_ruby/models/user.rb @@ -164,6 +164,15 @@ module JamRuby return id end + def set_password(old_password, new_password) + raise JamRuby::JamArgumentError, ValidationMessages::OLD_PASSWORD_DOESNT_MATCH unless authenticate old_password + # FIXME: Should verify that the new password meets certain quality criteria + # FIXME: Need to run the new password through the validations here. Not sure if this does that. + password = new_password + save + end + + # helper method for creating / updating a User def self.save(id, updater_id, first_name, last_name, email, password, password_confirmation, musician, gender, birth_date, internet_service_provider, city, state, country, instruments, photo_url) diff --git a/spec/jam_ruby/models/user_spec.rb b/spec/jam_ruby/models/user_spec.rb index f3d88acd7..ed3937bc2 100644 --- a/spec/jam_ruby/models/user_spec.rb +++ b/spec/jam_ruby/models/user_spec.rb @@ -125,6 +125,17 @@ describe User do it { should be_invalid } end + describe "setting a new password should work" do + + end + describe "setting a new password should fail if old one doesnt match" do + + end + describe "setting a new password should fail if new one doesnt validate" do + + end + + describe "return value of authenticate method" do before { @user.save } let(:found_user) { User.find_by_email(@user.email) }