From 8671aea0b45a5a9dd182e853cdd7fde60d0d7f62 Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Wed, 2 Mar 2022 16:43:40 +0100 Subject: [PATCH] Maintenance: RSpec attachments simulating cleanup --- .../shared_draft/starts_controller_spec.rb | 11 --------- .../shared_draft/zoom_controller_spec.rb | 11 --------- spec/support/store_helper.rb | 24 +++++++++++++++++++ spec/system/ticket/shared_draft_start_spec.rb | 11 --------- spec/system/ticket/shared_draft_zoom_spec.rb | 11 --------- 5 files changed, 24 insertions(+), 44 deletions(-) create mode 100644 spec/support/store_helper.rb diff --git a/spec/requests/ticket/shared_draft/starts_controller_spec.rb b/spec/requests/ticket/shared_draft/starts_controller_spec.rb index df51fed46..2a13ab466 100644 --- a/spec/requests/ticket/shared_draft/starts_controller_spec.rb +++ b/spec/requests/ticket/shared_draft/starts_controller_spec.rb @@ -289,15 +289,4 @@ RSpec.describe 'Ticket Shared Drafts Start API endpoints', authenticated_as: :ag post '/api/v1/tickets', params: params, as: :json end end - - def attach(id:, object_name: 'UploadCache') - Store.add( - object: object_name, - o_id: id, - data: File.binread(Rails.root.join('test/data/image/1x1.png')), - filename: '1x1.png', - preferences: {}, - created_by_id: 1, - ) - end end diff --git a/spec/requests/ticket/shared_draft/zoom_controller_spec.rb b/spec/requests/ticket/shared_draft/zoom_controller_spec.rb index 6a3bba744..fb4a69175 100644 --- a/spec/requests/ticket/shared_draft/zoom_controller_spec.rb +++ b/spec/requests/ticket/shared_draft/zoom_controller_spec.rb @@ -222,15 +222,4 @@ RSpec.describe 'Ticket Shared Drafts Zoom API endpoints', authenticated_as: :age put "/api/v1/tickets/#{ticket_id}", params: params, as: :json end end - - def attach(id:, object_name: 'UploadCache') - Store.add( - object: object_name, - o_id: id, - data: File.binread(Rails.root.join('test/data/image/1x1.png')), - filename: '1x1.png', - preferences: {}, - created_by_id: 1, - ) - end end diff --git a/spec/support/store_helper.rb b/spec/support/store_helper.rb new file mode 100644 index 000000000..b9a6bf0a7 --- /dev/null +++ b/spec/support/store_helper.rb @@ -0,0 +1,24 @@ +# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/ + +module ZammadStoreHelper + # Add attachment to Store + # + # @param id [Integer] ID of the owner object + # @param object_name [String] class name of the owner object + # @param filename [String] filename (including path) to file to use as a test. + # + def attach(id:, object_name: 'UploadCache', filename: 'test/data/image/1x1.png') + Store.add( + object: object_name, + o_id: id, + data: File.binread(Rails.root.join(filename)), + filename: Pathname.new(filename).basename, + preferences: {}, + created_by_id: 1, + ) + end +end + +RSpec.configure do |config| + config.include ZammadStoreHelper +end diff --git a/spec/system/ticket/shared_draft_start_spec.rb b/spec/system/ticket/shared_draft_start_spec.rb index 20d6389a6..f4cb68587 100644 --- a/spec/system/ticket/shared_draft_start_spec.rb +++ b/spec/system/ticket/shared_draft_start_spec.rb @@ -249,15 +249,4 @@ RSpec.describe 'Ticket Shared Draft Start', type: :system, authenticated_as: :au end end end - - def attach(id:, object_name: 'UploadCache') - Store.add( - object: object_name, - o_id: id, - data: File.binread(Rails.root.join('test/data/image/1x1.png')), - filename: '1x1.png', - preferences: {}, - created_by_id: 1, - ) - end end diff --git a/spec/system/ticket/shared_draft_zoom_spec.rb b/spec/system/ticket/shared_draft_zoom_spec.rb index a63f3df60..b28011e29 100644 --- a/spec/system/ticket/shared_draft_zoom_spec.rb +++ b/spec/system/ticket/shared_draft_zoom_spec.rb @@ -249,15 +249,4 @@ RSpec.describe 'Ticket Shared Draft Zoom', type: :system, authenticated_as: :aut expect(page).to have_text('1x1.png') end end - - def attach(id:, object_name: 'UploadCache') - Store.add( - object: object_name, - o_id: id, - data: File.binread(Rails.root.join('test/data/image/1x1.png')), - filename: '1x1.png', - preferences: {}, - created_by_id: 1, - ) - end end