| Class | LoginControllerTest |
| In: |
test/functional/login_controller_test.rb
|
| Parent: | Test::Unit::TestCase |
# 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
Shows:
# File test/functional/login_controller_test.rb, line 117
117: def test_lost_password
118: # 1
119: get :lost_password
120: assert_response :success
121: assert_field 'user_email'
122: assert_tag :tag => 'form', :attributes => {:action => '/login/lost_password'}
123: # 2
124: post :lost_password, :user => {:email => 'noneexisting email'}
125: assert_response :success
126: assert_equal LoginController::FLASH_EMAIL_NOT_FOUND, flash['notice']
127: # 3
128: post :lost_password, :user => {:email => 'andy.kaufman@epf.eclipse.org'}
129: user_by_email = assigns(:user_by_email)
130: assert_not_nil user_by_email
131: assert_equal LoginController::FLASH_PW_SENT, flash['success']
132: assert_equal(1, @emails.size)
133: email = @emails.first
134: assert_equal("[#{ENV['EPFWIKI_APP_NAME']}] New Password", email.subject)
135: assert_equal("andy.kaufman@epf.eclipse.org", email.to[0])
136: assert_equal([ENV['EPFWIKI_REPLY_ADDRESS']], email.from)
137: assert_match(assigns(:user_by_email).password, email.body)
138: assert_match(assigns(:user_by_email).token_new, email.body)
139: assert_redirected_to :action => 'login'
140: @emails.clear
141: # 4
142: post :login, :user => {:email => user_by_email.email, :password => user_by_email.password}
143: assert_equal LoginController::FLASH_INVALID_PW, flash['notice']
144: end
Shows that a user can sign up by supplying name, email, password and password confirmation
# 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_equal '0', ENV['EPFWIKI_GENERATE_PASSWORDS']
64: assert_field 'user_password'
65: assert_field 'user_password_confirmation'
66: assert !ENV['EPFWIKI_DOMAINS'].blank?
67: assert_tag :tag => 'select', :attributes => {:name => 'user[email_extension]'}
68: post :sign_up, :user => {:name => "user1", :email=>"user1", :email_extension => "@somedomain.com"} # , :i_agree_to_the_terms_of_use => '1'
69: assert_errors
70: assert_not_nil assigns(:user)
71: assert_equal 'Password confirmation can\'t be blank, Password can\'t be blank, Email domain not valid', assigns(:user).errors.full_messages.join(', ')
72: 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'
73: assert_equal 'test.host', @request.host + (@request.port == 80 ? '' : ':' + @request.port.to_s)
74: assert_redirected_to :action => 'login'
75: assert_equal LoginController::FLASH_PW_CONFIRMATION_EMAIL_SENT, flash['success']
76: assert_equal(1, @emails.size)
77: email = @emails.first
78: assert_equal("[#{ENV['EPFWIKI_APP_NAME']}] Welcome", email.subject)
79: assert_equal("user1@epf.eclipse.org", email.to[0])
80: assert_equal([ENV['EPFWIKI_REPLY_ADDRESS']], email.from)
81: assert_redirected_to :action => 'login'
82: end
A user can sign up with name and email, a password is generated and sent to the user
# File test/functional/login_controller_test.rb, line 85
85: def test_sign_up_without_pw
86: ENV['EPFWIKI_GENERATE_PASSWORDS'] = '1'
87: ENV['EPFWIKI_DOMAINS'] = ''
88: get :sign_up
89: assert_response :success
90: assert_field 'user_name'
91: assert_field 'user_email'
92: assert_no_field 'user_password'
93: assert_no_field 'user_password_confirmation'
94: assert ENV['EPFWIKI_DOMAINS'].blank?
95: assert_no_tag :tag => 'select'
96: post :sign_up, :user => {:name => "user3", :email=>"user3"} # , :i_agree_to_the_terms_of_use => '1'
97: assert_errors
98: assert_not_nil assigns(:user)
99: assert_equal 'Email is invalid', assigns(:user).errors.full_messages.join(', ')
100: post :sign_up, :user => {:name => "user3", :email=>"user3@somedomain.com"} # , :i_agree_to_the_terms_of_use => '1'
101: @password = assigns(:user).password
102: assert !@password.blank?
103: assert_equal LoginController::FLASH_PW_SENT, flash['success']
104: assert_equal(1, @emails.size)
105: email = @emails.first
106: assert_equal("[#{ENV['EPFWIKI_APP_NAME']}] Welcome", email.subject)
107: assert_equal("user3@somedomain.com", email.to[0])
108: assert_equal([ENV['EPFWIKI_REPLY_ADDRESS']], email.from)
109: assert_redirected_to :action => 'login'
110: end
Shows we can create the central admin
# 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