summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-05-30 14:50:09 +0900
committerShinya Maeda <shinya@gitlab.com>2018-05-30 14:50:09 +0900
commit09122f93c34b15cb827aabdbdf35fc33b08f93af (patch)
tree57c137ef57621a7a2ed4940c56c7f5cbe6ec1c80 /spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
parent1d20679e9c8b1ba16bebaf982255946e7207b4d4 (diff)
parent5b1416aa74c4fa80e0c324fd2907166af5ca479b (diff)
downloadgitlab-ce-09122f93c34b15cb827aabdbdf35fc33b08f93af.tar.gz
Merge branch 'master' into per-project-pipeline-iid
Diffstat (limited to 'spec/lib/gitlab/import_export/attribute_cleaner_spec.rb')
-rw-r--r--spec/lib/gitlab/import_export/attribute_cleaner_spec.rb29
1 files changed, 26 insertions, 3 deletions
diff --git a/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb b/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
index cd5a1b2982b..536cc359d39 100644
--- a/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
+++ b/spec/lib/gitlab/import_export/attribute_cleaner_spec.rb
@@ -15,7 +15,10 @@ describe Gitlab::ImportExport::AttributeCleaner do
'project_id' => 99,
'user_id' => 99,
'random_id_in_the_middle' => 99,
- 'notid' => 99
+ 'notid' => 99,
+ 'import_source' => 'whatever',
+ 'import_type' => 'whatever',
+ 'non_existent_attr' => 'whatever'
}
end
@@ -28,10 +31,30 @@ describe Gitlab::ImportExport::AttributeCleaner do
}
end
+ let(:excluded_keys) { %w[import_source import_type] }
+
+ subject { described_class.clean(relation_hash: unsafe_hash, relation_class: relation_class, excluded_keys: excluded_keys) }
+
+ before do
+ allow(relation_class).to receive(:attribute_method?).and_return(true)
+ allow(relation_class).to receive(:attribute_method?).with('non_existent_attr').and_return(false)
+ end
+
it 'removes unwanted attributes from the hash' do
- # allow(relation_class).to receive(:attribute_method?).and_return(true)
+ expect(subject).to eq(post_safe_hash)
+ end
+
+ it 'removes attributes not present in relation_class' do
+ expect(subject.keys).not_to include 'non_existent_attr'
+ end
+
+ it 'removes excluded keys from the hash' do
+ expect(subject.keys).not_to include excluded_keys
+ end
+
+ it 'does not remove excluded key if not listed' do
parsed_hash = described_class.clean(relation_hash: unsafe_hash, relation_class: relation_class)
- expect(parsed_hash).to eq(post_safe_hash)
+ expect(parsed_hash.keys).to eq post_safe_hash.keys + excluded_keys
end
end