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_via_redirect '/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 "div#signupForm > fieldset > div.form-row > div.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 "div#signupForm > fieldset > div.form-row > div.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"
62 assert_difference('User.count', 0) do
63 assert_difference('ActionMailer::Base.deliveries.size', 0) do
65 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}}
69 assert_redirected_to "/user/terms"
71 assert_difference('User.count') do
72 assert_difference('ActionMailer::Base.deliveries.size', 1) do
73 post_via_redirect "/user/save", {},
74 {"HTTP_ACCEPT_LANGUAGE" => "#{locale.to_s}"}
79 register_email = ActionMailer::Base.deliveries.first
81 assert_equal register_email.to[0], new_email
82 # Check that the confirm account url is correct
83 assert_match /#{@url}/, register_email.body.to_s
86 assert_response :success
87 assert_template 'login'
89 ActionMailer::Base.deliveries.clear
93 # Check that the user can successfully recover their password
94 def lost_password_recovery_success
95 # Open the lost password form
96 # Submit the lost password form
98 # Submit the reset password token
99 # Check that the password has changed, and the user can login
102 def test_user_create_redirect
103 new_email = "redirect_tester@osm.org"
104 display_name = "redirect_tester"
105 password = "testtest"
106 # nothing special about this page, just need a protected page to redirect back to.
107 referer = "/traces/mine"
108 assert_difference('User.count') do
109 assert_difference('ActionMailer::Base.deliveries.size', 1) do
111 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password}, :referer => referer }
112 assert_redirected_to "/user/terms"
113 post_via_redirect "/user/save",
114 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password} }
119 register_email = ActionMailer::Base.deliveries.first
121 assert_equal register_email.to[0], new_email
122 # Check that the confirm account url is correct
123 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
124 register_email.parts.each do |part|
125 assert_match confirm_regex, part.body.to_s
127 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
130 assert_response :success
131 assert_template 'login'
133 ActionMailer::Base.deliveries.clear
135 # Go to the confirmation page
136 get 'user/confirm', { :confirm_string => confirm_string }
137 assert_response :success
138 assert_template 'user/confirm'
140 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
141 assert_response :redirect # to trace/mine in original referrer
143 assert_response :redirect # but it not redirects to /user/<display_name>/traces
145 assert_response :success
146 assert_template 'trace/list'
149 def test_user_create_openid_success
150 new_email = "newtester-openid@osm.org"
151 display_name = "new_tester-openid"
152 password = "testtest"
153 assert_difference('User.count') do
154 assert_difference('ActionMailer::Base.deliveries.size', 1) do
156 {: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 => ""}}
157 assert_response :redirect
158 res = openid_request(@response.redirect_url)
160 assert_redirected_to "/user/terms"
162 {: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}}
163 assert_response :redirect
169 assert_response :success
170 assert_template 'login'
172 ActionMailer::Base.deliveries.clear
175 def test_user_create_openid_failure
176 new_email = "newtester-openid2@osm.org"
177 display_name = "new_tester-openid2"
178 password = "testtest2"
179 assert_difference('User.count',0) do
180 assert_difference('ActionMailer::Base.deliveries.size',0) do
182 {: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 => ""}}
183 assert_response :redirect
184 res = openid_request(@response.redirect_url)
186 assert_response :success
187 assert_template 'user/new'
191 ActionMailer::Base.deliveries.clear
194 def test_user_create_openid_redirect
195 new_email = "redirect_tester_openid@osm.org"
196 display_name = "redirect_tester_openid"
198 # nothing special about this page, just need a protected page to redirect back to.
199 referer = "/traces/mine"
200 assert_difference('User.count') do
201 assert_difference('ActionMailer::Base.deliveries.size', 1) do
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 => "", :pass_crypt_confirmation => ""}, :referer => referer }
204 assert_response :redirect
205 res = openid_request(@response.location)
207 assert_redirected_to "/user/terms"
208 post_via_redirect "/user/save",
209 {: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"} }
214 register_email = ActionMailer::Base.deliveries.first
216 assert_equal register_email.to[0], new_email
217 # Check that the confirm account url is correct
218 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
219 register_email.parts.each do |part|
220 assert_match confirm_regex, part.body.to_s
222 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
225 assert_response :success
226 assert_template 'login'
228 ActionMailer::Base.deliveries.clear
230 # Go to the confirmation page
231 get 'user/confirm', { :confirm_string => confirm_string }
232 assert_response :success
233 assert_template 'user/confirm'
235 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
236 assert_response :redirect # to trace/mine in original referrer
238 assert_response :redirect # but it not redirects to /user/<display_name>/traces
240 assert_response :success
241 assert_template "trace/list"