Commit 30a87139 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '214434-fix-3' into 'master'

Ensure specs are under saas context when needed

See merge request gitlab-org/gitlab!72856
parents 77d2f7e0 a3908e36
......@@ -2,6 +2,10 @@
FactoryBot.define do
factory :gitlab_subscription do
after(:build) do
raise 'not under .com' unless Gitlab.com?
end
namespace
association :hosted_plan, factory: :ultimate_plan
seats { 10 }
......
......@@ -73,7 +73,7 @@ FactoryBot.define do
factory :group_with_plan, parent: :group do
transient do
plan { :default_plan }
plan { :free_plan }
trial_ends_on { nil }
end
......
......@@ -47,7 +47,7 @@ end
FactoryBot.define do
factory :namespace_with_plan, parent: :namespace do
transient do
plan { :default_plan }
plan { :free_plan }
trial_ends_on { nil }
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe 'Billings > Extend / Reactivate Trial', :js do
RSpec.describe 'Billings > Extend / Reactivate Trial', :js, :saas do
include SubscriptionPortalHelpers
let_it_be(:user) { create(:user) }
......
......@@ -21,7 +21,7 @@ RSpec.describe 'Dashboard operations', :js do
expect(page).to have_text(pipeline.status)
end
context 'when opened on gitlab.com', :sass do
context 'when opened on gitlab.com', :saas do
before do
stub_application_setting(check_namespace_plan: true)
stub_licensed_features(operations_dashboard: true)
......
......@@ -249,7 +249,7 @@ RSpec.describe 'Edit group settings' do
end
end
context 'namespace plan is checked' do
context 'namespace plan is checked', :saas do
before do
create(:gitlab_subscription, namespace: group, hosted_plan: plan)
stub_licensed_features(group_project_templates: true)
......
......@@ -45,7 +45,7 @@ RSpec.describe 'Projects > Push Rules', :js do
expect(page).to have_content(title)
end
describe 'with GL.com plans' do
describe 'with GL.com plans', :saas do
before do
stub_application_setting(check_namespace_plan: true)
end
......
......@@ -10,7 +10,7 @@ RSpec.describe ProjectsFinder do
subject { finder.execute }
describe 'filter by plans' do
describe 'filter by plans', :saas do
let(:params) { { plans: plans } }
let(:project_ids_relation) { nil }
......
......@@ -290,7 +290,7 @@ RSpec.describe EpicsFinder do
expect { epics.to_a }.not_to exceed_all_query_limit(5)
end
it 'does not execute more than 6 SQL queries when checking namespace plans' do
it 'does not execute more than 6 SQL queries when checking namespace plans', :saas do
allow(Gitlab::CurrentSettings)
.to receive(:should_check_namespace_plan?)
.and_return(true)
......
......@@ -35,7 +35,7 @@ RSpec.describe GroupsHelper do
end
end
context 'on .com' do
context 'on .com', :saas do
before do
allow(::Gitlab).to receive(:com?).and_return(true)
stub_ee_application_setting(should_check_namespace_plan: true)
......
......@@ -132,7 +132,7 @@ RSpec.describe EE::UserCalloutsHelper do
end
end
describe '#render_dashboard_ultimate_trial' do
describe '#render_dashboard_ultimate_trial', :saas do
let_it_be(:namespace) { create(:namespace) }
let_it_be(:ultimate_plan) { create(:ultimate_plan) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe TrialStatusWidgetHelper do
RSpec.describe TrialStatusWidgetHelper, :saas do
describe 'data attributes for mounting Vue components' do
let(:trial_length) { 30 } # days
let(:today_for_specs) { Date.parse('2021-01-15') }
......
......@@ -9,7 +9,7 @@ RSpec.describe Gitlab::HookData::GroupMemberBuilder do
let(:data) { described_class.new(group_member).build(event) }
context 'data' do
context 'group_plan attribute' do
context 'group_plan attribute', :saas do
let(:group) { create(:group_with_plan, plan: :ultimate_plan) }
it 'returns correct group_plan' do
......
......@@ -17,7 +17,7 @@ RSpec.describe Gitlab::Tracking::StandardContext do
end
end
context 'when namespace is available' do
context 'when namespace is available', :saas do
subject { described_class.new(namespace: create(:namespace_with_plan, plan: plan)) }
it 'contains plan name' do
......
......@@ -58,7 +58,7 @@ RSpec.describe Namespace do
end
described_class::PLANS.each do |namespace_plan|
describe "#{namespace_plan}_plan?" do
describe "#{namespace_plan}_plan?", :saas do
it_behaves_like 'plan helper', namespace_plan
end
end
......@@ -165,7 +165,7 @@ RSpec.describe Namespace do
end
context 'scopes' do
describe '.with_feature_available_in_plan' do
describe '.with_feature_available_in_plan', :saas do
let!(:namespace) { create(:namespace) }
context 'plan is nil' do
......@@ -184,7 +184,7 @@ RSpec.describe Namespace do
end
end
describe '.join_gitlab_subscription' do
describe '.join_gitlab_subscription', :saas do
let!(:namespace) { create(:namespace) }
subject { described_class.join_gitlab_subscription.select('gitlab_subscriptions.hosted_plan_id').first.hosted_plan_id }
......@@ -204,7 +204,7 @@ RSpec.describe Namespace do
end
end
describe '.in_active_trial' do
describe '.in_active_trial', :saas do
let_it_be(:namespaces) do
[
create(:namespace),
......@@ -222,7 +222,7 @@ RSpec.describe Namespace do
end
end
describe '.not_in_active_trial' do
describe '.not_in_active_trial', :saas do
let_it_be(:namespaces) do
[
create(:namespace),
......@@ -240,7 +240,7 @@ RSpec.describe Namespace do
end
end
describe '.in_default_plan' do
describe '.in_default_plan', :saas do
subject { described_class.in_default_plan.ids }
where(:plan_name, :expect_in_default_plan) do
......@@ -268,7 +268,7 @@ RSpec.describe Namespace do
end
end
describe '.eligible_for_trial' do
describe '.eligible_for_trial', :saas do
let_it_be(:namespace) { create :namespace }
subject { described_class.eligible_for_trial.first }
......@@ -509,13 +509,13 @@ RSpec.describe Namespace do
end
end
describe '#feature_available?' do
describe '#feature_available?', :saas do
subject { group.licensed_feature_available?(feature) }
it_behaves_like 'feature available'
end
describe '#feature_available_non_trial?' do
describe '#feature_available_non_trial?', :saas do
subject { group.feature_available_non_trial?(feature) }
it_behaves_like 'feature available'
......@@ -582,7 +582,7 @@ RSpec.describe Namespace do
it { is_expected.to eq(default_limits) }
end
context 'when "free" plan is defined in the system' do
context 'when "free" plan is defined in the system', :saas do
let!(:free_plan) { create(:free_plan) }
context 'when no limits are set' do
......@@ -814,7 +814,7 @@ RSpec.describe Namespace do
end
end
describe '#paid?' do
describe '#paid?', :saas do
it 'returns true for a root namespace with a paid plan' do
create(:gitlab_subscription, :ultimate, namespace: namespace)
......@@ -893,7 +893,7 @@ RSpec.describe Namespace do
end
end
describe '#billed_user_ids' do
describe '#billed_user_ids', :saas do
context 'with a user namespace' do
let(:user) { create(:user) }
......@@ -1170,7 +1170,7 @@ RSpec.describe Namespace do
end
end
describe '#billable_members_count' do
describe '#billable_members_count', :saas do
context 'with a user namespace' do
let(:user) { create(:user) }
......@@ -1782,7 +1782,7 @@ RSpec.describe Namespace do
end
end
describe '#closest_gitlab_subscription' do
describe '#closest_gitlab_subscription', :saas do
subject { group.closest_gitlab_subscription }
context 'when there is a root ancestor' do
......
......@@ -520,7 +520,7 @@ RSpec.describe User do
end
end
context 'when namespace plan is checked' do
context 'when namespace plan is checked', :saas do
before do
create(:gitlab_subscription, namespace: group_1, hosted_plan: create(:bronze_plan))
create(:gitlab_subscription, namespace: group_2, hosted_plan: create(:ultimate_plan))
......@@ -1252,7 +1252,7 @@ RSpec.describe User do
end
end
describe '#manageable_groups_eligible_for_trial' do
describe '#manageable_groups_eligible_for_trial', :saas do
let_it_be(:user) { create :user }
let_it_be(:non_trialed_group_z) { create :group_with_plan, name: 'Zeta', plan: :free_plan }
let_it_be(:non_trialed_group_a) { create :group_with_plan, name: 'Alpha', plan: :free_plan }
......@@ -1355,7 +1355,7 @@ RSpec.describe User do
end
end
context 'feature available for specific groups only' do
context 'feature available for specific groups only', :saas do
before do
allow(Gitlab::CurrentSettings)
.to receive(:should_check_namespace_plan?)
......@@ -1392,7 +1392,7 @@ RSpec.describe User do
end
end
context 'paid namespaces' do
context 'paid namespaces', :saas do
using RSpec::Parameterized::TableSyntax
let_it_be(:ultimate_group) { create(:group_with_plan, plan: :ultimate_plan) }
......@@ -1436,7 +1436,7 @@ RSpec.describe User do
end
end
describe '#owns_paid_namespace?' do
describe '#owns_paid_namespace?', :saas do
context 'when the user is an owner of at least one paid group' do
it 'returns true' do
ultimate_group.add_owner(user)
......@@ -1663,7 +1663,7 @@ RSpec.describe User do
end
end
describe '#owns_upgradeable_namespace?' do
describe '#owns_upgradeable_namespace?', :saas do
let_it_be(:user) { create(:user) }
subject { user.owns_upgradeable_namespace? }
......@@ -1891,7 +1891,7 @@ RSpec.describe User do
is_expected.to be(false)
end
it 'returns false if owns a group with a plan on a trial with an end date' do
it 'returns false if owns a group with a plan on a trial with an end date', :saas do
group_with_plan = create(:group_with_plan, name: 'trial group', plan: :premium_plan, trial_ends_on: 1.year.from_now)
group_with_plan.add_owner(user)
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe ElasticsearchIndexedNamespace do
RSpec.describe ElasticsearchIndexedNamespace, :saas do
before do
stub_ee_application_setting(elasticsearch_indexing: true)
end
......@@ -47,6 +47,8 @@ RSpec.describe ElasticsearchIndexedNamespace do
before do
stub_ee_application_setting(elasticsearch_indexing: false)
described_class.delete_all # reset index status
end
def get_indexed_namespaces
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe GitlabSubscription do
RSpec.describe GitlabSubscription, :saas do
using RSpec::Parameterized::TableSyntax
%i[free_plan bronze_plan premium_plan ultimate_plan].each do |plan|
......
......@@ -23,11 +23,7 @@ RSpec.describe Member, type: :model do
end
describe '#is_using_seat', :aggregate_failures do
context 'when hosted on GL.com' do
before do
allow(Gitlab).to receive(:com?).and_return true
end
context 'when hosted on GL.com', :saas do
it 'calls users check for using the gitlab_com seat method' do
expect(user).to receive(:using_gitlab_com_seat?).with(group).once.and_return true
expect(user).not_to receive(:using_license_seat?)
......@@ -162,7 +158,7 @@ RSpec.describe Member, type: :model do
end
end
context 'check if user cap has been reached' do
context 'check if user cap has been reached', :saas do
let_it_be(:group, refind: true) do
create(:group_with_plan, plan: :ultimate_plan,
namespace_settings: create(:namespace_settings, new_user_signups_cap: 1))
......
......@@ -1411,36 +1411,38 @@ RSpec.describe GroupPolicy do
end
end
it_behaves_like 'model with wiki policies', :saas do
let_it_be_with_refind(:container) { create(:group_with_plan, plan: :premium_plan) }
let_it_be(:user) { owner }
context 'under .com', :saas do
it_behaves_like 'model with wiki policies' do
let_it_be_with_refind(:container) { create(:group_with_plan, plan: :premium_plan) }
let_it_be(:user) { owner }
before_all do
create(:license, plan: License::PREMIUM_PLAN)
end
before do
enable_namespace_license_check!
end
before_all do
create(:license, plan: License::PREMIUM_PLAN)
end
# We don't have feature toggles on groups yet, so we currently simulate
# this by stubbing the license check instead.
def set_access_level(access_level)
case access_level
when ProjectFeature::ENABLED
stub_licensed_features(group_wikis: true)
when ProjectFeature::DISABLED
stub_licensed_features(group_wikis: false)
when ProjectFeature::PRIVATE
skip('Access level private is not supported yet for group wikis, see https://gitlab.com/gitlab-org/gitlab/-/issues/208412')
before do
enable_namespace_license_check!
end
# We don't have feature toggles on groups yet, so we currently simulate
# this by stubbing the license check instead.
def set_access_level(access_level)
case access_level
when ProjectFeature::ENABLED
stub_licensed_features(group_wikis: true)
when ProjectFeature::DISABLED
stub_licensed_features(group_wikis: false)
when ProjectFeature::PRIVATE
skip('Access level private is not supported yet for group wikis, see https://gitlab.com/gitlab-org/gitlab/-/issues/208412')
end
end
end
context 'when the feature is not licensed on this group' do
let_it_be(:container) { create(:group_with_plan, plan: :bronze_plan) }
context 'when the feature is not licensed on this group' do
let_it_be(:container) { create(:group_with_plan, plan: :bronze_plan) }
it 'does not include the wiki permissions' do
expect_disallowed(*wiki_permissions[:all])
it 'does not include the wiki permissions' do
expect_disallowed(*wiki_permissions[:all])
end
end
end
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe SubscriptionPresenter do
RSpec.describe SubscriptionPresenter, :saas do
let(:subscription) { create(:gitlab_subscription) }
let(:presenter) { described_class.new(subscription) }
......
......@@ -121,7 +121,7 @@ RSpec.describe API::Namespaces do
end
end
context 'with gitlab subscription' do
context 'with gitlab subscription', :saas do
before do
group1.add_guest(user)
......@@ -378,7 +378,7 @@ RSpec.describe API::Namespaces do
end
end
context "when passing attributes for gitlab_subscription" do
context "when passing attributes for gitlab_subscription", :saas do
let(:gitlab_subscription) do
{
start_date: '2019-06-01',
......@@ -442,7 +442,7 @@ RSpec.describe API::Namespaces do
end
end
describe 'POST :id/gitlab_subscription' do
describe 'POST :id/gitlab_subscription', :saas do
let(:params) do
{ seats: 10,
plan_code: 'gold',
......@@ -522,7 +522,7 @@ RSpec.describe API::Namespaces do
end
end
describe 'GET :id/gitlab_subscription' do
describe 'GET :id/gitlab_subscription', :saas do
def do_get(current_user)
get api("/namespaces/#{namespace.id}/gitlab_subscription", current_user)
end
......@@ -583,7 +583,7 @@ RSpec.describe API::Namespaces do
end
end
describe 'PUT :id/gitlab_subscription' do
describe 'PUT :id/gitlab_subscription', :saas do
def do_put(namespace_id, current_user, payload)
put api("/namespaces/#{namespace_id}/gitlab_subscription", current_user), params: payload
end
......
......@@ -57,7 +57,7 @@ RSpec.describe Dashboard::Projects::ListService do
it_behaves_like 'project not found'
end
describe 'checking license' do
describe 'checking license', :saas do
let(:projects) { [project] }
using RSpec::Parameterized::TableSyntax
......
......@@ -29,7 +29,7 @@ RSpec.describe Members::CreateService do
create(:group_member, :invited, group: subgroup)
end
context 'with group plan' do
context 'with group plan', :saas do
let(:plan_limits) { create(:plan_limits, daily_invites: daily_invites) }
let(:plan) { create(:plan, limits: plan_limits) }
let!(:subscription) do
......
......@@ -13,7 +13,7 @@ RSpec.shared_examples 'pushes wip limits to frontend' do
end
end
context 'on .com' do
context 'on .com', :saas do
before do
enable_namespace_license_check!
end
......
......@@ -137,7 +137,7 @@ RSpec.describe 'layouts/nav/sidebar/_group' do
end
end
describe 'Security & Compliance menu' do
describe 'Security & Compliance menu', :saas do
let(:group) { create(:group_with_plan, plan: :ultimate_plan) }
before do
......@@ -263,7 +263,7 @@ RSpec.describe 'layouts/nav/sidebar/_group' do
end
end
context 'when security dashboard feature is disabled' do
context 'when security dashboard feature is disabled', :saas do
let(:group) { create(:group_with_plan, plan: :bronze_plan) }
it 'is not visible' do
......
......@@ -2,10 +2,12 @@
require 'spec_helper'
RSpec.describe ElasticNamespaceRolloutWorker do
RSpec.describe ElasticNamespaceRolloutWorker, :saas do
before do
stub_const('ROLLOUT', described_class::ROLLOUT)
stub_const('ROLLBACK', described_class::ROLLBACK)
ElasticsearchIndexedNamespace.delete_all # reset index
end
Plan::PAID_HOSTED_PLANS.each do |plan|
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe ElasticRemoveExpiredNamespaceSubscriptionsFromIndexCronWorker do
RSpec.describe ElasticRemoveExpiredNamespaceSubscriptionsFromIndexCronWorker, :saas do
subject { described_class.new }
let(:not_expired_subscription1) { create(:gitlab_subscription, :bronze, end_date: Date.today + 2) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker do
RSpec.describe UpdateMaxSeatsUsedForGitlabComSubscriptionsWorker, :saas do
describe '#perform' do
subject { described_class.new }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment