Merge branch 'master' of bitbucket.org:jamkazam/jam-ruby

This commit is contained in:
Brian Smith 2012-12-16 18:24:23 -05:00
commit 9ca701d99e
8 changed files with 75 additions and 2 deletions

View File

@ -37,5 +37,14 @@ module JamRuby
format.html
end
end
def password_changed(user)
@user = user
sendgrid_unique_args :type => "password_changed"
mail(:to => user.email, :subject => "Jamkazam Password Changed") do |format|
format.text
format.html
end
end
end
end
end

View File

@ -0,0 +1,5 @@
<html>
<body>
You Just Changed Your Password! <%= @user.email %>
</body>
</html>

View File

@ -0,0 +1 @@
You Just Changed Your Password! <%= @user.email %>

View File

@ -25,4 +25,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

View File

@ -4,7 +4,7 @@ module JamRuby
self.primary_key = 'id'
attr_accessor :legal_terms
attr_accessible :creator, :musician_access, :approval_required, :fan_chat, :fan_access
attr_accessible :creator, :description, :musician_access, :approval_required, :fan_chat, :fan_access
belongs_to :creator, :inverse_of => :music_sessions, :class_name => "JamRuby::User", :foreign_key => "user_id"

View File

@ -164,6 +164,18 @@ module JamRuby
return id
end
def set_password(old_password, new_password, new_password_confirmation)
raise JamRuby::JamArgumentError unless authenticate old_password
# FIXME: Should verify that the new password meets certain quality criteria. Really, maybe that should be a
# verification step.
self.password = new_password
self.password_confirmation = new_password_confirmation
save
UserMailer.password_changed(self).deliver
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)

View File

@ -223,6 +223,21 @@ describe MusicSession do
music_sessions.length.should == 1
end
it "updates the fields of a music session properly" do
genre1 = FactoryGirl.create(:genre)
genre2 = FactoryGirl.create(:genre)
genre3 = FactoryGirl.create(:genre)
genre4 = FactoryGirl.create(:genre)
creator = FactoryGirl.create(:user)
session = FactoryGirl.create(:music_session, :creator => creator, :description => "Session", :genres => [genre3,genre4])
session.update_attributes({:description => "Session2", :genre => [genre1, genre2]})
session.genres = [genre1, genre2]
session.reload
session.description.should == "Session2"
session.genres.length.should == 2
session.genres[0].id.should == genre1.id
end
=begin
# mslemmer:
# I'm going to clean this up into smaller tasks.

View File

@ -125,6 +125,34 @@ describe User do
it { should be_invalid }
end
describe "set_password" do
before do
@user.confirm_email!
end
it "setting a new password should work" do
@user.set_password("foobar", "newpassword", "newpassword")
User.authenticate(@user.email, "newpassword").should_not be_nil
end
it "setting a new password should fail if old one doesnt match" do
expect { @user.set_password("wrongold", "newpassword", "newpassword") }.to raise_error
end
it "setting a new password should fail if new ones dont match" do
@user.set_password("foobar", "newpassword", "newpassword2")
User.authenticate(@user.email, "newpassword").should be_nil
end
it "setting a new password should fail if new one doesnt validate" do
@user.set_password("foobar", "a", "a")
User.authenticate(@user.email, "newpassword").should be_nil
end
end
describe "return value of authenticate method" do
before { @user.save }
let(:found_user) { User.find_by_email(@user.email) }