Commit f690b908 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'fix-zeitwerk-json' into 'master'

Rename JSON to Json [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!63814
parents 3c1780fb 8499a3e2
......@@ -22,8 +22,8 @@ module Ci
validates :build, presence: true
validates :secrets, json_schema: { filename: 'build_metadata_secrets' }
serialize :config_options, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_variables, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_options, Serializers::Json # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_variables, Serializers::Json # rubocop:disable Cop/ActiveRecordSerialize
chronic_duration_attr_reader :timeout_human_readable, :timeout
......
......@@ -12,7 +12,7 @@ class MergeRequestContextCommit < ApplicationRecord
validates :sha, presence: true
validates :sha, uniqueness: { message: 'has already been added' }
serialize :trailers, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :trailers, Serializers::Json # rubocop:disable Cop/ActiveRecordSerialize
validates :trailers, json_schema: { filename: 'git_trailers' }
# Sort by committed date in descending order to ensure latest commits comes on the top
......
......@@ -12,7 +12,7 @@ class MergeRequestDiffCommit < ApplicationRecord
sha_attribute :sha
alias_attribute :id, :sha
serialize :trailers, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :trailers, Serializers::Json # rubocop:disable Cop/ActiveRecordSerialize
validates :trailers, json_schema: { filename: 'git_trailers' }
# Deprecated; use `bulk_insert!` from `BulkInsertSafe` mixin instead.
......
......@@ -86,7 +86,7 @@ module BulkImports
# rubocop: disable CodeReuse/Serializer
def serializer
@serializer ||= ::Gitlab::ImportExport::JSON::StreamingSerializer.new(
@serializer ||= ::Gitlab::ImportExport::Json::StreamingSerializer.new(
portable,
portable_tree,
json_writer,
......@@ -96,7 +96,7 @@ module BulkImports
# rubocop: enable CodeReuse/Serializer
def json_writer
@json_writer ||= ::Gitlab::ImportExport::JSON::NdjsonWriter.new(export_path)
@json_writer ||= ::Gitlab::ImportExport::Json::NdjsonWriter.new(export_path)
end
def ndjson_filename
......
......@@ -844,7 +844,7 @@ You have to use a serializer to provide a translation layer:
```ruby
class BuildMetadata
serialize :config_options, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_options, Serializers::Json # rubocop:disable Cop/ActiveRecordSerialize
end
```
......
......@@ -39,7 +39,7 @@ module Vulnerabilities
has_one :evidence, class_name: 'Vulnerabilities::Finding::Evidence', inverse_of: :finding, foreign_key: 'vulnerability_occurrence_id'
serialize :config_options, Serializers::JSON # rubocop:disable Cop/ActiveRecordSerialize
serialize :config_options, Serializers::Json # rubocop:disable Cop/ActiveRecordSerialize
attr_writer :sha
attr_accessor :scan
......
......@@ -51,7 +51,7 @@ module BulkImports
end
def ndjson_reader(tmp_dir)
@ndjson_reader ||= Gitlab::ImportExport::JSON::NdjsonReader.new(tmp_dir)
@ndjson_reader ||= Gitlab::ImportExport::Json::NdjsonReader.new(tmp_dir)
end
def relative_resource_url(context)
......
......@@ -55,11 +55,11 @@ module Gitlab
def relation_reader
strong_memoize(:relation_reader) do
if @group_hash.present?
ImportExport::JSON::LegacyReader::Hash.new(
ImportExport::Json::LegacyReader::Hash.new(
@group_hash,
relation_names: reader.group_relation_names)
else
ImportExport::JSON::LegacyReader::File.new(
ImportExport::Json::LegacyReader::File.new(
File.join(shared.export_path, 'group.json'),
relation_names: reader.group_relation_names)
end
......
......@@ -118,7 +118,7 @@ module Gitlab
def relation_reader
strong_memoize(:relation_reader) do
ImportExport::JSON::NdjsonReader.new(
ImportExport::Json::NdjsonReader.new(
File.join(shared.export_path, 'tree')
)
end
......
......@@ -42,7 +42,7 @@ module Gitlab
end
def serialize(group)
ImportExport::JSON::StreamingSerializer.new(
ImportExport::Json::StreamingSerializer.new(
group,
group_tree,
json_writer,
......@@ -64,7 +64,7 @@ module Gitlab
end
def json_writer
@json_writer ||= ImportExport::JSON::NdjsonWriter.new(@full_path)
@json_writer ||= ImportExport::Json::NdjsonWriter.new(@full_path)
end
end
end
......
......@@ -2,7 +2,7 @@
module Gitlab
module ImportExport
module JSON
module Json
class LegacyReader
class File < LegacyReader
include Gitlab::Utils::StrongMemoize
......
......@@ -2,7 +2,7 @@
module Gitlab
module ImportExport
module JSON
module Json
class LegacyWriter
include Gitlab::ImportExport::CommandLineUtil
......
......@@ -2,7 +2,7 @@
module Gitlab
module ImportExport
module JSON
module Json
class NdjsonReader
MAX_JSON_DOCUMENT_SIZE = 50.megabytes
......
......@@ -2,7 +2,7 @@
module Gitlab
module ImportExport
module JSON
module Json
class NdjsonWriter
include Gitlab::ImportExport::CommandLineUtil
......
......@@ -2,7 +2,7 @@
module Gitlab
module ImportExport
module JSON
module Json
class StreamingSerializer
include Gitlab::ImportExport::CommandLineUtil
......
......@@ -22,7 +22,7 @@ module Gitlab
private
def batch_size(exportable)
Gitlab::ImportExport::JSON::StreamingSerializer.batch_size(exportable)
Gitlab::ImportExport::Json::StreamingSerializer.batch_size(exportable)
end
end
end
......
......@@ -56,13 +56,13 @@ module Gitlab
def ndjson_relation_reader
return unless Feature.enabled?(:project_import_ndjson, project.namespace, default_enabled: true)
ImportExport::JSON::NdjsonReader.new(
ImportExport::Json::NdjsonReader.new(
File.join(shared.export_path, 'tree')
)
end
def legacy_relation_reader
ImportExport::JSON::LegacyReader::File.new(
ImportExport::Json::LegacyReader::File.new(
File.join(shared.export_path, 'project.json'),
relation_names: reader.project_relation_names,
allowed_path: importable_path
......
......@@ -14,7 +14,7 @@ module Gitlab
end
def save
ImportExport::JSON::StreamingSerializer.new(
ImportExport::Json::StreamingSerializer.new(
exportable,
reader.project_tree,
json_writer,
......@@ -56,10 +56,10 @@ module Gitlab
@json_writer ||= begin
if ::Feature.enabled?(:project_export_as_ndjson, @project.namespace, default_enabled: true)
full_path = File.join(@shared.export_path, 'tree')
Gitlab::ImportExport::JSON::NdjsonWriter.new(full_path)
Gitlab::ImportExport::Json::NdjsonWriter.new(full_path)
else
full_path = File.join(@shared.export_path, ImportExport.project_filename)
Gitlab::ImportExport::JSON::LegacyWriter.new(full_path, allowed_path: 'project')
Gitlab::ImportExport::Json::LegacyWriter.new(full_path, allowed_path: 'project')
end
end
end
......
......@@ -2,7 +2,7 @@
module Serializers
# Make the resulting hash have deep indifferent access
class JSON
class Json
class << self
def dump(obj)
obj
......
......@@ -31,7 +31,7 @@ RSpec.describe Gitlab::ImportExport::Group::TreeSaver do
end
it 'fails to export a group' do
allow_next_instance_of(Gitlab::ImportExport::JSON::NdjsonWriter) do |ndjson_writer|
allow_next_instance_of(Gitlab::ImportExport::Json::NdjsonWriter) do |ndjson_writer|
allow(ndjson_writer).to receive(:write_relation_array).and_raise(RuntimeError, 'exception')
end
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
require_relative 'shared_example'
RSpec.describe Gitlab::ImportExport::JSON::LegacyReader::File do
RSpec.describe Gitlab::ImportExport::Json::LegacyReader::File do
it_behaves_like 'import/export json legacy reader' do
let(:valid_path) { 'spec/fixtures/lib/gitlab/import_export/light/project.json' }
let(:data) { valid_path }
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
require_relative 'shared_example'
RSpec.describe Gitlab::ImportExport::JSON::LegacyReader::Hash do
RSpec.describe Gitlab::ImportExport::Json::LegacyReader::Hash do
it_behaves_like 'import/export json legacy reader' do
let(:path) { 'spec/fixtures/lib/gitlab/import_export/light/project.json' }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::ImportExport::JSON::LegacyWriter do
RSpec.describe Gitlab::ImportExport::Json::LegacyWriter do
let(:path) { "#{Dir.tmpdir}/legacy_writer_spec/test.json" }
subject do
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::ImportExport::JSON::NdjsonReader do
RSpec.describe Gitlab::ImportExport::Json::NdjsonReader do
include ImportExport::CommonUtil
let(:fixture) { 'spec/fixtures/lib/gitlab/import_export/light/tree' }
......
......@@ -2,7 +2,7 @@
require "spec_helper"
RSpec.describe Gitlab::ImportExport::JSON::NdjsonWriter do
RSpec.describe Gitlab::ImportExport::Json::NdjsonWriter do
include ImportExport::CommonUtil
let(:path) { "#{Dir.tmpdir}/ndjson_writer_spec/tree" }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::ImportExport::JSON::StreamingSerializer do
RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
let_it_be(:user) { create(:user) }
let_it_be(:release) { create(:release) }
let_it_be(:group) { create(:group) }
......@@ -27,7 +27,7 @@ RSpec.describe Gitlab::ImportExport::JSON::StreamingSerializer do
end
let(:exportable_path) { 'project' }
let(:json_writer) { instance_double('Gitlab::ImportExport::JSON::LegacyWriter') }
let(:json_writer) { instance_double('Gitlab::ImportExport::Json::LegacyWriter') }
let(:hash) { { name: exportable.name, description: exportable.description }.stringify_keys }
let(:include) { [] }
let(:custom_orderer) { nil }
......
......@@ -28,7 +28,7 @@ RSpec.describe Gitlab::ImportExport::LegacyRelationTreeSaver do
stub_feature_flags(export_reduce_relation_batch_size: true)
end
include_examples 'FastHashSerializer with batch size', Gitlab::ImportExport::JSON::StreamingSerializer::SMALLER_BATCH_SIZE
include_examples 'FastHashSerializer with batch size', Gitlab::ImportExport::Json::StreamingSerializer::SMALLER_BATCH_SIZE
end
context 'when export_reduce_relation_batch_size feature flag is disabled' do
......@@ -36,7 +36,7 @@ RSpec.describe Gitlab::ImportExport::LegacyRelationTreeSaver do
stub_feature_flags(export_reduce_relation_batch_size: false)
end
include_examples 'FastHashSerializer with batch size', Gitlab::ImportExport::JSON::StreamingSerializer::BATCH_SIZE
include_examples 'FastHashSerializer with batch size', Gitlab::ImportExport::Json::StreamingSerializer::BATCH_SIZE
end
end
end
......@@ -77,7 +77,7 @@ RSpec.describe Gitlab::ImportExport::Project::Sample::RelationTreeRestorer do
let(:relation_factory) { Gitlab::ImportExport::Project::Sample::RelationFactory }
let(:reader) { Gitlab::ImportExport::Reader.new(shared: shared) }
let(:path) { 'spec/fixtures/lib/gitlab/import_export/sample_data/tree' }
let(:relation_reader) { Gitlab::ImportExport::JSON::NdjsonReader.new(path) }
let(:relation_reader) { Gitlab::ImportExport::Json::NdjsonReader.new(path) }
it 'initializes relation_factory with date_calculator as parameter' do
expect(Gitlab::ImportExport::Project::Sample::RelationFactory).to receive(:create).with(hash_including(:date_calculator)).at_least(:once).times
......
......@@ -820,9 +820,9 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end
before do
allow_any_instance_of(Gitlab::ImportExport::JSON::LegacyReader::File).to receive(:exist?).and_return(true)
allow_any_instance_of(Gitlab::ImportExport::JSON::NdjsonReader).to receive(:exist?).and_return(false)
allow_any_instance_of(Gitlab::ImportExport::JSON::LegacyReader::File).to receive(:tree_hash) { tree_hash }
allow_any_instance_of(Gitlab::ImportExport::Json::LegacyReader::File).to receive(:exist?).and_return(true)
allow_any_instance_of(Gitlab::ImportExport::Json::NdjsonReader).to receive(:exist?).and_return(false)
allow_any_instance_of(Gitlab::ImportExport::Json::LegacyReader::File).to receive(:tree_hash) { tree_hash }
end
context 'no group visibility' do
......
......@@ -96,7 +96,7 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
context 'using legacy reader' do
let(:path) { 'spec/fixtures/lib/gitlab/import_export/complex/project.json' }
let(:relation_reader) do
Gitlab::ImportExport::JSON::LegacyReader::File.new(
Gitlab::ImportExport::Json::LegacyReader::File.new(
path,
relation_names: reader.project_relation_names,
allowed_path: 'project'
......@@ -117,14 +117,14 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
context 'using ndjson reader' do
let(:path) { 'spec/fixtures/lib/gitlab/import_export/complex/tree' }
let(:relation_reader) { Gitlab::ImportExport::JSON::NdjsonReader.new(path) }
let(:relation_reader) { Gitlab::ImportExport::Json::NdjsonReader.new(path) }
it_behaves_like 'import project successfully'
end
context 'with invalid relations' do
let(:path) { 'spec/fixtures/lib/gitlab/import_export/project_with_invalid_relations/tree' }
let(:relation_reader) { Gitlab::ImportExport::JSON::NdjsonReader.new(path) }
let(:relation_reader) { Gitlab::ImportExport::Json::NdjsonReader.new(path) }
it 'logs the invalid relation and its errors' do
expect(relation_tree_restorer.shared.logger)
......@@ -151,7 +151,7 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
let(:object_builder) { Gitlab::ImportExport::Group::ObjectBuilder }
let(:relation_factory) { Gitlab::ImportExport::Group::RelationFactory }
let(:relation_reader) do
Gitlab::ImportExport::JSON::LegacyReader::File.new(
Gitlab::ImportExport::Json::LegacyReader::File.new(
path,
relation_names: reader.group_relation_names)
end
......
......@@ -2,7 +2,7 @@
require 'fast_spec_helper'
RSpec.describe Serializers::JSON do
RSpec.describe Serializers::Json do
describe '.dump' do
let(:obj) { { key: "value" } }
......
......@@ -20,11 +20,11 @@ module ImportExport
def setup_reader(reader)
if reader == :ndjson_reader && Feature.enabled?(:project_import_ndjson, default_enabled: true)
allow_any_instance_of(Gitlab::ImportExport::JSON::LegacyReader::File).to receive(:exist?).and_return(false)
allow_any_instance_of(Gitlab::ImportExport::JSON::NdjsonReader).to receive(:exist?).and_return(true)
allow_any_instance_of(Gitlab::ImportExport::Json::LegacyReader::File).to receive(:exist?).and_return(false)
allow_any_instance_of(Gitlab::ImportExport::Json::NdjsonReader).to receive(:exist?).and_return(true)
else
allow_any_instance_of(Gitlab::ImportExport::JSON::LegacyReader::File).to receive(:exist?).and_return(true)
allow_any_instance_of(Gitlab::ImportExport::JSON::NdjsonReader).to receive(:exist?).and_return(false)
allow_any_instance_of(Gitlab::ImportExport::Json::LegacyReader::File).to receive(:exist?).and_return(true)
allow_any_instance_of(Gitlab::ImportExport::Json::NdjsonReader).to receive(:exist?).and_return(false)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment