1 # frozen_string_literal: true
5 class AclsControllerTest < ActionDispatch::IntegrationTest
7 # test all routes which lead to this controller
10 { :path => "/acls", :method => :get },
11 { :controller => "acls", :action => "index" }
14 { :path => "/acls/new", :method => :get },
15 { :controller => "acls", :action => "new" }
18 { :path => "/acls", :method => :post },
19 { :controller => "acls", :action => "create" }
22 { :path => "/acls/1/edit", :method => :get },
23 { :controller => "acls", :action => "edit", :id => "1" }
26 { :path => "/acls/1", :method => :put },
27 { :controller => "acls", :action => "update", :id => "1" }
30 { :path => "/acls/1", :method => :delete },
31 { :controller => "acls", :action => "destroy", :id => "1" }
37 assert_redirected_to login_path(:referer => acls_path)
40 def test_index_non_administrator
41 session_for(create(:user))
44 assert_redirected_to :controller => "errors", :action => "forbidden"
47 def test_index_administrator
48 session_for(create(:administrator_user))
51 assert_response :success
52 assert_template :index
55 def test_index_invalid_paged
56 session_for(create(:administrator_user))
58 %w[-1 fred].each do |id|
59 get acls_path(:before => id)
60 assert_redirected_to :controller => "errors", :action => "bad_request"
62 get acls_path(:after => id)
63 assert_redirected_to :controller => "errors", :action => "bad_request"
69 assert_redirected_to login_path(:referer => new_acl_path)
72 def test_new_non_administrator
73 session_for(create(:user))
76 assert_redirected_to :controller => "errors", :action => "forbidden"
79 def test_new_administrator
80 session_for(create(:administrator_user))
83 assert_response :success
88 assert_no_difference "Acl.count" do
89 post acls_path(:acl => { :address => "192.0.2.0/24", :k => "no_account_creation" })
91 assert_response :forbidden
94 def test_create_non_administrator
95 session_for(create(:user))
97 assert_no_difference "Acl.count" do
98 post acls_path(:acl => { :address => "192.0.2.0/24", :k => "no_account_creation" })
100 assert_redirected_to :controller => "errors", :action => "forbidden"
103 def test_create_administrator
104 session_for(create(:administrator_user))
106 assert_difference "Acl.count", 1 do
107 post acls_path(:acl => { :address => "192.0.2.0/24", :k => "no_account_creation" })
109 assert_redirected_to acls_path
115 get edit_acl_path(acl)
116 assert_redirected_to login_path(:referer => edit_acl_path(acl))
119 def test_edit_non_administrator
120 session_for(create(:user))
122 get edit_acl_path(create(:acl))
123 assert_redirected_to :controller => "errors", :action => "forbidden"
126 def test_edit_administrator
127 session_for(create(:administrator_user))
129 get edit_acl_path(create(:acl))
130 assert_response :success
131 assert_template :edit
135 acl = create(:acl, :k => "no_account_creation")
137 put acl_path(acl, :acl => { :k => "no_note_comment" })
138 assert_response :forbidden
139 assert_equal "no_account_creation", acl.reload.k
142 def test_update_non_administrator
143 session_for(create(:user))
144 acl = create(:acl, :k => "no_account_creation")
146 put acl_path(acl, :acl => { :k => "no_note_comment" })
147 assert_redirected_to :controller => "errors", :action => "forbidden"
148 assert_equal "no_account_creation", acl.reload.k
151 def test_update_administrator
152 session_for(create(:administrator_user))
153 acl = create(:acl, :k => "no_account_creation")
155 put acl_path(acl, :acl => { :k => "no_note_comment" })
156 assert_redirected_to acls_path
157 assert_equal "no_note_comment", acl.reload.k
163 assert_no_difference "Acl.count" do
166 assert_response :forbidden
169 def test_destroy_non_administrator
170 session_for(create(:user))
173 assert_no_difference "Acl.count" do
176 assert_redirected_to :controller => "errors", :action => "forbidden"
179 def test_destroy_administrator
180 session_for(create(:administrator_user))
183 assert_difference "Acl.count", -1 do
186 assert_redirected_to acls_path