diff options
Diffstat (limited to 'spec/support/shared_examples/services')
3 files changed, 73 insertions, 20 deletions
diff --git a/spec/support/shared_examples/services/base_rpm_service_shared_examples.rb b/spec/support/shared_examples/services/base_rpm_service_shared_examples.rb new file mode 100644 index 00000000000..c9520852a5b --- /dev/null +++ b/spec/support/shared_examples/services/base_rpm_service_shared_examples.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'handling rpm xml file' do + include_context 'with rpm package data' + + let(:xml) { nil } + let(:data) { {} } + + context 'when generate empty xml' do + it 'generate expected xml' do + expect(subject).to eq(empty_xml) + end + end + + context 'when updating existing xml' do + let(:xml) { empty_xml } + let(:data) { xml_update_params } + + shared_examples 'changing root tag attribute' do + it "increment previous 'packages' value by 1" do + previous_value = Nokogiri::XML(xml).at(described_class::ROOT_TAG).attributes["packages"].value.to_i + new_value = Nokogiri::XML(subject).at(described_class::ROOT_TAG).attributes["packages"].value.to_i + + expect(previous_value + 1).to eq(new_value) + end + end + + it 'generate valid xml add expected xml node to existing xml' do + # Have one root attribute + result = Nokogiri::XML::Document.parse(subject).remove_namespaces! + expect(result.children.count).to eq(1) + + # Root node has 1 child with generated node + expect(result.xpath("//#{described_class::ROOT_TAG}/package").count).to eq(1) + end + + context 'when empty xml' do + it_behaves_like 'changing root tag attribute' + end + + context 'when xml has children' do + let(:xml) { described_class.new(xml: empty_xml, data: data).execute } + + it 'has children nodes' do + result = Nokogiri::XML::Document.parse(xml).remove_namespaces! + expect(result.children.count).to be > 0 + end + + it_behaves_like 'changing root tag attribute' + end + end +end diff --git a/spec/support/shared_examples/services/merge_request_shared_examples.rb b/spec/support/shared_examples/services/merge_request_shared_examples.rb index b3ba0a1be93..cfd75d3cfcd 100644 --- a/spec/support/shared_examples/services/merge_request_shared_examples.rb +++ b/spec/support/shared_examples/services/merge_request_shared_examples.rb @@ -19,29 +19,13 @@ RSpec.shared_examples 'reviewer_ids filter' do let(:reviewer2) { create(:user) } context 'when the current user can admin the merge_request' do - context 'when merge_request_reviewer feature is enabled' do + context 'with a reviewer who can read the merge_request' do before do - stub_feature_flags(merge_request_reviewer: true) + project.add_developer(reviewer1) end - context 'with a reviewer who can read the merge_request' do - before do - project.add_developer(reviewer1) - end - - it 'contains reviewers who can read the merge_request' do - expect(execute.reviewers).to contain_exactly(reviewer1) - end - end - end - - context 'when merge_request_reviewer feature is disabled' do - before do - stub_feature_flags(merge_request_reviewer: false) - end - - it 'contains no reviewers' do - expect(execute.reviewers).to eq [] + it 'contains reviewers who can read the merge_request' do + expect(execute.reviewers).to contain_exactly(reviewer1) end end end diff --git a/spec/support/shared_examples/services/reviewers_change_trigger_shared_examples.rb b/spec/support/shared_examples/services/reviewers_change_trigger_shared_examples.rb new file mode 100644 index 00000000000..cc37ea0c6f0 --- /dev/null +++ b/spec/support/shared_examples/services/reviewers_change_trigger_shared_examples.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'triggers GraphQL subscription mergeRequestReviewersUpdated' do + specify do + expect(GraphqlTriggers).to receive(:merge_request_reviewers_updated).with(merge_request) + + action + end +end + +RSpec.shared_examples 'does not trigger GraphQL subscription mergeRequestReviewersUpdated' do + specify do + expect(GraphqlTriggers).not_to receive(:merge_request_reviewers_updated) + + action + end +end |