diff options
Diffstat (limited to 'spec')
15 files changed, 101 insertions, 87 deletions
diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 01b96c2eb81..6596d788e98 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Admin::GroupsController do expect(response).to have_gitlab_http_status(:ok) expect(response).to render_template(:index) - expect(assigns(:groups)).to match_array([group, group_2, group_3]) + expect(assigns(:groups)).to eq([group, group_2, group_3]) end it 'renders a correct list of sort by options' do @@ -60,7 +60,7 @@ RSpec.describe Admin::GroupsController do it 'returns a sorted by name_asc result' do get :index, params: { sort: 'name_asc' } - expect(assigns(:groups)).to match_array([group, group_3, group_2]) + expect(assigns(:groups)).to eq([group, group_3, group_2]) end end @@ -68,7 +68,7 @@ RSpec.describe Admin::GroupsController do it 'returns a search by name result' do get :index, params: { name: 'Ygr' } - expect(assigns(:groups)).to match_array([group_2]) + expect(assigns(:groups)).to eq([group_2]) end it 'returns an empty list if no match' do diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 8a65c219f5d..00370a5b7e3 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ApplicationExperiment, :experiment, feature_category: :experimentation_conversion do +RSpec.describe ApplicationExperiment, :experiment, feature_category: :acquisition do subject(:application_experiment) { described_class.new('namespaced/stub', **context) } let(:context) { {} } diff --git a/spec/features/gitlab_experiments_spec.rb b/spec/features/gitlab_experiments_spec.rb index c1417f6f7c5..facf4994c44 100644 --- a/spec/features/gitlab_experiments_spec.rb +++ b/spec/features/gitlab_experiments_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe "Gitlab::Experiment", :js, feature_category: :experimentation_activation do +RSpec.describe "Gitlab::Experiment", :js, feature_category: :activation do # This is part of a set of tests that ensure that tracking remains # consistent at the front end layer. Since we don't want to actually # introduce an experiment in real code, we're going to simulate it diff --git a/spec/features/invites_spec.rb b/spec/features/invites_spec.rb index 0a270adbd01..61f91adee32 100644 --- a/spec/features/invites_spec.rb +++ b/spec/features/invites_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe 'Group or Project invitations', :aggregate_failures, feature_category: :experimentation_expansion do +RSpec.describe 'Group or Project invitations', :aggregate_failures, feature_category: :acquisition do let_it_be(:owner) { create(:user, name: 'John Doe') } # private will ensure we really have access to the group when we land on the activity page let_it_be(:group) { create(:group, :private, name: 'Owned') } diff --git a/spec/features/users/signup_spec.rb b/spec/features/users/signup_spec.rb index 73e745db6f8..968308938d1 100644 --- a/spec/features/users/signup_spec.rb +++ b/spec/features/users/signup_spec.rb @@ -67,16 +67,6 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do end shared_examples 'signup process' do - def fill_in_signup_form - fill_in 'new_user_username', with: new_user.username - fill_in 'new_user_email', with: new_user.email - fill_in 'new_user_first_name', with: new_user.first_name - fill_in 'new_user_last_name', with: new_user.last_name - fill_in 'new_user_password', with: new_user.password - - wait_for_all_requests - end - def confirm_email new_user_token = User.find_by_email(new_user.email).confirmation_token @@ -226,9 +216,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'creates the user account and sends a confirmation email, and pre-fills email address after confirming' do visit new_user_registration_path - fill_in_signup_form - - expect { click_button 'Register' }.to change { User.count }.by(1) + expect { fill_in_sign_up_form(new_user) }.to change { User.count }.by(1) expect(page).to have_current_path users_almost_there_path, ignore_query: true expect(page).to have_content("Please check your email (#{new_user.email}) to confirm your account") @@ -246,9 +234,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'creates the user account and sends a confirmation email' do visit new_user_registration_path - fill_in_signup_form - - expect { click_button 'Register' }.to change { User.count }.by(1) + expect { fill_in_sign_up_form(new_user) }.to change { User.count }.by(1) expect(page).to have_current_path dashboard_projects_path end end @@ -262,8 +248,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'creates the user account and goes to dashboard' do visit new_user_registration_path - fill_in_signup_form - click_button "Register" + fill_in_sign_up_form(new_user) expect(page).to have_current_path dashboard_projects_path end @@ -277,9 +262,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'creates the user but does not sign them in' do visit new_user_registration_path - fill_in_signup_form - - expect { click_button 'Register' }.to change { User.count }.by(1) + expect { fill_in_sign_up_form(new_user) }.to change { User.count }.by(1) expect(page).to have_current_path new_user_session_path, ignore_query: true expect(page).to have_content(<<~TEXT.squish) You have signed up successfully. However, we could not sign you in @@ -294,8 +277,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do create(:user, email: new_user.email) visit new_user_registration_path - fill_in_signup_form - click_button "Register" + fill_in_sign_up_form(new_user) expect(page).to have_current_path user_registration_path, ignore_query: true expect(page).to have_content("error prohibited this user from being saved") @@ -306,8 +288,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do create(:user, email: new_user.email) visit new_user_registration_path - fill_in_signup_form - click_button "Register" + fill_in_sign_up_form(new_user) expect(page).to have_current_path user_registration_path, ignore_query: true expect(page.body).not_to match(/#{new_user.password}/) @@ -328,8 +309,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do visit new_user_registration_path expect(page).to have_content(terms_text) - fill_in_signup_form - click_button 'Register' + fill_in_sign_up_form(new_user) expect(page).to have_current_path(dashboard_projects_path) end @@ -357,9 +337,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'prevents from signing up' do visit new_user_registration_path - fill_in_signup_form - - expect { click_button 'Register' }.not_to change { User.count } + expect { fill_in_sign_up_form(new_user) }.not_to change { User.count } expect(page).to have_content(_('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')) expect(page).to have_content( "Minimum length is #{Gitlab::CurrentSettings.minimum_password_length} characters") @@ -370,9 +348,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'prevents from signing up' do visit new_user_registration_path - fill_in_signup_form - - expect { click_button 'Register' }.not_to change { User.count } + expect { fill_in_sign_up_form(new_user) }.not_to change { User.count } expect(page).to have_content('That was a bit too quick! Please resubmit.') end end @@ -381,9 +357,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do it 'allows visiting of a page after initial registration' do visit new_user_registration_path - fill_in_signup_form - - click_button 'Register' + fill_in_sign_up_form(new_user) visit new_project_path @@ -394,8 +368,7 @@ RSpec.describe 'Signup', :js, feature_category: :user_profile do create(:user, email: new_user.email) visit new_user_registration_path - fill_in_signup_form - click_button "Register" + fill_in_sign_up_form(new_user) expect(page).to have_current_path user_registration_path, ignore_query: true expect(page.body).not_to match(/#{new_user.password}/) diff --git a/spec/lib/feature_spec.rb b/spec/lib/feature_spec.rb index 044415b9952..7860d85457a 100644 --- a/spec/lib/feature_spec.rb +++ b/spec/lib/feature_spec.rb @@ -11,6 +11,38 @@ RSpec.describe Feature, :clean_gitlab_redis_feature_flag, stub_feature_flags: fa skip_feature_flags_yaml_validation end + describe '.current_request' do + it 'returns a FlipperRequest with a flipper_id' do + flipper_request = described_class.current_request + + expect(flipper_request.flipper_id).to include("FlipperRequest:") + end + + context 'when request store is inactive' do + it 'does not cache flipper_id' do + previous_id = described_class.current_request.flipper_id + + expect(described_class.current_request.flipper_id).not_to eq(previous_id) + end + end + + context 'when request store is active', :request_store do + it 'caches flipper_id when request store is active' do + previous_id = described_class.current_request.flipper_id + + expect(described_class.current_request.flipper_id).to eq(previous_id) + end + + it 'returns a new flipper_id when request ends' do + previous_id = described_class.current_request.flipper_id + + RequestStore.end! + + expect(described_class.current_request.flipper_id).not_to eq(previous_id) + end + end + end + describe '.get' do let(:feature) { double(:feature) } let(:key) { 'my_feature' } @@ -299,6 +331,36 @@ RSpec.describe Feature, :clean_gitlab_redis_feature_flag, stub_feature_flags: fa end end + context 'with current_request actor' do + context 'when request store is inactive' do + it 'returns the approximate percentage set' do + number_of_times = 1_000 + percentage = 50 + described_class.enable_percentage_of_actors(:enabled_feature_flag, percentage) + + gate_values = Array.new(number_of_times) do + described_class.enabled?(:enabled_feature_flag, described_class.current_request) + end + + margin_of_error = 0.05 * number_of_times + expected_size = number_of_times * percentage / 100 + expect(gate_values.count { |v| v }).to be_within(margin_of_error).of(expected_size) + end + end + + context 'when request store is active', :request_store do + it 'always returns the same gate value' do + described_class.enable_percentage_of_actors(:enabled_feature_flag, 50) + + previous_gate_value = described_class.enabled?(:enabled_feature_flag, described_class.current_request) + + 1_000.times do + expect(described_class.enabled?(:enabled_feature_flag, described_class.current_request)).to eq(previous_gate_value) + end + end + end + end + context 'with a group member' do let(:key) { :awesome_feature } let(:guinea_pigs) { create_list(:user, 3) } diff --git a/spec/lib/gitlab/metrics/web_transaction_spec.rb b/spec/lib/gitlab/metrics/web_transaction_spec.rb index 139091eb456..dc59fa804c4 100644 --- a/spec/lib/gitlab/metrics/web_transaction_spec.rb +++ b/spec/lib/gitlab/metrics/web_transaction_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Gitlab::Metrics::WebTransaction do describe '#labels' do context 'when request goes to Grape endpoint' do before do - route = double(:route, request_method: 'GET', path: '/:version/projects/:id/archive(.:format)', origin: '/:version/projects/:id/archive') + route = double(:route, request_method: 'GET', path: '/:version/projects/:id/archive(.:format)') endpoint = double(:endpoint, route: route, options: { for: API::Projects, path: [":id/archive"] }, namespace: "/projects") @@ -76,12 +76,7 @@ RSpec.describe Gitlab::Metrics::WebTransaction do end it 'provides labels with the method and path of the route in the grape endpoint' do - expect(transaction.labels).to eq({ - controller: 'Grape', - action: 'GET /projects/:id/archive', - feature_category: 'projects', - endpoint_id: 'GET /:version/projects/:id/archive' - }) + expect(transaction.labels).to eq({ controller: 'Grape', action: 'GET /projects/:id/archive', feature_category: 'projects' }) end it 'contains only the labels defined for transactions' do @@ -104,14 +99,11 @@ RSpec.describe Gitlab::Metrics::WebTransaction do before do controller = double(:controller, class: controller_class, action_name: 'show', request: request) - allow(controller_class).to receive(:endpoint_id_for_action) - .with(controller.action_name) - .and_return("#{controller_class.name}##{controller.action_name}") env['action_controller.instance'] = controller end it 'tags a transaction with the name and action of a controller' do - expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT, endpoint_id: 'TestController#show' }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT }) end it 'contains only the labels defined for transactions' do @@ -121,14 +113,8 @@ RSpec.describe Gitlab::Metrics::WebTransaction do context 'when the request content type is not :html' do let(:request) { double(:request, format: double(:format, ref: :json)) } - before do - allow(controller_class).to receive(:endpoint_id_for_action) - .with("show.json") - .and_return("#{controller_class.name}#show.json") - end - it 'appends the mime type to the transaction action' do - expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT, endpoint_id: 'TestController#show.json' }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show.json', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT }) end end @@ -136,7 +122,7 @@ RSpec.describe Gitlab::Metrics::WebTransaction do let(:request) { double(:request, format: double(:format, ref: 'http://example.com')) } it 'does not append the MIME type to the transaction action' do - expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT, endpoint_id: 'TestController#show' }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: ::Gitlab::FeatureCategories::FEATURE_CATEGORY_DEFAULT }) end end @@ -145,7 +131,7 @@ RSpec.describe Gitlab::Metrics::WebTransaction do # This is needed since we're not actually making a request, which would trigger the controller pushing to the context ::Gitlab::ApplicationContext.push(feature_category: 'source_code_management') - expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: 'source_code_management', endpoint_id: 'TestController#show' }) + expect(transaction.labels).to eq({ controller: 'TestController', action: 'show', feature_category: "source_code_management" }) end end end @@ -161,12 +147,9 @@ RSpec.describe Gitlab::Metrics::WebTransaction do let(:controller) { double(:controller, class: controller_class, action_name: 'show', request: request) } let(:transaction_obj) { described_class.new({ 'action_controller.instance' => controller }) } - let(:labels) { { controller: 'TestController', action: 'show', feature_category: 'projects', endpoint_id: 'TestController#show' } } + let(:labels) { { controller: 'TestController', action: 'show', feature_category: 'projects' } } before do - allow(controller_class).to receive(:endpoint_id_for_action) - .with(controller.action_name) - .and_return("#{controller_class.name}##{controller.action_name}") ::Gitlab::ApplicationContext.push(feature_category: 'projects') end end diff --git a/spec/lib/release_highlights/validator_spec.rb b/spec/lib/release_highlights/validator_spec.rb index 7cfeffb095a..47f645d9c87 100644 --- a/spec/lib/release_highlights/validator_spec.rb +++ b/spec/lib/release_highlights/validator_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ReleaseHighlights::Validator, feature_category: :experimentation_adoption do +RSpec.describe ReleaseHighlights::Validator, feature_category: :activation do let(:validator) { described_class.new(file: yaml_path) } let(:yaml_path) { 'spec/fixtures/whats_new/valid.yml' } let(:invalid_yaml_path) { 'spec/fixtures/whats_new/invalid.yml' } diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 9d3359cf633..d728b332091 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -936,47 +936,43 @@ RSpec.describe Group, feature_category: :groups_and_projects do context 'when sort by is not provided (id desc by default)' do let(:sort) { nil } - it { is_expected.to match_array([group_1, group_2, group_3, group_4]) } + it { is_expected.to eq([group_1, group_2, group_3, group_4]) } end context 'when sort by name_asc' do let(:sort) { 'name_asc' } - it { is_expected.to match_array([group_3, group_4, group_2, group_1]) } + it { is_expected.to eq([group_3, group_4, group_2, group_1]) } end context 'when sort by name_desc' do let(:sort) { 'name_desc' } - it { is_expected.to match_array([group_1, group_2, group_4, group_3]) } + it { is_expected.to eq([group_1, group_2, group_4, group_3]) } end context 'when sort by recently_created' do let(:sort) { 'created_desc' } - it { is_expected.to match_array([group_3, group_1, group_4, group_2]) } + it { is_expected.to eq([group_3, group_1, group_4, group_2]) } end context 'when sort by oldest_created' do let(:sort) { 'created_asc' } - it { is_expected.to match_array([group_2, group_4, group_1, group_3]) } + it { is_expected.to eq([group_2, group_4, group_1, group_3]) } end context 'when sort by latest_activity' do let(:sort) { 'latest_activity_desc' } - # this should be expected if latest_activity is based on updated_at - # it { is_expected.to match_array([group_3, group_1, group_4, group_2]) } - it { is_expected.to match_array([group_1, group_2, group_3, group_4]) } + it { is_expected.to eq([group_1, group_2, group_3, group_4]) } end context 'when sort by oldest_activity' do let(:sort) { 'latest_activity_asc' } - # this should be expected if latest_activity is based on updated_at - # it { is_expected.to match_array([group_2, group_4, group_1, group_3]) } - it { is_expected.to match_array([group_1, group_2, group_3, group_4]) } + it { is_expected.to eq([group_1, group_2, group_3, group_4]) } end context 'when sort by storage_size_desc' do @@ -1058,7 +1054,7 @@ RSpec.describe Group, feature_category: :groups_and_projects do let(:sort) { 'storage_size_desc' } - it { is_expected.to match_array([group_2, group_4, group_1, group_3]) } + it { is_expected.to eq([group_2, group_4, group_1, group_3]) } end end diff --git a/spec/rubocop/cop/experiments_test_coverage_spec.rb b/spec/rubocop/cop/experiments_test_coverage_spec.rb index eb1e672ef40..8221d0d6720 100644 --- a/spec/rubocop/cop/experiments_test_coverage_spec.rb +++ b/spec/rubocop/cop/experiments_test_coverage_spec.rb @@ -4,7 +4,7 @@ require 'rubocop_spec_helper' require_relative '../../../rubocop/cop/experiments_test_coverage' -RSpec.describe RuboCop::Cop::ExperimentsTestCoverage, feature_category: :experimentation_conversion do +RSpec.describe RuboCop::Cop::ExperimentsTestCoverage, feature_category: :acquisition do let(:class_offense) { described_class::CLASS_OFFENSE } let(:block_offense) { described_class::BLOCK_OFFENSE } diff --git a/spec/services/ml/experiment_tracking/candidate_repository_spec.rb b/spec/services/ml/experiment_tracking/candidate_repository_spec.rb index 9b46675a08e..c68a581c8ff 100644 --- a/spec/services/ml/experiment_tracking/candidate_repository_spec.rb +++ b/spec/services/ml/experiment_tracking/candidate_repository_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Ml::ExperimentTracking::CandidateRepository, feature_category: :experimentation_activation do +RSpec.describe ::Ml::ExperimentTracking::CandidateRepository, feature_category: :activation do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:experiment) { create(:ml_experiments, user: user, project: project) } diff --git a/spec/services/ml/experiment_tracking/experiment_repository_spec.rb b/spec/services/ml/experiment_tracking/experiment_repository_spec.rb index 3c645fa84b4..f1afc4d66c2 100644 --- a/spec/services/ml/experiment_tracking/experiment_repository_spec.rb +++ b/spec/services/ml/experiment_tracking/experiment_repository_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Ml::ExperimentTracking::ExperimentRepository, feature_category: :experimentation_activation do +RSpec.describe ::Ml::ExperimentTracking::ExperimentRepository, feature_category: :activation do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:experiment) { create(:ml_experiments, user: user, project: project) } diff --git a/spec/services/ml/experiment_tracking/handle_candidate_gitlab_metadata_service_spec.rb b/spec/services/ml/experiment_tracking/handle_candidate_gitlab_metadata_service_spec.rb index f0e7c241d5d..a3a7d538bcc 100644 --- a/spec/services/ml/experiment_tracking/handle_candidate_gitlab_metadata_service_spec.rb +++ b/spec/services/ml/experiment_tracking/handle_candidate_gitlab_metadata_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe ::Ml::ExperimentTracking::HandleCandidateGitlabMetadataService, feature_category: :experimentation_activation do +RSpec.describe ::Ml::ExperimentTracking::HandleCandidateGitlabMetadataService, feature_category: :activation do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { project.owner } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } diff --git a/spec/services/projects/in_product_marketing_campaign_emails_service_spec.rb b/spec/services/projects/in_product_marketing_campaign_emails_service_spec.rb index fab8cafd1a0..f45bf0eea41 100644 --- a/spec/services/projects/in_product_marketing_campaign_emails_service_spec.rb +++ b/spec/services/projects/in_product_marketing_campaign_emails_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::InProductMarketingCampaignEmailsService, feature_category: :experimentation_adoption do +RSpec.describe Projects::InProductMarketingCampaignEmailsService, feature_category: :activation do describe '#execute' do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/workers/projects/record_target_platforms_worker_spec.rb b/spec/workers/projects/record_target_platforms_worker_spec.rb index 116da404112..d4515f7727a 100644 --- a/spec/workers/projects/record_target_platforms_worker_spec.rb +++ b/spec/workers/projects/record_target_platforms_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Projects::RecordTargetPlatformsWorker, feature_category: :experimentation_activation do +RSpec.describe Projects::RecordTargetPlatformsWorker, feature_category: :activation do include ExclusiveLeaseHelpers let_it_be(:swift) { create(:programming_language, name: 'Swift') } |