1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserCreationTest < ActionController::IntegrationTest
6 def test_create_user_form
7 I18n.available_locales.each do |locale|
8 get '/user/new', {}, {"accept_language" => locale.to_s}
9 assert_response :success
10 assert_template 'user/new'
14 def test_user_create_submit_duplicate_email
15 I18n.available_locales.each do |localer|
16 dup_email = users(:public_user).email
17 display_name = "#{localer.to_s}_new_tester"
18 assert_difference('User.count', 0) do
19 assert_difference('ActionMailer::Base.deliveries.size', 0) do
21 {:user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
22 {"accept_language" => localer.to_s}
25 assert_response :success
26 assert_template 'user/new'
27 assert_equal response.headers['Content-Language'][0..1], localer.to_s[0..1] unless localer == :root
28 assert_select "div#errorExplanation"
29 assert_select "table#signupForm > tr > td > div[class=fieldWithErrors] > input#user_email"
30 assert_no_missing_translations
34 def test_user_create_submit_duplicate_username
35 I18n.available_locales.each do |locale|
36 dup_display_name = users(:public_user).display_name
37 email = "#{locale.to_s}_new_tester"
38 assert_difference('User.count', 0) do
39 assert_difference('ActionMailer::Base.deliveries.size', 0) do
41 {:user => {:email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
42 {"accept_language" => locale.to_s}
45 assert_response :success
46 assert_template 'user/new'
47 assert_select "div#errorExplanation"
48 assert_select "table#signupForm > tr > td > div[class=fieldWithErrors] > input#user_display_name"
49 assert_no_missing_translations
53 def test_user_create_success
54 I18n.available_locales.each do |locale|
55 new_email = "#{locale.to_s}newtester@osm.org"
56 display_name = "#{locale.to_s}_new_tester"
57 assert_difference('User.count') do
58 assert_difference('ActionMailer::Base.deliveries.size', 1) do
59 post_via_redirect "/user/save",
60 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
61 {"accept_language" => "#{locale.to_s}"}
66 register_email = ActionMailer::Base.deliveries.first
68 assert_equal register_email.to[0], new_email
69 # Check that the confirm account url is correct
70 assert_match /#{@url}/, register_email.body
73 assert_response :success
74 assert_template 'login'
76 ActionMailer::Base.deliveries.clear
80 # Check that the user can successfully recover their password
81 def lost_password_recovery_success
82 # Open the lost password form
83 # Submit the lost password form
85 # Submit the reset password token
86 # Check that the password has changed, and the user can login
89 def test_user_create_redirect
90 new_email = "redirect_tester@osm.org"
91 display_name = "redirect_tester"
93 # nothing special about this page, just need a protected page to redirect back to.
94 referer = "/traces/mine"
95 assert_difference('User.count') do
96 assert_difference('ActionMailer::Base.deliveries.size', 1) do
98 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password}, :referer => referer }
99 assert_response :success
100 assert_template 'terms'
101 post_via_redirect "/user/save",
102 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password} }
107 register_email = ActionMailer::Base.deliveries.first
109 assert_equal register_email.to[0], new_email
110 # Check that the confirm account url is correct
111 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
112 assert_match(confirm_regex, register_email.body)
113 confirm_string = confirm_regex.match(register_email.body)[1]
116 assert_response :success
117 assert_template 'login'
119 ActionMailer::Base.deliveries.clear
121 # Go to the confirmation page
122 get 'user/confirm', { :confirm_string => confirm_string }
123 assert_response :success
124 assert_template 'user/confirm'
126 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
127 assert_response :redirect # to trace/mine in original referrer
129 assert_response :redirect # but it not redirects to /user/<display_name>/traces
131 assert_response :success
132 assert_template "trace/list.html.erb"
135 def test_user_create_openid_success
136 new_email = "newtester-openid@osm.org"
137 display_name = "new_tester-openid"
138 password = "testtest"
139 assert_difference('User.count') do
140 assert_difference('ActionMailer::Base.deliveries.size', 1) do
142 {: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 => ""}}
143 assert_response :redirect
144 res = openid_request(@response.redirected_to)
145 post '/user/terms', res
146 assert_response :success
147 assert_template 'terms'
149 {: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}}
150 assert_response :redirect
156 assert_response :success
157 assert_template 'login'
159 ActionMailer::Base.deliveries.clear
162 def test_user_create_openid_failure
163 new_email = "newtester-openid2@osm.org"
164 display_name = "new_tester-openid2"
165 password = "testtest2"
166 assert_difference('User.count',0) do
167 assert_difference('ActionMailer::Base.deliveries.size',0) do
169 {: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 => ""}}
170 assert_response :redirect
171 res = openid_request(@response.redirected_to)
172 post '/user/terms', res
173 assert_response :success
174 assert_template 'user/new'
178 ActionMailer::Base.deliveries.clear
181 def test_user_create_openid_redirect
182 new_email = "redirect_tester_openid@osm.org"
183 display_name = "redirect_tester_openid"
185 # nothing special about this page, just need a protected page to redirect back to.
186 referer = "/traces/mine"
187 assert_difference('User.count') do
188 assert_difference('ActionMailer::Base.deliveries.size', 1) do
190 {: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 }
191 assert_response :redirect
192 res = openid_request(@response.location)
193 post '/user/terms', res
194 assert_response :success
195 assert_template 'terms'
196 post_via_redirect "/user/save",
197 {: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"} }
202 register_email = ActionMailer::Base.deliveries.first
204 assert_equal register_email.to[0], new_email
205 # Check that the confirm account url is correct
206 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
207 assert_match(confirm_regex, register_email.body)
208 confirm_string = confirm_regex.match(register_email.body)[1]
211 assert_response :success
212 assert_template 'login'
214 ActionMailer::Base.deliveries.clear
216 # Go to the confirmation page
217 get 'user/confirm', { :confirm_string => confirm_string }
218 assert_response :success
219 assert_template 'user/confirm'
221 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
222 assert_response :redirect # to trace/mine in original referrer
224 assert_response :redirect # but it not redirects to /user/<display_name>/traces
226 assert_response :success
227 assert_template "trace/list.html.erb"