Class | LoginControllerTest
In: | test/functional/login_controller_test.rb
Parent: | Test::Unit::TestCase

### Methods

setup test_lost_password test_sign_up_with_pw test_signup_central_admin

### Public Instance methods

setup()

[Source]

        # File test/functional/login_controller_test.rb, line 28
    28:   def setup
    29:     logger.debug "Test Case: #{name}"
    30:     @controller = LoginController.new
    31:     @request    = ActionController::TestRequest.new
    32:     @response   = ActionController::TestResponse.new
    33:     @emails = ActionMailer::Base::deliveries
    34:     @emails.clear
    35:   end

test_lost_password()

Shows:

1. Request Lost password form
2. Error on wrong email addresses
3. New password set, email sent with password and token
4. Cannot logon with ‘new’ password (not activated yet)

[Source]

         # File test/functional/login_controller_test.rb, line 88
     88:   def   test_lost_password
     89:     # 1
     90:     get :lost_password
     91:     assert_response     :success
     92:     assert_field 'user_email'
     93:     assert_tag :tag => 'form', :attributes => {:action => '/login/lost_password'}
     94:     # 2
     95:     post :lost_password, :user => {:email => 'noneexisting email', :password => 'new_password', :password_confirmation => 'new_password'}
     96:     assert_response :success
     97:     assert_equal LoginController::FLASH_EMAIL_NOT_FOUND, flash['notice']
     98:     # 3
     99:     post :lost_password, :user => {:email => 'andy.kaufman@epf.eclipse.org'}
    100:     user_by_email = assigns(:user_by_email)
    101:     assert_not_nil user_by_email
    102:     assert_equal LoginController::FLASH_PW_CONFIRMATION_EMAIL_SENT, flash['success']
    103:     assert_equal(1, @emails.size)
    104:     email = @emails.first
    105:     assert_equal("[#{ENV['EPFWIKI_APP_NAME']}] New Password", email.subject)
    106:     assert_equal("andy.kaufman@epf.eclipse.org", email.to[0])
    107:     assert_equal([ENV['EPFWIKI_REPLY_ADDRESS']], email.from)
    108:     assert_match(assigns(:user_by_email).token_new, email.body)
    109:     assert_redirected_to :action => 'login'
    110:     @emails.clear
    111:     # 4
    112:     post :login, :user => {:email => user_by_email.email, :password => user_by_email.password}
    113:     assert_equal LoginController::FLASH_INVALID_PW, flash['notice']
    114:   end

test_sign_up_with_pw()

Shows that a user can sign up by supplying name, email, password and password confirmation

[Source]

        # File test/functional/login_controller_test.rb, line 58
    58:   def test_sign_up_with_pw
    59:     get :sign_up
    60:     assert_response :success
    61:     assert_field 'user_name'
    62:     assert_field 'user_email'
    63:     assert_field 'user_password'
    64:     assert_field 'user_password_confirmation'
    65:     assert !ENV['EPFWIKI_DOMAINS'].blank?
    66:     assert_tag :tag => 'select', :attributes => {:name => 'user[email_extension]'}
    67:     post :sign_up, :user => {:name => "user1", :email=>"user1", :email_extension => "@somedomain.com"} # , :i_agree_to_the_terms_of_use => '1'
    68:     assert_errors
    69:     assert_not_nil assigns(:user)
    70:     assert_equal 'Password confirmation can\'t be blank, Password can\'t be blank, Email domain not valid', assigns(:user).errors.full_messages.join(', ')
    71:     post :sign_up, :user => {:name => "user1", :email=>"user1", :email_extension => "@epf.eclipse.org", :password => 'user1', :password_confirmation => 'user1'} # , :i_agree_to_the_terms_of_use => '1'
    72:     assert_equal 'test.host', @request.host + (@request.port == 80 ? '' : ':' + @request.port.to_s)
    73:     assert_redirected_to :action => 'login'
    74:     assert_equal LoginController::FLASH_PW_CONFIRMATION_EMAIL_SENT, flash['success']
    75:     assert_equal(1, @emails.size)
    76:     email = @emails.first
    77:     assert_equal("[#{ENV['EPFWIKI_APP_NAME']}] Welcome", email.subject)
    78:     assert_equal("user1@epf.eclipse.org", email.to[0])
    79:     assert_equal([ENV['EPFWIKI_REPLY_ADDRESS']], email.from)
    80:     assert_redirected_to :action => 'login'
    81:   end

test_signup_central_admin()

Shows we can create the central admin

[Source]

        # File test/functional/login_controller_test.rb, line 38
    38:   def  test_signup_central_admin
    39:     User.delete_all
    40:     assert User.count == 0
    41:     get :index
    42:     assert_redirected_to :action => 'login'
    43:     get :login
    44:     assert_redirected_to :action => 'new_cadmin'
    45:     get :new_cadmin
    46:     assert_field 'user_name'
    47:     assert_field 'user_email'
    48:     assert_field 'user_password'
    49:     assert_field 'user_password_confirmation'
    50:     assert_tag :tag => 'input', :attributes => {:type => 'submit'}
    51:     assert_tag :tag => 'form', :attributes => {:action => '/login/new_cadmin'}
    52:     post        :new_cadmin, :user => {:name => 'George Shapiro', :email=> 'george.shapiro@epf.eclipse.org', :password => 'pass2', :password_confirmation => 'pass2'}
    53:     assert_equal LoginController::FLASH_CENTRAL_ADMIN_CREATED, flash['success']
    54:     assert_redirected_to :action => 'login'
    55:   end

[Validate]