Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#49120] extracted json helper methods

Eric Schubert65da6448b813
diff --git a/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_info_query_spec.rb b/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_info_query_spec.rb
index 50c50526739..4a1ac7a4458 100644
--- a/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_info_query_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_info_query_spec.rb
@@ -32,6 +32,8 @@ require 'spec_helper'
require_module_spec_helper
RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesInfoQuery, webmock: true do
+ include JsonResponseHelper
+
let(:storage) do
create(:one_drive_storage,
:with_oauth_client,
@@ -97,18 +99,18 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesInfoQue
status: 'ok',
status_code: '200',
id: '01BYE5RZ5MYLM2SMX75ZBIPQZIHT6OAYPB',
- name: "Business Data",
+ name: 'Business Data',
size: 39566226,
- mime_type: "application/x-op-directory",
- created_at: Time.parse("2017-08-07T16:16:30Z"),
- last_modified_at: Time.parse("2017-08-07T16:16:30Z"),
- owner_name: "Megan Bowen",
- owner_id: "48d31887-5fad-4d73-a9f5-3c356e68a038",
- last_modified_by_id: "48d31887-5fad-4d73-a9f5-3c356e68a038",
- last_modified_by_name: "Megan Bowen",
+ mime_type: 'application/x-op-directory',
+ created_at: Time.parse('2017-08-07T16:16:30Z'),
+ last_modified_at: Time.parse('2017-08-07T16:16:30Z'),
+ owner_name: 'Megan Bowen',
+ owner_id: '48d31887-5fad-4d73-a9f5-3c356e68a038',
+ last_modified_by_id: '48d31887-5fad-4d73-a9f5-3c356e68a038',
+ last_modified_by_name: 'Megan Bowen',
permissions: nil,
trashed: false,
- location: "/drives/b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd/root:"
+ location: '/drives/b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd/root:'
})
# rubocop:enable Layout/LineLength
end
@@ -121,18 +123,18 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesInfoQue
status: 'ok',
status_code: '200',
id: '01BYE5RZZ6FUE5272C5JCY3L7CLZ7XOUYM',
- name: "All Japan Revenues By City.xlsx",
+ name: 'All Japan Revenues By City.xlsx',
size: 20051,
- mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
- created_at: Time.parse("2017-08-07T16:07:10Z"),
- last_modified_at: Time.parse("2017-08-07T16:07:10Z"),
- owner_name: "Megan Bowen",
- owner_id: "48d31887-5fad-4d73-a9f5-3c356e68a038",
- last_modified_by_id: "48d31887-5fad-4d73-a9f5-3c356e68a038",
- last_modified_by_name: "Megan Bowen",
+ mime_type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ created_at: Time.parse('2017-08-07T16:07:10Z'),
+ last_modified_at: Time.parse('2017-08-07T16:07:10Z'),
+ owner_name: 'Megan Bowen',
+ owner_id: '48d31887-5fad-4d73-a9f5-3c356e68a038',
+ last_modified_by_id: '48d31887-5fad-4d73-a9f5-3c356e68a038',
+ last_modified_by_name: 'Megan Bowen',
permissions: nil,
trashed: false,
- location: "/drives/b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd/root:"
+ location: '/drives/b!-RIj2DuyvEyV1T4NlOaMHk8XkS_I8MdFlUCq1BlcjgmhRfAj3-Z8RY2VpuvV_tpd/root:'
})
# rubocop:enable Layout/LineLength
end
@@ -187,14 +189,4 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesInfoQue
expect(storage_files.errors.to_s).to eq(Storages::StorageError.new(code: :not_authorized).to_s)
end
end
-
- private
-
- def read_json(name)
- File.readlines(payload_path.join("#{name}.json")).join
- end
-
- def payload_path
- Pathname.new(Rails.root).join('modules/storages/spec/support/payloads/')
- end
end
diff --git a/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_query_spec.rb b/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_query_spec.rb
index db621b807b3..45c79c51423 100644
--- a/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_query_spec.rb
+++ b/modules/storages/spec/common/peripherals/storage_interaction/one_drive/files_query_spec.rb
@@ -32,6 +32,8 @@ require 'spec_helper'
require_module_spec_helper
RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery, webmock: true do
+ include JsonResponseHelper
+
let(:storage) { create(:one_drive_storage, :with_oauth_client) }
let(:user) { create(:user) }
let(:json) { read_json('root_drive') }
@@ -123,14 +125,4 @@ RSpec.describe Storages::Peripherals::StorageInteraction::OneDrive::FilesQuery,
expect(storage_files.errors.to_s).to eq(Storages::StorageError.new(code: :not_authorized).to_s)
end
end
-
- private
-
- def read_json(name)
- File.readlines(payload_path.join("#{name}.json")).join
- end
-
- def payload_path
- Pathname.new(Rails.root).join('modules/storages/spec/support/payloads/')
- end
end
diff --git a/modules/storages/spec/support/json_response_helper.rb b/modules/storages/spec/support/json_response_helper.rb
new file mode 100644
index 00000000000..17e327f6b5b
--- /dev/null
+++ b/modules/storages/spec/support/json_response_helper.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
+module JsonResponseHelper
+ def read_json(name)
+ File.readlines(payload_path.join("#{name}.json")).join
+ end
+
+ private
+
+ def payload_path
+ Pathname.new(Rails.root).join('modules/storages/spec/support/payloads/')
+ end
+end