/
users_controller_test.rb
82 lines (69 loc) · 2.04 KB
/
users_controller_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require File.dirname(__FILE__) + '/../test_helper'
require 'users_controller'
# Re-raise errors caught by the controller.
class UsersController; def rescue_action(e) raise e end; end
class UsersControllerTest < Test::Unit::TestCase
fixtures :users
def setup
@controller = UsersController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
def test_should_get_new
User.expects(:count).returns(0)
get :new
assert_response :success
end
def test_should_not_get_new_if_users_exist
get :new
assert_redirected_to root_path
end
def test_should_not_get_new_if_users_exist_even_for_relative_url
set_relative_url do
get :new
assert_redirected_to root_path
end
end
def test_should_allow_signup
assert_difference 'User.count' do
create_user
assert_response :redirect
assert_redirected_to root_path
end
end
def test_should_allow_signup_when_relative_url
set_relative_url do
assert_difference 'User.count' do
create_user
assert_response :redirect
assert_redirected_to root_path
end
end
end
def test_should_require_password_on_signup
assert_no_difference 'User.count' do
create_user(:password => nil)
assert assigns(:user).errors.on(:password)
assert_response :success
end
end
def test_should_require_password_confirmation_on_signup
assert_no_difference 'User.count' do
create_user(:password_confirmation => nil)
assert assigns(:user).errors.on(:password_confirmation)
assert_response :success
end
end
def test_should_require_email_on_signup
assert_no_difference 'User.count' do
create_user(:email => nil)
assert assigns(:user).errors.on(:email)
assert_response :success
end
end
protected
def create_user(options = {})
post :create, :user => { :email => 'quire@example.com', :name => 'quire',
:password => 'quire', :password_confirmation => 'quire' }.merge(options)
end
end