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=fieldWithErrors] > 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=fieldWithErrors] > 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
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 assert_match(confirm_regex, register_email.body)
117 confirm_string = confirm_regex.match(register_email.body)[1]
120 assert_response :success
121 assert_template 'login'
123 ActionMailer::Base.deliveries.clear
125 # Go to the confirmation page
126 get 'user/confirm', { :confirm_string => confirm_string }
127 assert_response :success
128 assert_template 'user/confirm'
130 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
131 assert_response :redirect # to trace/mine in original referrer
133 assert_response :redirect # but it not redirects to /user/<display_name>/traces
135 assert_response :success
136 assert_template "trace/list.html.erb"
139 def test_user_create_openid_success
140 new_email = "newtester-openid@osm.org"
141 display_name = "new_tester-openid"
142 password = "testtest"
143 assert_difference('User.count') do
144 assert_difference('ActionMailer::Base.deliveries.size', 1) do
146 {: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 => ""}}
147 assert_response :redirect
148 res = openid_request(@response.redirected_to)
149 post '/user/terms', res
150 assert_response :success
151 assert_template 'terms'
153 {: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}}
154 assert_response :redirect
160 assert_response :success
161 assert_template 'login'
163 ActionMailer::Base.deliveries.clear
166 def test_user_create_openid_failure
167 new_email = "newtester-openid2@osm.org"
168 display_name = "new_tester-openid2"
169 password = "testtest2"
170 assert_difference('User.count',0) do
171 assert_difference('ActionMailer::Base.deliveries.size',0) do
173 {: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 => ""}}
174 assert_response :redirect
175 res = openid_request(@response.redirected_to)
176 post '/user/terms', res
177 assert_response :success
178 assert_template 'user/new'
182 ActionMailer::Base.deliveries.clear
185 def test_user_create_openid_redirect
186 new_email = "redirect_tester_openid@osm.org"
187 display_name = "redirect_tester_openid"
189 # nothing special about this page, just need a protected page to redirect back to.
190 referer = "/traces/mine"
191 assert_difference('User.count') do
192 assert_difference('ActionMailer::Base.deliveries.size', 1) do
194 {: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 }
195 assert_response :redirect
196 res = openid_request(@response.location)
197 post '/user/terms', res
198 assert_response :success
199 assert_template 'terms'
200 post_via_redirect "/user/save",
201 {: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"} }
206 register_email = ActionMailer::Base.deliveries.first
208 assert_equal register_email.to[0], new_email
209 # Check that the confirm account url is correct
210 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
211 assert_match(confirm_regex, register_email.body)
212 confirm_string = confirm_regex.match(register_email.body)[1]
215 assert_response :success
216 assert_template 'login'
218 ActionMailer::Base.deliveries.clear
220 # Go to the confirmation page
221 get 'user/confirm', { :confirm_string => confirm_string }
222 assert_response :success
223 assert_template 'user/confirm'
225 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
226 assert_response :redirect # to trace/mine in original referrer
228 assert_response :redirect # but it not redirects to /user/<display_name>/traces
230 assert_response :success
231 assert_template "trace/list.html.erb"