1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserCreationTest < ActionController::IntegrationTest
10 def test_create_user_form
11 I18n.available_locales.each do |locale|
12 get '/user/new', {}, {"HTTP_ACCEPT_LANGUAGE" => locale.to_s}
13 assert_response :success
14 assert_template 'user/new'
18 def test_user_create_submit_duplicate_email
19 I18n.available_locales.each do |localer|
20 dup_email = users(:public_user).email
21 display_name = "#{localer.to_s}_new_tester"
22 assert_difference('User.count', 0) do
23 assert_difference('ActionMailer::Base.deliveries.size', 0) do
25 {:user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
26 {"HTTP_ACCEPT_LANGUAGE" => localer.to_s}
29 assert_response :success
30 assert_template 'user/new'
31 assert_equal response.headers['Content-Language'][0..1], localer.to_s[0..1] unless localer == :root
32 assert_select "div#errorExplanation"
33 assert_select "table#signupForm > tr > td > div[class=field_with_errors] > input#user_email"
34 assert_no_missing_translations
38 def test_user_create_submit_duplicate_username
39 I18n.available_locales.each do |locale|
40 dup_display_name = users(:public_user).display_name
41 email = "#{locale.to_s}_new_tester"
42 assert_difference('User.count', 0) do
43 assert_difference('ActionMailer::Base.deliveries.size', 0) do
45 {:user => {:email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
46 {"HTTP_ACCEPT_LANGUAGE" => locale.to_s}
49 assert_response :success
50 assert_template 'user/new'
51 assert_select "div#errorExplanation"
52 assert_select "table#signupForm > tr > td > div[class=field_with_errors] > input#user_display_name"
53 assert_no_missing_translations
57 def test_user_create_success
58 I18n.available_locales.each do |locale|
59 new_email = "#{locale.to_s}newtester@osm.org"
60 display_name = "#{locale.to_s}_new_tester"
61 assert_difference('User.count') do
62 assert_difference('ActionMailer::Base.deliveries.size', 1) do
63 post_via_redirect "/user/save",
64 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
65 {"HTTP_ACCEPT_LANGUAGE" => "#{locale.to_s}"}
70 register_email = ActionMailer::Base.deliveries.first
72 assert_equal register_email.to[0], new_email
73 # Check that the confirm account url is correct
74 assert_match /#{@url}/, register_email.body.to_s
77 assert_response :success
78 assert_template 'login'
80 ActionMailer::Base.deliveries.clear
84 # Check that the user can successfully recover their password
85 def lost_password_recovery_success
86 # Open the lost password form
87 # Submit the lost password form
89 # Submit the reset password token
90 # Check that the password has changed, and the user can login
93 def test_user_create_redirect
94 new_email = "redirect_tester@osm.org"
95 display_name = "redirect_tester"
97 # nothing special about this page, just need a protected page to redirect back to.
98 referer = "/traces/mine"
99 assert_difference('User.count') do
100 assert_difference('ActionMailer::Base.deliveries.size', 1) do
102 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password}, :referer => referer }
103 assert_response :success
104 assert_template 'terms'
105 post_via_redirect "/user/save",
106 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password} }
111 register_email = ActionMailer::Base.deliveries.first
113 assert_equal register_email.to[0], new_email
114 # Check that the confirm account url is correct
115 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
116 register_email.parts.each do |part|
117 assert_match confirm_regex, part.body.to_s
119 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
122 assert_response :success
123 assert_template 'login'
125 ActionMailer::Base.deliveries.clear
127 # Go to the confirmation page
128 get 'user/confirm', { :confirm_string => confirm_string }
129 assert_response :success
130 assert_template 'user/confirm'
132 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
133 assert_response :redirect # to trace/mine in original referrer
135 assert_response :redirect # but it not redirects to /user/<display_name>/traces
137 assert_response :success
138 assert_template 'trace/list'
141 def test_user_create_openid_success
142 new_email = "newtester-openid@osm.org"
143 display_name = "new_tester-openid"
144 password = "testtest"
145 assert_difference('User.count') do
146 assert_difference('ActionMailer::Base.deliveries.size', 1) do
148 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => "", :pass_crypt_confirmation => ""}}
149 assert_response :redirect
150 res = openid_request(@response.redirect_url)
151 post '/user/terms', res
152 assert_response :success
153 assert_template 'terms'
155 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => password, :pass_crypt_confirmation => password}}
156 assert_response :redirect
162 assert_response :success
163 assert_template 'login'
165 ActionMailer::Base.deliveries.clear
168 def test_user_create_openid_failure
169 new_email = "newtester-openid2@osm.org"
170 display_name = "new_tester-openid2"
171 password = "testtest2"
172 assert_difference('User.count',0) do
173 assert_difference('ActionMailer::Base.deliveries.size',0) do
175 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.failure=newuser", :pass_crypt => "", :pass_crypt_confirmation => ""}}
176 assert_response :redirect
177 res = openid_request(@response.redirect_url)
178 post '/user/terms', res
179 assert_response :success
180 assert_template 'user/new'
184 ActionMailer::Base.deliveries.clear
187 def test_user_create_openid_redirect
188 new_email = "redirect_tester_openid@osm.org"
189 display_name = "redirect_tester_openid"
191 # nothing special about this page, just need a protected page to redirect back to.
192 referer = "/traces/mine"
193 assert_difference('User.count') do
194 assert_difference('ActionMailer::Base.deliveries.size', 1) do
196 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => "", :pass_crypt_confirmation => ""}, :referer => referer }
197 assert_response :redirect
198 res = openid_request(@response.location)
199 post '/user/terms', res
200 assert_response :success
201 assert_template 'terms'
202 post_via_redirect "/user/save",
203 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser", :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"} }
208 register_email = ActionMailer::Base.deliveries.first
210 assert_equal register_email.to[0], new_email
211 # Check that the confirm account url is correct
212 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
213 register_email.parts.each do |part|
214 assert_match confirm_regex, part.body.to_s
216 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
219 assert_response :success
220 assert_template 'login'
222 ActionMailer::Base.deliveries.clear
224 # Go to the confirmation page
225 get 'user/confirm', { :confirm_string => confirm_string }
226 assert_response :success
227 assert_template 'user/confirm'
229 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
230 assert_response :redirect # to trace/mine in original referrer
232 assert_response :redirect # but it not redirects to /user/<display_name>/traces
234 assert_response :success
235 assert_template "trace/list"