diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-01 09:07:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-01 09:07:32 +0300 |
commit | 916bb1bb577b64ec769b4c081c4f861a2f47322f (patch) | |
tree | 5184da3dd62647179130811c75de9631c925300d /spec | |
parent | a3e0d4c59ff43ee406d2fee12a29339b95a0787d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/experiments/application_experiment_spec.rb | 35 | ||||
-rw-r--r-- | spec/finders/groups/custom_emoji_finder_spec.rb | 65 | ||||
-rw-r--r-- | spec/graphql/types/group_type_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/banzai/filter/custom_emoji_filter_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/experiment/rollout/feature_spec.rb | 65 | ||||
-rw-r--r-- | spec/models/award_emoji_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/custom_emoji_spec.rb | 41 | ||||
-rw-r--r-- | spec/requests/api/graphql/custom_emoji_query_spec.rb | 4 | ||||
-rw-r--r-- | spec/serializers/discussion_entity_spec.rb | 7 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/helpers/stub_saas_features.rb | 23 | ||||
-rw-r--r-- | spec/support_specs/helpers/stub_saas_features_spec.rb | 65 |
12 files changed, 36 insertions, 322 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 00370a5b7e3..24e08241fe7 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -24,6 +24,12 @@ RSpec.describe ApplicationExperiment, :experiment, feature_category: :acquisitio expect { experiment(:example) {} }.not_to raise_error end + describe ".available?" do + it 'is false for foss' do + expect(described_class).not_to be_available + end + end + describe "#publish" do it "tracks the assignment", :snowplow do expect(application_experiment).to receive(:track).with(:assignment) @@ -169,33 +175,6 @@ RSpec.describe ApplicationExperiment, :experiment, feature_category: :acquisitio end describe "#process_redirect_url" do - using RSpec::Parameterized::TableSyntax - - where(:url, :processed_url) do - 'https://about.gitlab.com/' | 'https://about.gitlab.com/' - 'https://gitlab.com/' | 'https://gitlab.com/' - 'http://docs.gitlab.com' | 'http://docs.gitlab.com' - 'https://docs.gitlab.com/some/path?foo=bar' | 'https://docs.gitlab.com/some/path?foo=bar' - 'http://badgitlab.com' | nil - 'https://gitlab.com.nefarious.net' | nil - 'https://unknown.gitlab.com' | nil - "https://badplace.com\nhttps://gitlab.com" | nil - 'https://gitlabbcom' | nil - 'https://gitlabbcom/' | nil - 'http://gdk.test/foo/bar' | 'http://gdk.test/foo/bar' - 'http://localhost:3000/foo/bar' | 'http://localhost:3000/foo/bar' - end - - with_them do - it "returns the url or nil if invalid on SaaS", :saas do - expect(application_experiment.process_redirect_url(url)).to eq(processed_url) - end - - it "considers all urls invalid when not on SaaS" do - expect(application_experiment.process_redirect_url(url)).to be_nil - end - end - it "generates the correct urls based on where the engine was mounted" do url = Rails.application.routes.url_helpers.experiment_redirect_url(application_experiment, url: 'https://docs.gitlab.com') expect(url).to include("/-/experiment/namespaced%2Fstub:#{application_experiment.context.key}?https://docs.gitlab.com") @@ -227,7 +206,7 @@ RSpec.describe ApplicationExperiment, :experiment, feature_category: :acquisitio it "tracks an event", :snowplow do experiment(:top) { |e| e.control { experiment(:nested) {} } } - expect(Gitlab::Tracking).to have_received(:event).with( # rubocop:disable RSpec/ExpectGitlabTracking + expect(Gitlab::Tracking).to have_received(:event).with( # rubocop:disable RSpec/ExpectGitlabTracking -- Testing nested functionality 'top', :nested, hash_including(label: 'nested') diff --git a/spec/finders/groups/custom_emoji_finder_spec.rb b/spec/finders/groups/custom_emoji_finder_spec.rb deleted file mode 100644 index f1044997d4f..00000000000 --- a/spec/finders/groups/custom_emoji_finder_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Groups::CustomEmojiFinder, feature_category: :code_review_workflow do - describe '#execute' do - let(:params) { {} } - - subject(:execute) { described_class.new(group, params).execute } - - context 'when inside a group' do - let_it_be(:group) { create(:group) } - let_it_be(:custom_emoji) { create(:custom_emoji, group: group) } - - it 'returns custom emoji from group' do - expect(execute).to contain_exactly(custom_emoji) - end - end - - context 'when group is nil' do - let_it_be(:group) { nil } - - it 'returns nil' do - expect(execute).to be_empty - end - end - - context 'when group is a subgroup' do - let_it_be(:parent) { create(:group) } - let_it_be(:group) { create(:group, parent: parent) } - let_it_be(:custom_emoji) { create(:custom_emoji, group: group) } - - it 'returns custom emoji' do - expect(described_class.new(group, params).execute).to contain_exactly(custom_emoji) - end - end - - describe 'when custom emoji is in parent group' do - let_it_be(:parent) { create(:group) } - let_it_be(:group) { create(:group, parent: parent) } - let_it_be(:custom_emoji) { create(:custom_emoji, group: parent) } - let(:params) { { include_ancestor_groups: true } } - - it 'returns custom emoji' do - expect(execute).to contain_exactly(custom_emoji) - end - - context 'when params is empty' do - let(:params) { {} } - - it 'returns empty record' do - expect(execute).to eq([]) - end - end - - context 'when include_ancestor_groups is false' do - let(:params) { { include_ancestor_groups: false } } - - it 'returns empty record' do - expect(execute).to eq([]) - end - end - end - end -end diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index d3f9053faf3..6622551f063 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -125,37 +125,4 @@ RSpec.describe GitlabSchema.types['Group'] do expect { clean_state_query }.not_to exceed_all_query_limit(control) end end - - describe 'custom emoji' do - let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } - let_it_be(:subgroup) { create(:group, parent: group) } - let_it_be(:custom_emoji) { create(:custom_emoji, group: group) } - let_it_be(:custom_emoji_subgroup) { create(:custom_emoji, group: subgroup) } - let(:query) do - %( - query { - group(fullPath: "#{subgroup.full_path}") { - customEmoji(includeAncestorGroups: true) { - nodes { - id - } - } - } - } - ) - end - - before_all do - group.add_reporter(user) - end - - describe 'when includeAncestorGroups is true' do - it 'returns emoji from ancestor groups' do - result = GitlabSchema.execute(query, context: { current_user: user }).as_json - - expect(result.dig('data', 'group', 'customEmoji', 'nodes').count).to eq(2) - end - end - end end diff --git a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb index 4fc9d9dd4f6..7fd25eac81b 100644 --- a/spec/lib/banzai/filter/custom_emoji_filter_spec.rb +++ b/spec/lib/banzai/filter/custom_emoji_filter_spec.rb @@ -55,12 +55,4 @@ RSpec.describe Banzai::Filter::CustomEmojiFilter, feature_category: :team_planni filter('<p>:tanuki:</p> <p>:party-parrot:</p>') end.not_to exceed_all_query_limit(control_count.count) end - - it 'uses custom emoji from ancestor group' do - subgroup = create(:group, parent: group) - - doc = filter('<p>:tanuki:</p>', group: subgroup) - - expect(doc.css('gl-emoji').size).to eq 1 - end end diff --git a/spec/lib/gitlab/experiment/rollout/feature_spec.rb b/spec/lib/gitlab/experiment/rollout/feature_spec.rb index 6d01b7a175f..9d602083ad6 100644 --- a/spec/lib/gitlab/experiment/rollout/feature_spec.rb +++ b/spec/lib/gitlab/experiment/rollout/feature_spec.rb @@ -3,50 +3,25 @@ require 'spec_helper' RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment, feature_category: :acquisition do - subject { described_class.new(subject_experiment) } + subject(:experiment_instance) { described_class.new(subject_experiment) } let(:subject_experiment) { experiment('namespaced/stub') } - describe "#enabled?", :saas do + describe "#enabled?" do before do stub_feature_flags(gitlab_experiment: true) - allow(subject).to receive(:feature_flag_defined?).and_return(true) - allow(subject).to receive(:feature_flag_instance).and_return(double(state: :on)) + allow(experiment_instance).to receive(:feature_flag_defined?).and_return(true) + allow(experiment_instance) + .to receive(:feature_flag_instance).and_return(instance_double('Flipper::Feature', state: :on)) end - it "is enabled when all criteria are met" do - expect(subject).to be_enabled - end - - it "isn't enabled if the feature definition doesn't exist" do - expect(subject).to receive(:feature_flag_defined?).and_return(false) - - expect(subject).not_to be_enabled - end - - it "isn't enabled if we're not in dev or dotcom environments" do - expect(Gitlab).to receive(:com?).and_return(false) - - expect(subject).not_to be_enabled - end - - it "isn't enabled if the feature flag state is :off" do - expect(subject).to receive(:feature_flag_instance).and_return(double(state: :off)) - - expect(subject).not_to be_enabled - end - - it "isn't enabled if the gitlab_experiment feature flag is false" do - stub_feature_flags(gitlab_experiment: false) - - expect(subject).not_to be_enabled - end + it { is_expected.not_to be_enabled } end describe "#execute_assignment" do let(:variants) do ->(e) do - # rubocop:disable Lint/EmptyBlock + # rubocop:disable Lint/EmptyBlock -- Specific for test e.control {} e.variant(:red) {} e.variant(:blue) {} @@ -63,26 +38,26 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment, feature_catego it "uses the default value as specified in the yaml" do expect(Feature).to receive(:enabled?).with( 'namespaced_stub', - subject, + experiment_instance, type: :experiment ).and_return(false) - expect(subject.execute_assignment).to be_nil + expect(experiment_instance.execute_assignment).to be_nil end it "returns an assigned name" do - expect(subject.execute_assignment).to eq(:blue) + expect(experiment_instance.execute_assignment).to eq(:blue) end context "when there are no behaviors" do - let(:variants) { ->(e) { e.control {} } } # rubocop:disable Lint/EmptyBlock + let(:variants) { ->(e) { e.control {} } } # rubocop:disable Lint/EmptyBlock -- Specific for test it "does not raise an error" do - expect { subject.execute_assignment }.not_to raise_error + expect { experiment_instance.execute_assignment }.not_to raise_error end end - context "for even rollout to non-control", :saas do + context "for even rollout to non-control" do let(:counts) { Hash.new(0) } let(:subject_experiment) { experiment('namespaced/stub') } @@ -91,8 +66,8 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment, feature_catego allow(instance).to receive(:enabled?).and_return(true) end - subject_experiment.variant(:variant1) {} # rubocop:disable Lint/EmptyBlock - subject_experiment.variant(:variant2) {} # rubocop:disable Lint/EmptyBlock + subject_experiment.variant(:variant1) {} # rubocop:disable Lint/EmptyBlock -- Specific for test + subject_experiment.variant(:variant2) {} # rubocop:disable Lint/EmptyBlock -- Specific for test end it "rolls out relatively evenly to 2 behaviors" do @@ -102,7 +77,7 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment, feature_catego end it "rolls out relatively evenly to 3 behaviors" do - subject_experiment.variant(:variant3) {} # rubocop:disable Lint/EmptyBlock + subject_experiment.variant(:variant3) {} # rubocop:disable Lint/EmptyBlock -- Specific for test 100.times { |i| run_cycle(subject_experiment, value: i) } @@ -115,7 +90,7 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment, feature_catego end it "rolls out with the expected distribution" do - subject_experiment.variant(:variant3) {} # rubocop:disable Lint/EmptyBlock + subject_experiment.variant(:variant3) {} # rubocop:disable Lint/EmptyBlock -- Specific for test 100.times { |i| run_cycle(subject_experiment, value: i) } @@ -152,14 +127,14 @@ RSpec.describe Gitlab::Experiment::Rollout::Feature, :experiment, feature_catego describe "#flipper_id" do it "returns the expected flipper id if the experiment doesn't provide one" do - subject.instance_variable_set(:@experiment, double(id: '__id__')) - expect(subject.flipper_id).to eq('Experiment;__id__') + experiment_instance.instance_variable_set(:@experiment, instance_double('Gitlab::Experiment', id: '__id__')) + expect(experiment_instance.flipper_id).to eq('Experiment;__id__') end it "lets the experiment provide a flipper id so it can override the default" do allow(subject_experiment).to receive(:flipper_id).and_return('_my_overridden_id_') - expect(subject.flipper_id).to eq('_my_overridden_id_') + expect(experiment_instance.flipper_id).to eq('_my_overridden_id_') end end end diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb index a901453ba9f..87abd8a676d 100644 --- a/spec/models/award_emoji_spec.rb +++ b/spec/models/award_emoji_spec.rb @@ -319,17 +319,6 @@ RSpec.describe AwardEmoji, feature_category: :team_planning do expect(new_award.url).to eq(custom_emoji.url) end - describe 'when inside subgroup' do - let_it_be(:subgroup) { create(:group, parent: custom_emoji.group) } - let_it_be(:project) { create(:project, namespace: subgroup) } - - it 'is set for custom emoji' do - new_award = build_award(custom_emoji.name) - - expect(new_award.url).to eq(custom_emoji.url) - end - end - context 'feature flag disabled' do before do stub_feature_flags(custom_emoji: false) diff --git a/spec/models/custom_emoji_spec.rb b/spec/models/custom_emoji_spec.rb index cbdf05cf28f..15655d08556 100644 --- a/spec/models/custom_emoji_spec.rb +++ b/spec/models/custom_emoji_spec.rb @@ -48,45 +48,4 @@ RSpec.describe CustomEmoji do expect(emoji.errors.messages).to eq(file: ["is blocked: Only allowed schemes are http, https"]) end end - - describe '#for_resource' do - let_it_be(:group) { create(:group) } - let_it_be(:custom_emoji) { create(:custom_emoji, namespace: group) } - - context 'when custom_emoji feature flag is disabled' do - before do - stub_feature_flags(custom_emoji: false) - end - - it { expect(described_class.for_resource(group)).to eq([]) } - end - - context 'when group is nil' do - let_it_be(:group) { nil } - - it { expect(described_class.for_resource(group)).to eq([]) } - end - - context 'when resource is a project' do - let_it_be(:project) { create(:project) } - - it { expect(described_class.for_resource(project)).to eq([]) } - end - - it { expect(described_class.for_resource(group)).to eq([custom_emoji]) } - end - - describe '#for_namespaces' do - let_it_be(:group) { create(:group) } - let_it_be(:custom_emoji) { create(:custom_emoji, namespace: group, name: 'parrot') } - - it { expect(described_class.for_namespaces([group.id])).to eq([custom_emoji]) } - - context 'with subgroup' do - let_it_be(:subgroup) { create(:group, parent: group) } - let_it_be(:subgroup_emoji) { create(:custom_emoji, namespace: subgroup, name: 'parrot') } - - it { expect(described_class.for_namespaces([subgroup.id, group.id])).to eq([subgroup_emoji]) } - end - end end diff --git a/spec/requests/api/graphql/custom_emoji_query_spec.rb b/spec/requests/api/graphql/custom_emoji_query_spec.rb index c89ad0002b4..1858ea831dd 100644 --- a/spec/requests/api/graphql/custom_emoji_query_spec.rb +++ b/spec/requests/api/graphql/custom_emoji_query_spec.rb @@ -35,14 +35,14 @@ RSpec.describe 'getting custom emoji within namespace', feature_category: :share expect(graphql_data['group']['customEmoji']['nodes'].first['name']).to eq(custom_emoji.name) end - it 'returns empty array when the custom_emoji feature flag is disabled' do + it 'returns nil custom emoji when the custom_emoji feature flag is disabled' do stub_feature_flags(custom_emoji: false) post_graphql(custom_emoji_query(group), current_user: current_user) expect(response).to have_gitlab_http_status(:ok) expect(graphql_data['group']).to be_present - expect(graphql_data['group']['customEmoji']['nodes']).to eq([]) + expect(graphql_data['group']['customEmoji']).to be_nil end it 'returns nil group when unauthorised' do diff --git a/spec/serializers/discussion_entity_spec.rb b/spec/serializers/discussion_entity_spec.rb index 4b818ce35e6..0fe10ed2c6d 100644 --- a/spec/serializers/discussion_entity_spec.rb +++ b/spec/serializers/discussion_entity_spec.rb @@ -53,6 +53,13 @@ RSpec.describe DiscussionEntity do .to match_schema('entities/note_user_entity') end + it 'exposes the url for custom award emoji' do + custom_emoji = create(:custom_emoji, group: group) + create(:award_emoji, awardable: note, name: custom_emoji.name) + + expect(subject[:notes].last[:award_emoji].first.keys).to include(:url) + end + context 'when is LegacyDiffDiscussion' do let(:discussion) { create(:legacy_diff_note_on_merge_request, noteable: note.noteable, project: project).to_discussion } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4876acfce8a..e57e110926b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -212,7 +212,6 @@ RSpec.configure do |config| config.include_context 'when rendered has no HTML escapes', type: :view include StubFeatureFlags - include StubSaasFeatures include StubSnowplow include StubMember diff --git a/spec/support/helpers/stub_saas_features.rb b/spec/support/helpers/stub_saas_features.rb deleted file mode 100644 index 82ad6e59cb4..00000000000 --- a/spec/support/helpers/stub_saas_features.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module StubSaasFeatures - # Stub SaaS feature with `feature_name: true/false` - # - # @param [Hash] features where key is feature name and value is boolean whether enabled or not. - # - # Examples - # - `stub_saas_features(onboarding: false)` ... Disable `onboarding` - # SaaS feature globally. - # - `stub_saas_features(onboarding: true)` ... Enable `onboarding` - # SaaS feature globally. - def stub_saas_features(features) - all_features = ::Gitlab::Saas::FEATURES.index_with { false } - all_features.merge!(features) - - all_features.each do |feature_name, value| - raise ArgumentError, 'value must be boolean' unless value.in? [true, false] - - allow(::Gitlab::Saas).to receive(:feature_available?).with(feature_name).and_return(value) - end - end -end diff --git a/spec/support_specs/helpers/stub_saas_features_spec.rb b/spec/support_specs/helpers/stub_saas_features_spec.rb deleted file mode 100644 index db608c774c0..00000000000 --- a/spec/support_specs/helpers/stub_saas_features_spec.rb +++ /dev/null @@ -1,65 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe StubSaasFeatures, feature_category: :shared do - describe '#stub_saas_features' do - using RSpec::Parameterized::TableSyntax - - let(:feature_name) { :feature_one } - let(:all_features) { [feature_name, :feature_two, :feature_three] } - - before do - stub_const("Gitlab::Saas::FEATURES", all_features) - end - - context 'when checking global state' do - where(:feature_value) do - [true, false] - end - - with_them do - before do - stub_saas_features(feature_name => feature_value) - end - - it { expect(::Gitlab::Saas.feature_available?(feature_name)).to eq(feature_value) } - end - end - - context 'when value is not boolean' do - it 'raises an error' do - expect do - stub_saas_features(feature_name => '_not_boolean_') - end.to raise_error(ArgumentError, /value must be boolean/) - end - end - - it 'subsequent run changes state' do - # enable FF on all - stub_saas_features({ feature_name => true }) - expect(::Gitlab::Saas.feature_available?(feature_name)).to eq(true) - - # disable FF on all - stub_saas_features({ feature_name => false }) - expect(::Gitlab::Saas.feature_available?(feature_name)).to eq(false) - end - - it 'handles multiple features' do - stub_saas_features(feature_name => false, some_new_feature: true) - - expect(::Gitlab::Saas.feature_available?(feature_name)).to eq(false) - expect(::Gitlab::Saas.feature_available?(:some_new_feature)).to eq(true) - end - - context 'when checking multiple features' do - it 'stubs defaults false value for other known features' do - stub_saas_features(feature_one: true) - - expect(::Gitlab::Saas.feature_available?(:feature_one)).to eq(true) - expect(::Gitlab::Saas.feature_available?(:feature_two)).to eq(false) - expect(::Gitlab::Saas.feature_available?(:feature_three)).to eq(false) - end - end - end -end |