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
97 post_via_redirect "/user/save",
98 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => password, :pass_crypt_confirmation => password}, :referer => referer }
103 register_email = ActionMailer::Base.deliveries.first
105 assert_equal register_email.to[0], new_email
106 # Check that the confirm account url is correct
107 confirm_regex = Regexp.new("/user/confirm\\?confirm_string=([a-zA-Z0-9]*)")
108 assert_match(confirm_regex, register_email.body)
109 confirm_string = confirm_regex.match(register_email.body)[1]
112 assert_response :success
113 assert_template 'login'
115 ActionMailer::Base.deliveries.clear
117 # Go to the confirmation page
118 get 'user/confirm', { :confirm_string => confirm_string }
119 assert_response :success
120 assert_template 'user/confirm'
122 post 'user/confirm', { :confirm_string => confirm_string, :confirm_action => 'submit' }
123 assert_response :redirect # to trace/mine in original referrer
125 assert_response :redirect # but it not redirects to /user/<display_name>/traces
127 assert_response :success
128 assert_template "trace/list.html.erb"
131 def test_user_create_openid_success
132 new_email = "newtester-openid@osm.org"
133 display_name = "new_tester-openid"
134 assert_difference('User.count') do
135 assert_difference('ActionMailer::Base.deliveries.size', 1) do
137 {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :openid_url => "http://localhost:1123/john.doe?openid.success=newuser"}}
138 assert_response :redirect
139 res = openid_request(@response.redirected_to)
140 post '/user/save', res
141 assert_response :redirect
147 assert_response :success
148 assert_template 'login'
150 ActionMailer::Base.deliveries.clear