Browse Source

Maintenance: RSpec attachments simulating cleanup

Mantas Masalskis 3 years ago
parent
commit
8671aea0b4

+ 0 - 11
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

+ 0 - 11
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

+ 24 - 0
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

+ 0 - 11
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

+ 0 - 11
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