source: subversion/sites/rails_port/test/integration/user_creation_test.rb @ 16119

Last change on this file since 16119 was 15758, checked in by Shaun McDonald, 11 years ago

More tests to check that user creation works, and the url in the e-mail is the same. Seems that we can only test that a particular page is loading fine in all locales in the integration tests, and not the functional tests.

File size: 3.4 KB
Line 
1require File.dirname(__FILE__) + '/../test_helper'
2
3class UserCreationTest < ActionController::IntegrationTest
4  fixtures :users
5
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'
11    end
12  end
13 
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
20          post '/user/save', 
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}
23        end
24      end
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#loginForm > tr > td > div[class=fieldWithErrors] > input#user_email"
30      assert_no_missing_translations
31    end
32  end
33 
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
40          post '/user/save',
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}
43        end
44      end
45      assert_response :success
46      assert_template 'user/new'
47      assert_select "div#errorExplanation"
48      assert_select "table#loginForm > tr > td > div[class=fieldWithErrors] > input#user_display_name"
49      assert_no_missing_translations
50    end
51  end
52 
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}"}
62        end
63      end
64     
65      # Check the e-mail
66      register_email = ActionMailer::Base.deliveries.first
67   
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
71     
72      # Check the page
73      assert_response :success
74      assert_template 'login'
75     
76      ActionMailer::Base.deliveries.clear
77    end
78  end
79 
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
84    # Check the e-mail
85    # Submit the reset password token
86    # Check that the password has changed, and the user can login
87  end
88end
Note: See TracBrowser for help on using the repository browser.