Skip to content

Commit 1a12c22

Browse files
committed
Move access-related tests to authorizations_spec
We already had tests to check that only Admins could access Mission Control. But now that the link to "Jobs" is in the sidebar together with other pages for which we test who has access in authorizations_spec, I think it's clearer for us to have all these tests in the same file, so I moved the tests from jobs_spec.rb to authorizations_spec.rb and added tests for when the user is not authenticated.
1 parent 323d943 commit 1a12c22

File tree

2 files changed

+74
-38
lines changed

2 files changed

+74
-38
lines changed

spec/requests/authorizations_spec.rb

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,75 @@
11
require "rails_helper"
22

33
RSpec.describe "Authorizations", type: :request do
4-
let(:user) { create(:user) }
4+
context "not authenticated" do
5+
context "when trying to access the Regions index" do
6+
it "redirects to the login page" do
7+
get "/regions"
8+
expect(response).to redirect_to("/session/new")
9+
expect(session[:return_to_after_authenticating]).to eq("/regions")
10+
end
11+
end
12+
13+
context "when trying to access the Providers index" do
14+
it "redirects to the login page" do
15+
get "/providers"
16+
expect(response).to redirect_to("/session/new")
17+
expect(session[:return_to_after_authenticating]).to eq("/providers")
18+
end
19+
end
20+
21+
context "when trying to access the Languages index" do
22+
it "redirects to the login page" do
23+
get "/languages"
24+
expect(response).to redirect_to("/session/new")
25+
expect(session[:return_to_after_authenticating]).to eq("/languages")
26+
end
27+
end
28+
29+
context "when trying to access the Tags index" do
30+
it "redirects to the login page" do
31+
get "/tags"
32+
expect(response).to redirect_to("/session/new")
33+
expect(session[:return_to_after_authenticating]).to eq("/tags")
34+
end
35+
end
36+
37+
context "when trying to access the Users index" do
38+
it "redirects to the login page" do
39+
get "/users"
40+
expect(response).to redirect_to("/session/new")
41+
expect(session[:return_to_after_authenticating]).to eq("/users")
42+
end
43+
end
544

6-
before { sign_in(user) }
45+
context "when trying to access the Import Reports index" do
46+
it "redirects to the login page" do
47+
get "/import_reports"
48+
expect(response).to redirect_to("/session/new")
49+
expect(session[:return_to_after_authenticating]).to eq("/import_reports")
50+
end
51+
end
52+
53+
context "when trying to access the Jobs interface" do
54+
it "redirects to the login page" do
55+
get "/jobs"
56+
expect(response).to redirect_to("/session/new")
57+
expect(session[:return_to_after_authenticating]).to eq("/jobs/")
58+
end
59+
end
60+
end
761

862
context "contributor" do
63+
let(:user) { create(:user) }
64+
65+
before { sign_in(user) }
66+
67+
it "cannot access the Jobs interface" do
68+
get "/jobs"
69+
expect(response).to have_http_status(:forbidden)
70+
expect(response.body).to include("Access denied")
71+
end
72+
973
context "Region-related actions" do
1074
let!(:region) { create(:region) }
1175

@@ -174,7 +238,9 @@
174238
end
175239

176240
context "administrator" do
177-
before { user.update(is_admin: true) }
241+
let(:admin) { create(:user, :admin) }
242+
243+
before { sign_in(admin) }
178244

179245
it "can access the Topics tab" do
180246
get "/topics"
@@ -200,5 +266,10 @@
200266
get "/users"
201267
expect(response).to be_successful
202268
end
269+
270+
it "can access the Jobs interface" do
271+
get "/jobs"
272+
expect(response).to be_successful
273+
end
203274
end
204275
end

spec/requests/jobs_spec.rb

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)