Commit 385468e0 authored by nmilojevic1's avatar nmilojevic1 Committed by Stan Hu

Fix MR comments

- Added author column inside Where
- Made configuration_helper more generalised
parent 0fac0300
......@@ -16,7 +16,7 @@ describe 'Import/Export attribute configuration' do
let(:safe_model_attributes) { YAML.load_file(safe_attributes_file) }
it 'has no new columns' do
project_relation_names.each do |relation_name|
relation_names_for(:project).each do |relation_name|
relation_class = relation_class_for_name(relation_name)
relation_attributes = relation_class.new.attributes.keys - relation_class.encrypted_attributes.keys.map(&:to_s)
......
......@@ -11,7 +11,7 @@ describe 'Import/Export model configuration' do
let(:all_models_yml) { 'spec/lib/gitlab/import_export/all_models.yml' }
let(:all_models_hash) { YAML.load_file(all_models_yml) }
let(:current_models) { setup_models }
let(:model_names) { project_relation_names }
let(:model_names) { relation_names_for(:project) }
it 'has no new models' do
model_names.each do |model_name|
......
......@@ -13,12 +13,14 @@ describe 'Import/Export Project configuration' do
include ConfigurationHelper
where(:relation_path, :relation_name) do
project_relation_paths.map {|a| [a.join("."), a.last]}
relation_paths_for(:project).map do |relation_names|
next if relation_names.last == "author"
[relation_names.join("."), relation_names.last]
end.compact
end
with_them do
next if params[:relation_name] == "author"
context "where relation #{params[:relation_path]}" do
it 'does not have prohibited keys' do
relation_class = relation_class_for_name(relation_name)
......
......@@ -22,22 +22,22 @@ module ConfigurationHelper
new_hash
end
def config_hash
Gitlab::ImportExport::Config.new.to_h.deep_stringify_keys
def config_hash(config = Gitlab::ImportExport.config_file)
Gitlab::ImportExport::Config.new(config: config).to_h.deep_stringify_keys
end
def project_relation_paths
def relation_paths_for(key, config: Gitlab::ImportExport.config_file)
# - project is not part of the tree, so it has to be added manually.
flat_hash({ "project" => config_hash.dig('tree', 'project') }).keys
flat_hash({ "project" => config_hash(config).dig('tree', key.to_s) }).keys
end
def project_relation_names
names = names_from_tree(config_hash.dig('tree', 'project'))
def relation_names_for(key, config: Gitlab::ImportExport.config_file)
names = names_from_tree(config_hash(config).dig('tree', key.to_s))
# Remove duplicated or add missing models
# - project is not part of the tree, so it has to be added manually.
# - milestone, labels, merge_request have both singular and plural versions in the tree, so remove the duplicates.
# - User, Author... Models we do not care about for checking models
names.flatten.uniq - %w(milestones labels user author merge_request design) + ['project']
names.flatten.uniq - %w(milestones labels user author merge_request design) + [key.to_s]
end
def relation_class_for_name(relation_name)
......
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