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/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 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/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..cd638bef4 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..327ec1f86 100644 --- a/app/controllers/clearance/sessions_controller.rb +++ b/app/controllers/clearance/sessions_controller.rb @@ -12,24 +12,29 @@ 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? 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_out, :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 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: [] 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 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 new file mode 100644 index 000000000..fb5e20498 --- /dev/null +++ b/test/rails_root/config/locales/en.yml @@ -0,0 +1,19 @@ +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: + 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. 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