Skip to content

Commit

Permalink
Update clearance and tests to Rails3-style syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Jun 10, 2010
1 parent c07789c commit 0fbf771
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/controllers/clearance/passwords_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def new
def create
if user = ::User.find_by_email(params[:password][:email])
user.forgot_password!
::ClearanceMailer.deliver_change_password user
::ClearanceMailer.change_password(user).deliver
flash_notice_after_create
redirect_to(url_after_create)
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/clearance/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def create
flash_success_after_create
redirect_back_or(url_after_create)
else
::ClearanceMailer.deliver_confirmation(@user)
::ClearanceMailer.confirmation(@user).deliver
flash_notice_after_create
redirect_to(sign_in_url)
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/clearance_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class ClearanceMailer < ActionMailer::Base

def change_password(user)
@user = user
from Clearance.configuration.mailer_sender
recipients user.email
recipients @user.email
subject I18n.t(:change_password,
:scope => [:clearance, :models, :clearance_mailer],
:default => "Change your password")
body :user => user
end

def confirmation(user)
@user = user
from Clearance.configuration.mailer_sender
recipients user.email
recipients @user.email
subject I18n.t(:confirmation,
:scope => [:clearance, :models, :clearance_mailer],
:default => "Account confirmation")
body :user => user
end

end
8 changes: 4 additions & 4 deletions lib/clearance/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def remember_me!
# user.reset_remember_token!
def reset_remember_token!
generate_remember_token
save(false)
save(:validate => false)
end

# Confirm my email.
Expand All @@ -108,7 +108,7 @@ def reset_remember_token!
def confirm_email!
self.email_confirmed = true
self.confirmation_token = nil
save(false)
save(:validate => false)
end

# Mark my account as forgotten password.
Expand All @@ -117,7 +117,7 @@ def confirm_email!
# user.forgot_password!
def forgot_password!
generate_confirmation_token
save(false)
save(:validate => false)
end

# Update my password.
Expand Down Expand Up @@ -185,7 +185,7 @@ def password_required?
end

def send_confirmation_email
ClearanceMailer.deliver_confirmation self
ClearanceMailer.confirmation(self).deliver
end
end

Expand Down
2 changes: 1 addition & 1 deletion shoulda_macros/clearance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def bad_confirmation_options(attribute)

def assert_confirmation_error(model, attribute, message = "confirmation error")
warn "[DEPRECATION] assert_confirmation_error: not meant to be public, no longer used internally"
assert model.errors.on(attribute).include?("doesn't match confirmation"),
assert model.errors[attribute].include?("doesn't match confirmation"),
message
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class UserTest < ActiveSupport::TestCase
user = Factory.build(:user, :password => 'blah',
:password_confirmation => 'boogidy')
assert ! user.save
assert user.errors.on(:password)
assert user.errors[:password].any?
end

should "require non blank password confirmation on create" do
user = Factory.build(:user, :password => 'blah',
:password_confirmation => '')
assert ! user.save
assert user.errors.on(:password)
assert user.errors[:password].any?
end

should "initialize salt" do
Expand Down

0 comments on commit 0fbf771

Please sign in to comment.