From 2cc3c987e3ef428ec00cb1f6f783ab059f5f0480 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 19 Jun 2026 15:50:31 +0100 Subject: [PATCH] test printer request permissions --- spec/requests/print_hosts_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/support/sign_in_role.rb | 5 +++++ 2 files changed, 35 insertions(+) diff --git a/spec/requests/print_hosts_spec.rb b/spec/requests/print_hosts_spec.rb index b6d99231a..69aba5dff 100644 --- a/spec/requests/print_hosts_spec.rb +++ b/spec/requests/print_hosts_spec.rb @@ -18,6 +18,10 @@ RSpec.describe "PrintHosts", :after_first_run do expect(response).to have_http_status(:forbidden) end + it "denies permission to people with print-only permissions", :as_printer do + expect(response).to have_http_status(:forbidden) + end + it "shows list to admins", :as_administrator do expect(response).to have_http_status(:success) end @@ -33,6 +37,10 @@ RSpec.describe "PrintHosts", :after_first_run do it "is denied to non-admins", :as_moderator do expect(response).to have_http_status(:forbidden) end + + it "denies permission to people with print-only permissions", :as_printer do + expect(response).to have_http_status(:forbidden) + end end describe "GET /print_hosts/new" do @@ -45,6 +53,10 @@ RSpec.describe "PrintHosts", :after_first_run do it "is denied to non-admins", :as_moderator do expect(response).to have_http_status(:forbidden) end + + it "denies permission to people with print-only permissions", :as_printer do + expect(response).to have_http_status(:forbidden) + end end describe "GET /print_hosts/:id/edit" do @@ -57,6 +69,10 @@ RSpec.describe "PrintHosts", :after_first_run do it "is denied to non-administrators", :as_moderator do expect(response).to have_http_status(:forbidden) end + + it "denies permission to people with print-only permissions", :as_printer do + expect(response).to have_http_status(:forbidden) + end end describe "PATCH /print_hosts/:id" do @@ -77,6 +93,10 @@ RSpec.describe "PrintHosts", :after_first_run do it "is denied to non-administrators", :as_moderator do expect(response).to have_http_status(:forbidden) end + + it "denies permission to people with print-only permissions", :as_printer do + expect(response).to have_http_status(:forbidden) + end end describe "DELETE /print_hosts/:id" do @@ -91,6 +111,10 @@ RSpec.describe "PrintHosts", :after_first_run do it "is denied to non-administrators", :as_moderator do expect(response).to have_http_status(:forbidden) end + + it "denies permission to people with print-only permissions", :as_printer do + expect(response).to have_http_status(:forbidden) + end end describe "POST /print_hosts/:id/print" do @@ -113,6 +137,12 @@ RSpec.describe "PrintHosts", :after_first_run do post "/print_hosts/#{print_host.to_param}/print", params: {file_id: file.public_id} expect(response).to have_http_status(:forbidden) end + + it "accepts print requests from people with print-only permissions", :as_printer do + expect { + post "/print_hosts/#{print_host.to_param}/print", params: {file_id: file.public_id} + }.to have_enqueued_job(SendFileToPrintHostJob).with(print_host: print_host, file: file) + end end end end diff --git a/spec/support/sign_in_role.rb b/spec/support/sign_in_role.rb index d707bfa0b..51693b3a2 100644 --- a/spec/support/sign_in_role.rb +++ b/spec/support/sign_in_role.rb @@ -26,4 +26,9 @@ RSpec.configure do |config| @current_user = create(:user) sign_in @current_user end + + config.before(:each, :as_printer) do + @current_user = create(:printer) + sign_in @current_user + end end