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/support_specs | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/support_specs')
3 files changed, 107 insertions, 43 deletions
diff --git a/spec/support_specs/helpers/graphql_helpers_spec.rb b/spec/support_specs/helpers/graphql_helpers_spec.rb new file mode 100644 index 00000000000..bfc71f519cf --- /dev/null +++ b/spec/support_specs/helpers/graphql_helpers_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GraphqlHelpers do + include GraphqlHelpers + + describe '.graphql_mutation' do + shared_examples 'correct mutation definition' do + it 'returns correct mutation definition' do + query = <<~MUTATION + mutation($updateAlertStatusInput: UpdateAlertStatusInput!) { + updateAlertStatus(input: $updateAlertStatusInput) { + clientMutationId + } + } + MUTATION + variables = %q({"updateAlertStatusInput":{"projectPath":"test/project"}}) + + is_expected.to eq(GraphqlHelpers::MutationDefinition.new(query, variables)) + end + end + + context 'when fields argument is passed' do + subject do + graphql_mutation(:update_alert_status, { project_path: 'test/project' }, 'clientMutationId') + end + + it_behaves_like 'correct mutation definition' + end + + context 'when block is passed' do + subject do + graphql_mutation(:update_alert_status, { project_path: 'test/project' }) do + 'clientMutationId' + end + end + + it_behaves_like 'correct mutation definition' + end + + context 'when both fields and a block are passed' do + subject do + graphql_mutation(:mutation_name, { variable_name: 'variable/value' }, 'fieldName') do + 'fieldName' + end + end + + it 'raises an ArgumentError' do + expect { subject }.to raise_error( + ArgumentError, + 'Please pass either `fields` parameter or a block to `#graphql_mutation`, but not both.' + ) + end + end + end +end diff --git a/spec/support_specs/helpers/stub_feature_flags_spec.rb b/spec/support_specs/helpers/stub_feature_flags_spec.rb index b6e230075f2..e90a7f68a90 100644 --- a/spec/support_specs/helpers/stub_feature_flags_spec.rb +++ b/spec/support_specs/helpers/stub_feature_flags_spec.rb @@ -3,16 +3,7 @@ require 'spec_helper' describe StubFeatureFlags do - before do - # reset stub introduced by `stub_feature_flags` - allow(Feature).to receive(:enabled?).and_call_original - end - - context 'if not stubbed' do - it 'features are disabled by default' do - expect(Feature.enabled?(:test_feature)).to eq(false) - end - end + let(:feature_name) { :test_feature } describe '#stub_feature_flags' do using RSpec::Parameterized::TableSyntax @@ -30,7 +21,7 @@ describe StubFeatureFlags do with_them do before do - stub_feature_flags(feature_name => feature_actors) + stub_feature_flags(feature_name => actor(feature_actors)) end it { expect(Feature.enabled?(feature_name)).to eq(expected_result) } @@ -62,15 +53,15 @@ describe StubFeatureFlags do with_them do before do - stub_feature_flags(feature_name => feature_actors) + stub_feature_flags(feature_name => actor(feature_actors)) end - it { expect(Feature.enabled?(feature_name, tested_actor)).to eq(expected_result) } - it { expect(Feature.disabled?(feature_name, tested_actor)).not_to eq(expected_result) } + it { expect(Feature.enabled?(feature_name, actor(tested_actor))).to eq(expected_result) } + it { expect(Feature.disabled?(feature_name, actor(tested_actor))).not_to eq(expected_result) } context 'default_enabled does not impact feature state' do - it { expect(Feature.enabled?(feature_name, tested_actor, default_enabled: true)).to eq(expected_result) } - it { expect(Feature.disabled?(feature_name, tested_actor, default_enabled: true)).not_to eq(expected_result) } + it { expect(Feature.enabled?(feature_name, actor(tested_actor), default_enabled: true)).to eq(expected_result) } + it { expect(Feature.disabled?(feature_name, actor(tested_actor), default_enabled: true)).not_to eq(expected_result) } end end end @@ -82,7 +73,7 @@ describe StubFeatureFlags do end with_them do - subject { stub_feature_flags(feature_name => feature_actors) } + subject { stub_feature_flags(feature_name => actor(feature_actors)) } it { expect { subject }.to raise_error(ArgumentError, /accepts only/) } end @@ -90,11 +81,11 @@ describe StubFeatureFlags do context 'does not raise error' do where(:feature_actors) do - [true, false, nil, :symbol, double, User.new] + [true, false, nil, stub_feature_flag_gate(100), User.new] end with_them do - subject { stub_feature_flags(feature_name => feature_actors) } + subject { stub_feature_flags(feature_name => actor(feature_actors)) } it { expect { subject }.not_to raise_error } end @@ -103,28 +94,39 @@ describe StubFeatureFlags do it 'subsquent run changes state' do # enable FF only on A - stub_feature_flags(test_feature: %i[A]) - expect(Feature.enabled?(:test_feature)).to eq(false) - expect(Feature.enabled?(:test_feature, :A)).to eq(true) - expect(Feature.enabled?(:test_feature, :B)).to eq(false) + stub_feature_flags({ feature_name => actor(%i[A]) }) + expect(Feature.enabled?(feature_name)).to eq(false) + expect(Feature.enabled?(feature_name, actor(:A))).to eq(true) + expect(Feature.enabled?(feature_name, actor(:B))).to eq(false) # enable FF only on B - stub_feature_flags(test_feature: %i[B]) - expect(Feature.enabled?(:test_feature)).to eq(false) - expect(Feature.enabled?(:test_feature, :A)).to eq(false) - expect(Feature.enabled?(:test_feature, :B)).to eq(true) + stub_feature_flags({ feature_name => actor(%i[B]) }) + expect(Feature.enabled?(feature_name)).to eq(false) + expect(Feature.enabled?(feature_name, actor(:A))).to eq(false) + expect(Feature.enabled?(feature_name, actor(:B))).to eq(true) # enable FF on all - stub_feature_flags(test_feature: true) - expect(Feature.enabled?(:test_feature)).to eq(true) - expect(Feature.enabled?(:test_feature, :A)).to eq(true) - expect(Feature.enabled?(:test_feature, :B)).to eq(true) + stub_feature_flags({ feature_name => true }) + expect(Feature.enabled?(feature_name)).to eq(true) + expect(Feature.enabled?(feature_name, actor(:A))).to eq(true) + expect(Feature.enabled?(feature_name, actor(:B))).to eq(true) # disable FF on all - stub_feature_flags(test_feature: false) - expect(Feature.enabled?(:test_feature)).to eq(false) - expect(Feature.enabled?(:test_feature, :A)).to eq(false) - expect(Feature.enabled?(:test_feature, :B)).to eq(false) + stub_feature_flags({ feature_name => false }) + expect(Feature.enabled?(feature_name)).to eq(false) + expect(Feature.enabled?(feature_name, actor(:A))).to eq(false) + expect(Feature.enabled?(feature_name, actor(:B))).to eq(false) + end + end + + def actor(actor) + case actor + when Array + actor.map(&method(:actor)) + when Symbol # convert to flipper compatible object + stub_feature_flag_gate(actor) + else + actor end end end diff --git a/spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb b/spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb index 3b15d804d7c..4a711b43d9a 100644 --- a/spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb +++ b/spec/support_specs/matchers/exceed_query_limit_helpers_spec.rb @@ -3,16 +3,21 @@ require 'spec_helper' describe ExceedQueryLimitHelpers do - class TestQueries < ActiveRecord::Base - self.table_name = 'schema_migrations' - end + before do + stub_const('TestQueries', Class.new(ActiveRecord::Base)) + stub_const('TestMatcher', Class.new) + + TestQueries.class_eval do + self.table_name = 'schema_migrations' + end - class TestMatcher - include ExceedQueryLimitHelpers + TestMatcher.class_eval do + include ExceedQueryLimitHelpers - def expected - ActiveRecord::QueryRecorder.new do - 2.times { TestQueries.count } + def expected + ActiveRecord::QueryRecorder.new do + 2.times { TestQueries.count } + end end end end |