@@ -1,83 +1,95 | |||||
1 | require File.expand_path('../../test_helper', __FILE__) |
|
1 | require File.expand_path('../../test_helper', __FILE__) | |
2 |
|
2 | |||
3 | class AuthSourcesControllerTest < ActionController::TestCase |
|
3 | class AuthSourcesControllerTest < ActionController::TestCase | |
4 | fixtures :all |
|
4 | fixtures :all | |
5 |
|
5 | |||
6 | def setup |
|
6 | def setup | |
7 | @request.session[:user_id] = 1 |
|
7 | @request.session[:user_id] = 1 | |
8 | end |
|
8 | end | |
9 |
|
9 | |||
10 | context "get :index" do |
|
10 | context "get :index" do | |
11 | setup do |
|
11 | setup do | |
12 | get :index |
|
12 | get :index | |
13 | end |
|
13 | end | |
14 |
|
14 | |||
15 | should_assign_to :auth_sources |
|
15 | should_assign_to :auth_sources | |
16 | should_assign_to :auth_source_pages |
|
16 | should_assign_to :auth_source_pages | |
17 | should_respond_with :success |
|
17 | should_respond_with :success | |
18 | should_render_template :index |
|
18 | should_render_template :index | |
19 | end |
|
19 | end | |
20 |
|
20 | |||
21 | context "get :new" do |
|
21 | context "get :new" do | |
22 | setup do |
|
22 | setup do | |
23 | get :new |
|
23 | get :new | |
24 | end |
|
24 | end | |
25 |
|
25 | |||
26 | should_assign_to :auth_source |
|
26 | should_assign_to :auth_source | |
27 | should_respond_with :success |
|
27 | should_respond_with :success | |
28 | should_render_template :new |
|
28 | should_render_template :new | |
29 |
|
29 | |||
30 | should "initilize a new AuthSource" do |
|
30 | should "initilize a new AuthSource" do | |
31 | assert_equal AuthSource, assigns(:auth_source).class |
|
31 | assert_equal AuthSource, assigns(:auth_source).class | |
32 | assert assigns(:auth_source).new_record? |
|
32 | assert assigns(:auth_source).new_record? | |
33 | end |
|
33 | end | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | context "post :create" do |
|
36 | context "post :create" do | |
37 | setup do |
|
37 | setup do | |
38 | post :create, :auth_source => {:name => 'Test'} |
|
38 | post :create, :auth_source => {:name => 'Test'} | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | should_respond_with :redirect |
|
41 | should_respond_with :redirect | |
42 | should_redirect_to("index") {{:action => 'index'}} |
|
42 | should_redirect_to("index") {{:action => 'index'}} | |
43 | should_set_the_flash_to /success/i |
|
43 | should_set_the_flash_to /success/i | |
44 | end |
|
44 | end | |
45 |
|
45 | |||
46 | context "get :edit" do |
|
46 | context "get :edit" do | |
47 | setup do |
|
47 | setup do | |
48 | @auth_source = AuthSource.generate!(:name => 'TestEdit') |
|
48 | @auth_source = AuthSource.generate!(:name => 'TestEdit') | |
49 | get :edit, :id => @auth_source.id |
|
49 | get :edit, :id => @auth_source.id | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | should_assign_to(:auth_source) {@auth_source} |
|
52 | should_assign_to(:auth_source) {@auth_source} | |
53 | should_respond_with :success |
|
53 | should_respond_with :success | |
54 | should_render_template :edit |
|
54 | should_render_template :edit | |
55 | end |
|
55 | end | |
56 |
|
56 | |||
57 | context "post :update" do |
|
57 | context "post :update" do | |
58 | setup do |
|
58 | setup do | |
59 | @auth_source = AuthSource.generate!(:name => 'TestEdit') |
|
59 | @auth_source = AuthSource.generate!(:name => 'TestEdit') | |
60 | post :update, :id => @auth_source.id, :auth_source => {:name => 'TestUpdate'} |
|
60 | post :update, :id => @auth_source.id, :auth_source => {:name => 'TestUpdate'} | |
61 | end |
|
61 | end | |
62 |
|
62 | |||
63 | should_respond_with :redirect |
|
63 | should_respond_with :redirect | |
64 | should_redirect_to("index") {{:action => 'index'}} |
|
64 | should_redirect_to("index") {{:action => 'index'}} | |
65 | should_set_the_flash_to /update/i |
|
65 | should_set_the_flash_to /update/i | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | context "post :destroy" do |
|
68 | context "post :destroy" do | |
69 | context "without users" do |
|
|||
70 |
|
|
69 | setup do | |
71 |
|
|
70 | @auth_source = AuthSource.generate!(:name => 'TestEdit') | |
|
71 | end | |||
|
72 | ||||
|
73 | context "without users" do | |||
|
74 | setup do | |||
72 | post :destroy, :id => @auth_source.id |
|
75 | post :destroy, :id => @auth_source.id | |
73 | end |
|
76 | end | |
74 |
|
77 | |||
75 | should_respond_with :redirect |
|
78 | should_respond_with :redirect | |
76 | should_redirect_to("index") {{:action => 'index'}} |
|
79 | should_redirect_to("index") {{:action => 'index'}} | |
77 | should_set_the_flash_to /deletion/i |
|
80 | should_set_the_flash_to /deletion/i | |
|
81 | end | |||
78 |
|
82 | |||
|
83 | context "with users" do | |||
|
84 | setup do | |||
|
85 | User.generate!(:auth_source => @auth_source) | |||
|
86 | post :destroy, :id => @auth_source.id | |||
79 | end |
|
87 | end | |
80 |
|
88 | |||
81 | should "be tested with users" |
|
89 | should_respond_with :redirect | |
|
90 | should "not destroy the AuthSource" do | |||
|
91 | assert AuthSource.find(@auth_source.id) | |||
|
92 | end | |||
|
93 | end | |||
82 | end |
|
94 | end | |
83 | end |
|
95 | end |
General Comments 0
You need to be logged in to leave comments.
Login now