source: subversion/sites/rails_port/test/functional/user_controller_test.rb @ 15832

Last change on this file since 15832 was 15758, checked in by Shaun McDonald, 10 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: 2.9 KB
Line 
1require File.dirname(__FILE__) + '/../test_helper'
2
3class UserControllerTest < ActionController::TestCase
4  fixtures :users
5 
6  # The user creation page loads
7  def test_user_create_view
8    get :new
9    assert_response :success
10   
11    assert_select "html:root", :count => 1 do
12      assert_select "head", :count => 1 do
13        assert_select "title", :text => /Create account/, :count => 1
14      end
15      assert_select "body", :count => 1 do
16        assert_select "div#content", :count => 1 do
17          assert_select "form[action='/user/save'][method=post]", :count => 1 do
18            assert_select "input[id=user_email]", :count => 1
19            assert_select "input[id=user_email_confirmation]", :count => 1
20            assert_select "input[id=user_display_name]", :count => 1
21            assert_select "input[id=user_pass_crypt][type=password]", :count => 1
22            assert_select "input[id=user_pass_crypt_confirmation][type=password]", :count => 1
23            assert_select "input[type=submit][value=Signup]", :count => 1
24          end
25        end
26      end
27    end
28  end
29 
30  def test_user_create_success
31    new_email = "newtester@osm.org"
32    display_name = "new_tester"
33    assert_difference('User.count') do
34      assert_difference('ActionMailer::Base.deliveries.size') do
35        post :save, {:user => { :email => new_email, :email_confirmation => new_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}}
36      end
37    end
38     
39    # Check the e-mail
40    register_email = ActionMailer::Base.deliveries.first
41 
42    assert_equal register_email.to[0], new_email
43    assert_match /#{@url}/, register_email.body
44
45    # Check the page
46    assert_redirected_to :action => 'login'
47     
48    ActionMailer::Base.deliveries.clear
49  end
50 
51  def test_user_create_submit_duplicate_email
52    dup_email = users(:public_user).email
53    display_name = "new_tester"
54    assert_difference('User.count', 0) do
55      assert_difference('ActionMailer::Base.deliveries.size', 0) do
56        post :save, :user => { :email => dup_email, :email_confirmation => dup_email, :display_name => display_name, :pass_crypt => "testtest", :pass_crypt_confirmation => "testtest"}
57      end
58    end
59    assert_response :success                                                                       
60    assert_template 'new'
61    assert_select "div#errorExplanation"
62    assert_select "table#loginForm > tr > td > div[class=fieldWithErrors] > input#user_email"
63  end
64 
65  # Check that the user account page will display and contains some relevant
66  # information for the user
67  def test_view_user_account
68    get :view
69    assert_response :not_found
70   
71    get :view, {:display_name => "test"}
72    assert_response :success
73  end
74 
75  def test_user_api_details
76    get :api_details
77    assert_response :unauthorized
78   
79    basic_authorization(users(:normal_user).email, "test")
80    get :api_details
81    assert_response :success
82  end
83end
Note: See TracBrowser for help on using the repository browser.