1 | require File.dirname(__FILE__) + '/../test_helper' |
---|
2 | require 'admincontact_controller' |
---|
3 | |
---|
4 | # Re-raise errors caught by the controller. |
---|
5 | class AdmincontactController; def rescue_action(e) raise e end; end |
---|
6 | |
---|
7 | class AdmincontactControllerTest < Test::Unit::TestCase |
---|
8 | fixtures :contacts |
---|
9 | |
---|
10 | def setup |
---|
11 | @controller = AdmincontactController.new |
---|
12 | @request = ActionController::TestRequest.new |
---|
13 | @response = ActionController::TestResponse.new |
---|
14 | |
---|
15 | @first_id = contacts(:first).id |
---|
16 | end |
---|
17 | |
---|
18 | def test_index |
---|
19 | get :index |
---|
20 | assert_response :success |
---|
21 | assert_template 'list' |
---|
22 | end |
---|
23 | |
---|
24 | def test_list |
---|
25 | get :list |
---|
26 | |
---|
27 | assert_response :success |
---|
28 | assert_template 'list' |
---|
29 | |
---|
30 | assert_not_nil assigns(:contacts) |
---|
31 | end |
---|
32 | |
---|
33 | def test_show |
---|
34 | get :show, :id => @first_id |
---|
35 | |
---|
36 | assert_response :success |
---|
37 | assert_template 'show' |
---|
38 | |
---|
39 | assert_not_nil assigns(:contact) |
---|
40 | assert assigns(:contact).valid? |
---|
41 | end |
---|
42 | |
---|
43 | def test_new |
---|
44 | get :new |
---|
45 | |
---|
46 | assert_response :success |
---|
47 | assert_template 'new' |
---|
48 | |
---|
49 | assert_not_nil assigns(:contact) |
---|
50 | end |
---|
51 | |
---|
52 | def test_create |
---|
53 | num_contacts = Contact.count |
---|
54 | |
---|
55 | post :create, :contact => {} |
---|
56 | |
---|
57 | assert_response :redirect |
---|
58 | assert_redirected_to :action => 'list' |
---|
59 | |
---|
60 | assert_equal num_contacts + 1, Contact.count |
---|
61 | end |
---|
62 | |
---|
63 | def test_edit |
---|
64 | get :edit, :id => @first_id |
---|
65 | |
---|
66 | assert_response :success |
---|
67 | assert_template 'edit' |
---|
68 | |
---|
69 | assert_not_nil assigns(:contact) |
---|
70 | assert assigns(:contact).valid? |
---|
71 | end |
---|
72 | |
---|
73 | def test_update |
---|
74 | post :update, :id => @first_id |
---|
75 | assert_response :redirect |
---|
76 | assert_redirected_to :action => 'show', :id => @first_id |
---|
77 | end |
---|
78 | |
---|
79 | def test_destroy |
---|
80 | assert_nothing_raised { |
---|
81 | Contact.find(@first_id) |
---|
82 | } |
---|
83 | |
---|
84 | post :destroy, :id => @first_id |
---|
85 | assert_response :redirect |
---|
86 | assert_redirected_to :action => 'list' |
---|
87 | |
---|
88 | assert_raise(ActiveRecord::RecordNotFound) { |
---|
89 | Contact.find(@first_id) |
---|
90 | } |
---|
91 | end |
---|
92 | end |
---|