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