1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserCreationTest < ActionDispatch::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 "form > fieldset > div.form-row > input.field_with_errors#user_email"
33 assert_no_missing_translations
37 def test_user_create_submit_duplicate_username
38 I18n.available_locales.each do |locale|
39 dup_display_name = users(:public_user).display_name
40 email = "#{locale.to_s}_new_tester"
41 assert_difference('User.count', 0) do
42 assert_difference('ActionMailer::Base.deliveries.size', 0) do
44 {:user => {:email => email, :email_confirmation => email, :display_name => dup_display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}},
45 {"HTTP_ACCEPT_LANGUAGE" => locale.to_s}
48 assert_response :success
49 assert_template 'user/new'
50 assert_select "form > fieldset > div.form-row > input.field_with_errors#user_display_name"
51 assert_no_missing_translations
55 def test_user_create_success
56 I18n.available_locales.each do |locale|
57 new_email = "#{locale.to_s}newtester@osm.org"
58 display_name = "#{locale.to_s}_new_tester"
60 assert_difference('User.count', 0) do
61 assert_difference('ActionMailer::Base.deliveries.size', 0) do
63 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}}
67 assert_redirected_to "/user/terms"
69 assert_difference('User.count') do
70 assert_difference('ActionMailer::Base.deliveries.size', 1) do
71 post_via_redirect "/user/save", {},
72 {"HTTP_ACCEPT_LANGUAGE" => "#{locale.to_s}"}
77 register_email = ActionMailer::Base.deliveries.first
79 assert_equal register_email.to[0], new_email
80 # Check that the confirm account url is correct
81 assert_match /#{@url}/, register_email.body.to_s
84 assert_response :success
85 assert_template 'user/confirm'
87 ActionMailer::Base.deliveries.clear
91 # Check that the user can successfully recover their password
92 def lost_password_recovery_success
93 # Open the lost password form
94 # Submit the lost password form
96 # Submit the reset password token
97 # Check that the password has changed, and the user can login
100 def test_user_create_redirect
101 new_email = "redirect_tester@osm.org"
102 display_name = "redirect_tester"
103 password = "testtest"
104 # nothing special about this page, just need a protected page to redirect back to.
105 referer = "/traces/mine"
106 assert_difference('User.count') do
107 assert_difference('ActionMailer::Base.deliveries.size', 1) do
109 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password}, :referer => referer }
110 assert_redirected_to "/user/terms"
111 post_via_redirect "/user/save",
112 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password} }
117 register_email = ActionMailer::Base.deliveries.first
119 assert_equal register_email.to[0], new_email
120 # Check that the confirm account url is correct
121 confirm_regex = Regexp.new("/user/redirect_tester/confirm\\?confirm_string=([a-zA-Z0-9]*)")
122 register_email.parts.each do |part|
123 assert_match confirm_regex, part.body.to_s
125 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
128 assert_response :success
129 assert_template 'user/confirm'
131 ActionMailer::Base.deliveries.clear
133 # Go to the confirmation page
134 get "/user/#{display_name}/confirm", { :confirm_string => confirm_string }
135 assert_response :success
136 assert_template 'user/confirm'
138 post "user/#{display_name}/confirm", { :confirm_string => confirm_string }
139 assert_response :redirect
141 assert_response :success
142 assert_template 'site/welcome'
145 def test_user_create_openid_success
146 new_email = "newtester-openid@osm.org"
147 display_name = "new_tester-openid"
148 password = "testtest"
149 assert_difference('User.count') do
150 assert_difference('ActionMailer::Base.deliveries.size', 1) do
152 {: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 => ""}}
153 assert_response :redirect
154 res = openid_request(@response.redirect_url)
156 assert_redirected_to "/user/terms"
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 => password, :pass_crypt_confirmation => password}}
159 assert_response :redirect
165 assert_response :success
166 assert_template 'user/confirm'
168 ActionMailer::Base.deliveries.clear
171 def test_user_create_openid_failure
172 new_email = "newtester-openid2@osm.org"
173 display_name = "new_tester-openid2"
174 password = "testtest2"
175 assert_difference('User.count',0) do
176 assert_difference('ActionMailer::Base.deliveries.size',0) do
178 {: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 => ""}}
179 assert_response :redirect
180 res = openid_request(@response.redirect_url)
182 assert_response :success
183 assert_template 'user/new'
187 ActionMailer::Base.deliveries.clear
190 def test_user_create_openid_redirect
191 new_email = "redirect_tester_openid@osm.org"
192 display_name = "redirect_tester_openid"
194 # nothing special about this page, just need a protected page to redirect back to.
195 referer = "/traces/mine"
196 assert_difference('User.count') do
197 assert_difference('ActionMailer::Base.deliveries.size', 1) do
199 {: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 }
200 assert_response :redirect
201 res = openid_request(@response.location)
203 assert_redirected_to "/user/terms"
204 post_via_redirect "/user/save",
205 {: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"} }
210 register_email = ActionMailer::Base.deliveries.first
212 assert_equal register_email.to[0], new_email
213 # Check that the confirm account url is correct
214 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
215 register_email.parts.each do |part|
216 assert_match confirm_regex, part.body.to_s
218 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
221 assert_response :success
222 assert_template 'user/confirm'
224 ActionMailer::Base.deliveries.clear
226 # Go to the confirmation page
227 get "/user/#{display_name}/confirm", { :confirm_string => confirm_string }
228 assert_response :success
229 assert_template 'user/confirm'
231 post "/user/#{display_name}/confirm", { :confirm_string => confirm_string }
232 assert_response :redirect
234 assert_response :success
235 assert_template 'site/welcome'