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 |locale|
20 dup_email = users(:public_user).email
21 display_name = "#{locale}_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" => locale.to_s }
29 assert_response :success
30 assert_template "user/new"
31 assert_equal response.headers["Content-Language"][0..1], locale.to_s[0..1] unless locale == :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}_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}newtester@osm.org"
58 display_name = "#{locale}_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}" }
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 assert_difference("User.count", 0) do
175 assert_difference("ActionMailer::Base.deliveries.size", 0) do
177 :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 => "" }
178 assert_response :redirect
179 res = openid_request(@response.redirect_url)
181 assert_response :success
182 assert_template "user/new"
186 ActionMailer::Base.deliveries.clear
189 def test_user_create_openid_redirect
190 new_email = "redirect_tester_openid@osm.org"
191 display_name = "redirect_tester_openid"
192 # nothing special about this page, just need a protected page to redirect back to.
193 referer = "/traces/mine"
194 assert_difference("User.count") do
195 assert_difference("ActionMailer::Base.deliveries.size", 1) do
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 => "", :pass_crypt_confirmation => "" }, :referer => referer
198 assert_response :redirect
199 res = openid_request(@response.location)
201 assert_redirected_to "/user/terms"
202 post_via_redirect "/user/save",
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 => "testtest", :pass_crypt_confirmation => "testtest" }
208 register_email = ActionMailer::Base.deliveries.first
210 assert_equal register_email.to[0], new_email
211 # Check that the confirm account url is correct
212 confirm_regex = Regexp.new("/user/redirect_tester_openid/confirm\\?confirm_string=([a-zA-Z0-9]*)")
213 register_email.parts.each do |part|
214 assert_match confirm_regex, part.body.to_s
216 confirm_string = register_email.parts[0].body.match(confirm_regex)[1]
219 assert_response :success
220 assert_template "user/confirm"
222 ActionMailer::Base.deliveries.clear
224 # Go to the confirmation page
225 get "/user/#{display_name}/confirm", :confirm_string => confirm_string
226 assert_response :success
227 assert_template "user/confirm"
229 post "/user/#{display_name}/confirm", :confirm_string => confirm_string
230 assert_response :redirect
232 assert_response :success
233 assert_template "site/welcome"