noosfero | Fix account controller test

Bráulio Bhavamitra gitlab at gitlab.com
Mon Feb 23 20:24:33 BRT 2015


Bráulio Bhavamitra pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/48fdc451054c701ce07c60894dfdb0f3f82d76eb">48fdc451</a> by Braulio Bhavamitra
Fix account controller test

- - - - -


Changes:

=====================================
app/models/user.rb
=====================================
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -54,7 +54,7 @@ class User < ActiveRecord::Base
 
       user.person = p
     end
-    if user.environment.enabled?('skip_new_user_email_confirmation') 
+    if user.environment.enabled?('skip_new_user_email_confirmation')
       if user.environment.enabled?('admin_must_approve_new_users')
         create_moderate_task
       else
@@ -102,7 +102,7 @@ class User < ActiveRecord::Base
   validates_length_of       :email,    :within => 3..100, :if => (lambda {|user| !user.email.blank?})
   validates_uniqueness_of   :login, :email, :case_sensitive => false, :scope => :environment_id
   before_save :encrypt_password
-  before_save :normalize_email
+  before_save :normalize_email, if: proc{ |u| u.email.present? }
   validates_format_of :email, :with => Noosfero::Constants::EMAIL_FORMAT, :if => (lambda {|user| !user.email.blank?})
 
   validates_inclusion_of :terms_accepted, :in => [ '1' ], :if => lambda { |u| ! u.terms_of_use.blank? }, :message => N_('{fn} must be checked in order to signup.').fix_i18n

=====================================
test/functional/account_controller_test.rb
=====================================
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -818,17 +818,17 @@ class AccountControllerTest < ActionController::TestCase
   end
 
   should 'login with an alternative authentication defined by plugin' do
+    user = create_user
     class Plugin1 < Noosfero::Plugin
-      def alternative_authentication
-        User.new(:login => 'testuser')
-      end
     end
+    Plugin1.send(:define_method, :alternative_authentication){ user }
+
     Noosfero::Plugin.stubs(:all).returns([Plugin1.name])
     Environment.default.enable_plugin(Plugin1.name)
 
     post :login, :user => {:login => "testuser"}
 
-    assert_equal 'testuser', assigns(:current_user).login
+    assert_equal user.login, assigns(:current_user).login
     assert_response :redirect
   end
 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150223/4b568f13/attachment-0001.html>


More information about the Noosfero-dev mailing list