From 884eadde87fd558a2e9ae2de54eb2758914085a8 Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Tue, 12 May 2009 01:25:38 -0400 Subject: [PATCH 1/9] adding test for blank password confirmation --- lib/clearance/user.rb | 5 +++-- test/models/user_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/clearance/user.rb b/lib/clearance/user.rb index acb44503c..9499ea758 100644 --- a/lib/clearance/user.rb +++ b/lib/clearance/user.rb @@ -12,11 +12,12 @@ def self.included(model) attr_accessor :password, :password_confirmation validates_presence_of :email - validates_presence_of :password, :if => :password_required? - validates_confirmation_of :password, :if => :password_required? validates_uniqueness_of :email, :case_sensitive => false validates_format_of :email, :with => %r{.+@.+\..+} + validates_presence_of :password, :if => :password_required? + validates_confirmation_of :password, :if => :password_required? + before_save :initialize_salt, :encrypt_password, :initialize_token end end diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 8d82316d9..426640938 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -21,6 +21,13 @@ class UserTest < ActiveSupport::TestCase assert user.errors.on(:password) 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) + end + should "initialize salt" do assert_not_nil Factory(:user).salt end From 3f4dd3a899bdacbe33fe40f754730948c1d63ad2 Mon Sep 17 00:00:00 2001 From: Nick Quaranto Date: Fri, 15 May 2009 11:51:25 -0400 Subject: [PATCH 2/9] Formatting the code in the README properly --- README.textile | 82 +++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/README.textile b/README.textile index 1ca388aa0..b323abe76 100644 --- a/README.textile +++ b/README.textile @@ -14,19 +14,23 @@ Clearance is a Rails engine. It works with versions of Rails greater than 2.3. In config/environment.rb: - config.gem "thoughtbot-clearance", - :lib => 'clearance', - :source => 'http://gems.github.com', - :version => '0.6.4' +
+config.gem "thoughtbot-clearance", 
+  :lib     => 'clearance', 
+  :source  => 'http://gems.github.com', 
+  :version => '0.6.4'
+
Vendor the gem: - rake gems:install - rake gems:unpack +
+rake gems:install
+rake gems:unpack
+
Make sure the development database exists and run the generator: - script/generate clearance +@script/generate clearance@ A number of files will be created and instructions will be printed. @@ -34,25 +38,25 @@ You may already have some of these files. Don't worry. You'll be asked if you wa Run the migration: - rake db:migrate +@rake db:migrate@ h2. Environment Define a HOST constant in your environment files. In config/environments/test.rb and config/environments/development.rb it can be: - HOST = "localhost" +@HOST = "localhost"@ In production.rb it must be the actual host your application is deployed to. The constant is used by mailers to generate URLs in emails. In config/environment.rb: - DO_NOT_REPLY = "donotreply@example.com" +@DO_NOT_REPLY = "donotreply@example.com"@ Define root_url to *something* in your config/routes.rb: - map.root :controller => 'home' +@map.root :controller => 'home'@ h2. Cucumber Features @@ -60,42 +64,50 @@ As your app evolves, you want to know that authentication still works. Clearance In config/environments/test.rb: - config.gem 'webrat', - :version => '= 0.4.4' - config.gem 'cucumber', - :version => '= 0.3.0' - config.gem 'thoughtbot-factory_girl', - :lib => 'factory_girl', - :source => "http://gems.github.com", - :version => '1.2.1' +
+config.gem 'webrat',
+  :version => '= 0.4.4'
+config.gem 'cucumber',
+  :version => '= 0.3.0'
+config.gem 'thoughtbot-factory_girl',
+  :lib     => 'factory_girl',
+  :source  => "http://gems.github.com", 
+  :version => '1.2.1'
+
Vendor the gems: - rake gems:install RAILS_ENV=test - rake gems:unpack RAILS_ENV=test +
+rake gems:install RAILS_ENV=test
+rake gems:unpack  RAILS_ENV=test
+
Don't vendor nokogiri (due to its native extensions): - rm -rf vendor/gems/nokogiri-1.2.3 +@rm -rf vendor/gems/nokogiri-1.2.3@ Run the Cucumber generator (if you haven't already) and Clearance's feature generator: - script/generate cucumber - script/generate clearance_features +
+script/generate cucumber
+script/generate clearance_features
+
All of the files generated should be new with the exception of the features/support/paths.rb file. If you have not modified your paths.rb then you will be okay to replace it with this one. If you need to keep your paths.rb file then add these locations in your paths.rb manually: - def path_to(page_name) - case page_name - ... - when /the sign up page/i - new_user_path - when /the sign in page/i - new_session_path - when /the password reset request page/i - new_password_path - ... - end +
+def path_to(page_name)
+  case page_name
+   ...
+  when /the sign up page/i
+   new_user_path
+  when /the sign in page/i
+   new_session_path
+  when /the password reset request page/i
+   new_password_path
+  ...
+end
+
h2. Authors From eb42bf622573fdf9f47b9d4b262c62289cd31043 Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Fri, 15 May 2009 19:30:02 -0400 Subject: [PATCH 3/9] added internationalization to flash messages & email subject lines --- .../clearance/confirmations_controller.rb | 4 +++- app/controllers/clearance/passwords_controller.rb | 12 ++++++++---- app/controllers/clearance/sessions_controller.rb | 9 ++++++--- app/controllers/clearance/users_controller.rb | 6 ++++-- app/models/clearance_mailer.rb | 8 ++++++-- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/app/controllers/clearance/confirmations_controller.rb b/app/controllers/clearance/confirmations_controller.rb index b8d5502bd..4b94857ab 100644 --- a/app/controllers/clearance/confirmations_controller.rb +++ b/app/controllers/clearance/confirmations_controller.rb @@ -15,7 +15,9 @@ def create @user.confirm_email! sign_user_in(@user) - flash[:success] = "Confirmed email and signed in." + flash[:success] = translate(:confirmed_email, + :scope => [:clearance, :controllers, :confirmations], + :default => "Confirmed email and signed in.") redirect_to url_after_create end diff --git a/app/controllers/clearance/passwords_controller.rb b/app/controllers/clearance/passwords_controller.rb index fd2dab04d..50d426752 100644 --- a/app/controllers/clearance/passwords_controller.rb +++ b/app/controllers/clearance/passwords_controller.rb @@ -13,11 +13,15 @@ def create if user = ::User.find_by_email(params[:password][:email]) user.forgot_password! ::ClearanceMailer.deliver_change_password user - flash[:notice] = "You will receive an email within the next few minutes. " << - "It contains instructions for changing your password." + flash[:notice] = translate(:deliver_change_password, + :scope => [:clearance, :controllers, :passwords], + :default => "You will receive an email within the next few minutes. " << + "It contains instructions for changing your password.") redirect_to url_after_create else - flash.now[:failure] = "Unknown email" + flash.now[:failure] = translate(:unknown_email, + :scope => [:clearance, :controllers, :passwords], + :default => "Unknown email") render :template => 'passwords/new' end end @@ -34,7 +38,7 @@ def update params[:user][:password_confirmation]) @user.confirm_email! unless @user.email_confirmed? sign_user_in(@user) - flash[:success] = "Signed in." + flash[:success] = translate(:signed_in, :default => "Signed in.") redirect_to url_after_update else render :template => 'passwords/edit' diff --git a/app/controllers/clearance/sessions_controller.rb b/app/controllers/clearance/sessions_controller.rb index 5f12491f7..e1abab6e7 100644 --- a/app/controllers/clearance/sessions_controller.rb +++ b/app/controllers/clearance/sessions_controller.rb @@ -18,18 +18,21 @@ def create if @user.email_confirmed? sign_user_in(@user) remember(@user) if remember? - flash[:success] = "Signed in." + flash[:success] = translate(:signed_in, :default => "Signed in.") redirect_back_or url_after_create else ::ClearanceMailer.deliver_confirmation(@user) - deny_access("User has not confirmed email. Confirmation email will be resent.") + deny_access(translate(:unconfirmed_email, + :scope => [:clearance, :controllers, :sessions], + :default => "User has not confirmed email. " << + "Confirmation email will be resent.")) end end end def destroy forget(current_user) - flash[:success] = "Signed out." + flash[:success] = translate(:signed_in, :default => "Signed out.") redirect_to url_after_destroy end diff --git a/app/controllers/clearance/users_controller.rb b/app/controllers/clearance/users_controller.rb index 248a00681..b1b4ecc6b 100644 --- a/app/controllers/clearance/users_controller.rb +++ b/app/controllers/clearance/users_controller.rb @@ -13,8 +13,10 @@ def create @user = ::User.new params[:user] if @user.save ::ClearanceMailer.deliver_confirmation @user - flash[:notice] = "You will receive an email within the next few minutes. " << - "It contains instructions for confirming your account." + flash[:notice] = translate(:deliver_confirmation, + :scope => [:clearance, :controllers, :users], + :default => "You will receive an email within the next few minutes. " << + "It contains instructions for confirming your account.") redirect_to url_after_create else render :template => 'users/new' diff --git a/app/models/clearance_mailer.rb b/app/models/clearance_mailer.rb index 5e0a09442..90f5f1666 100644 --- a/app/models/clearance_mailer.rb +++ b/app/models/clearance_mailer.rb @@ -5,14 +5,18 @@ class ClearanceMailer < ActionMailer::Base def change_password(user) from DO_NOT_REPLY recipients user.email - subject "Change your password" + subject I18n.t(:change_password, + :scope => [:clearance, :models, :clearance_mailer], + :default => "Change your password") body :user => user end def confirmation(user) from DO_NOT_REPLY recipients user.email - subject "Account confirmation" + subject I18n.t(:confirmation, + :scope => [:clearance, :models, :clearance_mailer], + :default => "Account confirmation") body :user => user end From ac1e3edfc4c992338f1af13c23573ea2b4cbe2c1 Mon Sep 17 00:00:00 2001 From: Marcel Goerner Date: Sat, 16 May 2009 16:03:24 +0800 Subject: [PATCH 4/9] Typo in Symbol Signed-off-by: Dan Croak --- app/controllers/clearance/sessions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/clearance/sessions_controller.rb b/app/controllers/clearance/sessions_controller.rb index e1abab6e7..df6373caa 100644 --- a/app/controllers/clearance/sessions_controller.rb +++ b/app/controllers/clearance/sessions_controller.rb @@ -32,7 +32,7 @@ def create def destroy forget(current_user) - flash[:success] = translate(:signed_in, :default => "Signed out.") + flash[:success] = translate(:signed_out, :default => "Signed out.") redirect_to url_after_destroy end From 86f83b844475650e0438531c68f9e0110835e7e6 Mon Sep 17 00:00:00 2001 From: eugenebolshakov Date: Sat, 16 May 2009 18:53:53 +0800 Subject: [PATCH 5/9] Added a yml file with strings in english so that localization could actually be tested Signed-off-by: Dan Croak --- test/rails_root/config/locales/en.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/rails_root/config/locales/en.yml diff --git a/test/rails_root/config/locales/en.yml b/test/rails_root/config/locales/en.yml new file mode 100644 index 000000000..cc9b24b65 --- /dev/null +++ b/test/rails_root/config/locales/en.yml @@ -0,0 +1,18 @@ +en: + clearance: + models: + clearance_mailer: + change_password: Change your password + confirmation: Account confirmation + controllers: + confirmations: + confirmed_email: Confirmed email and signed in. + passwords: + deliver_change_password: You will receive an email within the next few minutes. It contains instructions for changing your password. + unknown_email: Unknown email + sessions: + unconfirmed_email: User has not confirmed email. Confirmation email will be resent. + users: + deliver_confirmation: You will receive an email within the next few minutes. It contains instructions for confirming your account. + signed_in: Signed in + signed_out: Signed out From c096f730c2423ec83f7c401d13d75bdce2f02b1e Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Sun, 17 May 2009 10:57:46 -0400 Subject: [PATCH 6/9] added missing bad email or password translation in sessions controller --- app/controllers/clearance/sessions_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/clearance/sessions_controller.rb b/app/controllers/clearance/sessions_controller.rb index df6373caa..327ec1f86 100644 --- a/app/controllers/clearance/sessions_controller.rb +++ b/app/controllers/clearance/sessions_controller.rb @@ -12,7 +12,9 @@ def create @user = ::User.authenticate(params[:session][:email], params[:session][:password]) if @user.nil? - flash.now[:failure] = "Bad email or password." + flash.now[:failure] = translate(:bad_email_or_password, + :scope => [:clearance, :controllers, :sessions], + :default => "Bad email or password.") render :template => 'sessions/new', :status => :unauthorized else if @user.email_confirmed? From ca16aa9fc8dbc5c9c504558f0f1d65a22174c41e Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Sun, 17 May 2009 11:04:29 -0400 Subject: [PATCH 7/9] adding :scope key to all translations --- app/controllers/clearance/passwords_controller.rb | 4 +++- app/controllers/clearance/sessions_controller.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/clearance/passwords_controller.rb b/app/controllers/clearance/passwords_controller.rb index 50d426752..fe8294b9d 100644 --- a/app/controllers/clearance/passwords_controller.rb +++ b/app/controllers/clearance/passwords_controller.rb @@ -38,7 +38,9 @@ def update params[:user][:password_confirmation]) @user.confirm_email! unless @user.email_confirmed? sign_user_in(@user) - flash[:success] = translate(:signed_in, :default => "Signed in.") + flash[:success] = translate(:signed_in, + :scope => [:clearance, :controllers, :passwords], + :default => "Signed in.") redirect_to url_after_update else render :template => 'passwords/edit' diff --git a/app/controllers/clearance/sessions_controller.rb b/app/controllers/clearance/sessions_controller.rb index 327ec1f86..d8d267dd7 100644 --- a/app/controllers/clearance/sessions_controller.rb +++ b/app/controllers/clearance/sessions_controller.rb @@ -34,7 +34,9 @@ def create def destroy forget(current_user) - flash[:success] = translate(:signed_out, :default => "Signed out.") + flash[:success] = translate(:signed_out, + :scope => [:clearance, :controllers, :sessions], + :default => "Signed out.") redirect_to url_after_destroy end From be7d139a41729a526775debc363d8c68dedc5822 Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Sun, 17 May 2009 11:38:17 -0400 Subject: [PATCH 8/9] audited all flashes for internationalization. saw failures for every flash & email eubject when locales/en.yml was altered. --- .../clearance/passwords_controller.rb | 6 ++---- .../clearance/sessions_controller.rb | 4 +--- test/rails_root/config/environment.rb | 2 +- test/rails_root/config/locales/en.yml | 17 +++++++++-------- test/test_helper.rb | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/controllers/clearance/passwords_controller.rb b/app/controllers/clearance/passwords_controller.rb index fe8294b9d..cd638bef4 100644 --- a/app/controllers/clearance/passwords_controller.rb +++ b/app/controllers/clearance/passwords_controller.rb @@ -21,7 +21,7 @@ def create else flash.now[:failure] = translate(:unknown_email, :scope => [:clearance, :controllers, :passwords], - :default => "Unknown email") + :default => "Unknown email.") render :template => 'passwords/new' end end @@ -38,9 +38,7 @@ def update params[:user][:password_confirmation]) @user.confirm_email! unless @user.email_confirmed? sign_user_in(@user) - flash[:success] = translate(:signed_in, - :scope => [:clearance, :controllers, :passwords], - :default => "Signed in.") + flash[:success] = translate(:signed_in, :default => "Signed in.") redirect_to url_after_update else render :template => 'passwords/edit' diff --git a/app/controllers/clearance/sessions_controller.rb b/app/controllers/clearance/sessions_controller.rb index d8d267dd7..327ec1f86 100644 --- a/app/controllers/clearance/sessions_controller.rb +++ b/app/controllers/clearance/sessions_controller.rb @@ -34,9 +34,7 @@ def create def destroy forget(current_user) - flash[:success] = translate(:signed_out, - :scope => [:clearance, :controllers, :sessions], - :default => "Signed out.") + flash[:success] = translate(:signed_out, :default => "Signed out.") redirect_to url_after_destroy end diff --git a/test/rails_root/config/environment.rb b/test/rails_root/config/environment.rb index 1665c9ba1..70432ccd0 100644 --- a/test/rails_root/config/environment.rb +++ b/test/rails_root/config/environment.rb @@ -1,5 +1,5 @@ require File.join(File.dirname(__FILE__), 'boot') -require 'md5' # Need this up here to generate the session[:secret] value down there +require 'md5' Rails::Initializer.run do |config| config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib')) diff --git a/test/rails_root/config/locales/en.yml b/test/rails_root/config/locales/en.yml index cc9b24b65..fb5e20498 100644 --- a/test/rails_root/config/locales/en.yml +++ b/test/rails_root/config/locales/en.yml @@ -1,18 +1,19 @@ en: - clearance: + clearance: models: clearance_mailer: - change_password: Change your password - confirmation: Account confirmation + change_password: Change your password + confirmation: Account confirmation controllers: - confirmations: + confirmations: confirmed_email: Confirmed email and signed in. - passwords: + passwords: deliver_change_password: You will receive an email within the next few minutes. It contains instructions for changing your password. - unknown_email: Unknown email + unknown_email: Unknown email. sessions: + bad_email_or_password: Bad email or password. unconfirmed_email: User has not confirmed email. Confirmation email will be resent. users: deliver_confirmation: You will receive an email within the next few minutes. It contains instructions for confirming your account. - signed_in: Signed in - signed_out: Signed out + signed_in: Signed in. + signed_out: Signed out. diff --git a/test/test_helper.rb b/test/test_helper.rb index b00127427..b0c0cee15 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,7 +6,7 @@ $: << File.expand_path(File.dirname(__FILE__) + '/..') require 'clearance' -gem 'thoughtbot-factory_girl' # from github +gem 'thoughtbot-factory_girl' require 'factory_girl' require 'redgreen' rescue LoadError From 7030aa9c627933c7da0e870071bbe50d9313f7bc Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Sun, 17 May 2009 11:40:37 -0400 Subject: [PATCH 9/9] bumped the gem to 0.6.5 (i18n release). updated CHANGELOG. --- CHANGELOG.textile | 4 ++++ Rakefile | 2 +- clearance.gemspec | 12 +++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.textile b/CHANGELOG.textile index cfc16fca5..3a221138d 100644 --- a/CHANGELOG.textile +++ b/CHANGELOG.textile @@ -1,3 +1,7 @@ +h2. 0.6.5 (5/17/2009) + +* [#6] Make Clearance i18n aware. (Timur Vafin, Marcel Goerner, Eugene Bolshakov, Dan Croak) + h2. 0.6.4 (05/12/2009) * Moved issue tracking to Github from Lighthouse. (Dan Croak) diff --git a/Rakefile b/Rakefile index c19e0c173..c246e6ddc 100644 --- a/Rakefile +++ b/Rakefile @@ -51,7 +51,7 @@ task :default => ['test:all', 'test:features'] gem_spec = Gem::Specification.new do |gem_spec| gem_spec.name = "clearance" - gem_spec.version = "0.6.4" + gem_spec.version = "0.6.5" gem_spec.summary = "Rails authentication with email & password." gem_spec.email = "support@thoughtbot.com" gem_spec.homepage = "http://github.com/thoughtbot/clearance" diff --git a/clearance.gemspec b/clearance.gemspec index b71dcf0df..e0572a014 100644 --- a/clearance.gemspec +++ b/clearance.gemspec @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: clearance version: !ruby/object:Gem::Version - version: 0.6.4 + version: 0.6.5 platform: ruby authors: - Dan Croak @@ -24,7 +24,7 @@ autorequire: bindir: bin cert_chain: [] -date: 2009-05-12 00:00:00 -04:00 +date: 2009-05-17 00:00:00 -04:00 default_executable: dependencies: [] @@ -99,8 +99,10 @@ files: - lib/clearance.rb - shoulda_macros/clearance.rb - rails/init.rb -has_rdoc: false +has_rdoc: true homepage: http://github.com/thoughtbot/clearance +licenses: [] + post_install_message: rdoc_options: [] @@ -121,9 +123,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement requirements: [] rubyforge_project: -rubygems_version: 1.3.1 +rubygems_version: 1.3.3 signing_key: -specification_version: 2 +specification_version: 3 summary: Rails authentication with email & password. test_files: []