|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | 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 |
5 | 44 |
|
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 |
7 | 61 |
|
8 | 62 | 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 | + |
9 | 73 | context "Region-related actions" do |
10 | 74 | let!(:region) { create(:region) } |
11 | 75 |
|
|
174 | 238 | end |
175 | 239 |
|
176 | 240 | context "administrator" do |
177 | | - before { user.update(is_admin: true) } |
| 241 | + let(:admin) { create(:user, :admin) } |
| 242 | + |
| 243 | + before { sign_in(admin) } |
178 | 244 |
|
179 | 245 | it "can access the Topics tab" do |
180 | 246 | get "/topics" |
|
200 | 266 | get "/users" |
201 | 267 | expect(response).to be_successful |
202 | 268 | end |
| 269 | + |
| 270 | + it "can access the Jobs interface" do |
| 271 | + get "/jobs" |
| 272 | + expect(response).to be_successful |
| 273 | + end |
203 | 274 | end |
204 | 275 | end |
0 commit comments