diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/import_export/attributes_permitter_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/import_export/attributes_permitter_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import_export/attributes_permitter_spec.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/attributes_permitter_spec.rb b/spec/lib/gitlab/import_export/attributes_permitter_spec.rb new file mode 100644 index 00000000000..d6217811b9c --- /dev/null +++ b/spec/lib/gitlab/import_export/attributes_permitter_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::ImportExport::AttributesPermitter do + let(:yml_config) do + <<-EOF + tree: + project: + - labels: + - :priorities + - milestones: + - events: + - :push_event_payload + + included_attributes: + labels: + - :title + - :description + + methods: + labels: + - :type + EOF + end + + let(:file) { Tempfile.new(%w(import_export .yml)) } + let(:config_hash) { Gitlab::ImportExport::Config.new(config: file.path).to_h } + + before do + file.write(yml_config) + file.rewind + end + + after do + file.close + file.unlink + end + + subject { described_class.new(config: config_hash) } + + describe '#permitted_attributes' do + it 'builds permitted attributes hash' do + expect(subject.permitted_attributes).to match( + a_hash_including( + project: [:labels, :milestones], + labels: [:priorities, :title, :description, :type], + events: [:push_event_payload], + milestones: [:events], + priorities: [], + push_event_payload: [] + ) + ) + end + end + + describe '#permit' do + let(:unfiltered_hash) do + { + title: 'Title', + description: 'Description', + undesired_attribute: 'Undesired Attribute', + another_attribute: 'Another Attribute' + } + end + + it 'only allows permitted attributes' do + expect(subject.permit(:labels, unfiltered_hash)).to eq(title: 'Title', description: 'Description') + end + end + + describe '#permitted_attributes_for' do + it 'returns an array of permitted attributes for a relation' do + expect(subject.permitted_attributes_for(:labels)).to contain_exactly(:title, :description, :type, :priorities) + end + end +end |