1 require File.dirname(__FILE__) + '/../test_helper'
3 class UserControllerTest < ActionController::TestCase
6 # The user creation page loads
7 def test_user_create_view
9 assert_response :success
11 assert_select "html", :count => 1 do
12 assert_select "head", :count => 1 do
13 assert_select "title", :text => /Create account/, :count => 1
15 assert_select "body", :count => 1 do
16 assert_select "div#content", :count => 1 do
17 assert_select "form[action='/user/terms'][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=Continue]", :count => 1
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"}}
40 register_email = ActionMailer::Base.deliveries.first
42 assert_equal register_email.to[0], new_email
43 assert_match /#{@url}/, register_email.body
46 assert_redirected_to :action => 'login', :referer => nil
48 ActionMailer::Base.deliveries.clear
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"}
59 assert_response :success
61 assert_select "div#errorExplanation"
62 assert_select "table#signupForm > tr > td > div[class=fieldWithErrors] > input#user_email"
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, {:display_name => "unknown"}
69 assert_response :not_found
71 get :view, {:display_name => "test"}
72 assert_response :success
75 def test_user_api_details
77 assert_response :unauthorized
79 basic_authorization(users(:normal_user).email, "test")
81 assert_response :success