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 "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"
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_response :success
70 assert_template 'user/terms'
72 assert_difference('User.count') do
73 assert_difference('ActionMailer::Base.deliveries.size', 1) do
74 post_via_redirect "/user/save", {},
75 {"HTTP_ACCEPT_LANGUAGE" => "#{locale.to_s}"}
80 register_email = ActionMailer::Base.deliveries.first
82 assert_equal register_email.to[0], new_email
83 # Check that the confirm account url is correct
84 assert_match /#{@url}/, register_email.body.to_s
87 assert_response :success
88 assert_template 'login'
90 ActionMailer::Base.deliveries.clear
94 # Check that the user can successfully recover their password
95 def lost_password_recovery_success
96 # Open the lost password form
97 # Submit the lost password form
99 # Submit the reset password token
100 # Check that the password has changed, and the user can login
103 def test_user_create_redirect
104 new_email = "redirect_tester@osm.org"
105 display_name = "redirect_tester"
106 password = "testtest"
107 # nothing special about this page, just need a protected page to redirect back to.
108 referer = "/traces/mine"
109 assert_difference('User.count') do
110 assert_difference('ActionMailer::Base.deliveries.size', 1) do
112 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password}, :referer => referer }
113 assert_response :success
114 assert_template 'terms'
115 post_via_redirect "/user/save",
116 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password} }
121 register_email = ActionMailer::Base.deliveries.first
123 assert_equal register_email.to[0], new_email
124 # Check that the confirm account url is correct
125 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
126 register_email.parts.each do |part|
127 assert_match confirm_regex, part.body.to_s
129 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
132 assert_response :success
133 assert_template 'login'
135 ActionMailer::Base.deliveries.clear
137 # Go to the confirmation page
138 get 'user/confirm', { :confirm_string => confirm_string }
139 assert_response :success
140 assert_template 'user/confirm'
142 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
143 assert_response :redirect # to trace/mine in original referrer
145 assert_response :redirect # but it not redirects to /user/<display_name>/traces
147 assert_response :success
148 assert_template 'trace/list'
151 def test_user_create_openid_success
152 new_email = "newtester-openid@osm.org"
153 display_name = "new_tester-openid"
154 password = "testtest"
155 assert_difference('User.count') do
156 assert_difference('ActionMailer::Base.deliveries.size', 1) do
158 {: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 => ""}}
159 assert_response :redirect
160 res = openid_request(@response.redirect_url)
161 post '/user/terms', res
162 assert_response :success
163 assert_template 'terms'
165 {: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}}
166 assert_response :redirect
172 assert_response :success
173 assert_template 'login'
175 ActionMailer::Base.deliveries.clear
178 def test_user_create_openid_failure
179 new_email = "newtester-openid2@osm.org"
180 display_name = "new_tester-openid2"
181 password = "testtest2"
182 assert_difference('User.count',0) do
183 assert_difference('ActionMailer::Base.deliveries.size',0) do
185 {: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 => ""}}
186 assert_response :redirect
187 res = openid_request(@response.redirect_url)
188 post '/user/terms', res
189 assert_response :success
190 assert_template 'user/new'
194 ActionMailer::Base.deliveries.clear
197 def test_user_create_openid_redirect
198 new_email = "redirect_tester_openid@osm.org"
199 display_name = "redirect_tester_openid"
201 # nothing special about this page, just need a protected page to redirect back to.
202 referer = "/traces/mine"
203 assert_difference('User.count') do
204 assert_difference('ActionMailer::Base.deliveries.size', 1) do
206 {: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 }
207 assert_response :redirect
208 res = openid_request(@response.location)
209 post '/user/terms', res
210 assert_response :success
211 assert_template 'terms'
212 post_via_redirect "/user/save",
213 {: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"} }
218 register_email = ActionMailer::Base.deliveries.first
220 assert_equal register_email.to[0], new_email
221 # Check that the confirm account url is correct
222 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
223 register_email.parts.each do |part|
224 assert_match confirm_regex, part.body.to_s
226 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
229 assert_response :success
230 assert_template 'login'
232 ActionMailer::Base.deliveries.clear
234 # Go to the confirmation page
235 get 'user/confirm', { :confirm_string => confirm_string }
236 assert_response :success
237 assert_template 'user/confirm'
239 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
240 assert_response :redirect # to trace/mine in original referrer
242 assert_response :redirect # but it not redirects to /user/<display_name>/traces
244 assert_response :success
245 assert_template "trace/list"