Commit 81313af3 authored by Douwe Maan's avatar Douwe Maan

Merge branch '2657-use-stub-licensed-features' into 'master'

Use stub_licensed_features everywhere it is appropriate

Closes #2657

See merge request !2233
parents c2c34698 ea323463
module AuditorUserHelper
def license_allows_auditor_user?
@license_allows_auditor_user ||= (::License.current&.feature_available?(:auditor_user))
@license_allows_auditor_user ||= ::License.feature_available?(:auditor_user)
end
end
......@@ -51,7 +51,7 @@ module Gitlab
end
def self.license_allows?
::License.current&.feature_available?(:geo)
::License.feature_available?(:geo)
end
def self.primary?
......
......@@ -9,8 +9,6 @@ describe Projects::EnvironmentsController do
end
before do
allow_any_instance_of(License).to receive(:feature_available?).and_return(false)
project.add_master(user)
sign_in(user)
......@@ -46,7 +44,7 @@ describe Projects::EnvironmentsController do
context 'when requesting available environments scope' do
before do
allow_any_instance_of(License).to receive(:feature_available?).with(:deploy_board).and_return(true)
stub_licensed_features(deploy_board: true)
get :index, environment_params(format: :json, scope: :available)
end
......@@ -94,7 +92,7 @@ describe Projects::EnvironmentsController do
context 'when license does not has the GitLab_DeployBoard add-on' do
before do
allow_any_instance_of(License).to receive(:feature_available?).with(:deploy_board).and_return(false)
stub_licensed_features(deploy_board: false)
get :index, environment_params(format: :json)
end
......@@ -307,7 +305,7 @@ describe Projects::EnvironmentsController do
let(:environment) { create(:environment, name: 'production', project: project) }
before do
allow_any_instance_of(License).to receive(:feature_available?).with(:deploy_board).and_return(true)
stub_licensed_features(deploy_board: true)
allow_any_instance_of(Environment).to receive(:deployment_service_ready?).and_return(true)
end
......@@ -335,7 +333,7 @@ describe Projects::EnvironmentsController do
context 'when license does not has the GitLab_DeployBoard add-on' do
before do
allow_any_instance_of(License).to receive(:feature_available?).with(:deploy_board).and_return(false)
stub_licensed_features(deploy_board: false)
end
it 'does not return any data' do
......
......@@ -16,9 +16,9 @@ feature "License Admin", feature: true do
end
describe 'limited users' do
let!(:license) { create(:license, data: build(:gitlab_license, restrictions: { active_user_count: 2000 }).export) }
it 'shows panel counts' do
restrictions = { active_user_count: 2000 }
allow_any_instance_of(Gitlab::License).to receive(:restrictions).and_return(restrictions)
visit admin_license_path
page.within '.license-panel' do
......
......@@ -19,8 +19,7 @@ describe 'Related issues', feature: true, js: true do
context 'with related_issues enabled' do
before do
allow_any_instance_of(License).to receive(:feature_available?).and_call_original
allow_any_instance_of(License).to receive(:feature_available?).with(:related_issues) { true }
stub_licensed_features(related_issues: true)
end
context 'with existing related issues' do
......@@ -79,8 +78,7 @@ describe 'Related issues', feature: true, js: true do
context 'with related_issues enabled' do
before do
allow_any_instance_of(License).to receive(:feature_available?).and_call_original
allow_any_instance_of(License).to receive(:feature_available?).with(:related_issues) { true }
stub_licensed_features(related_issues: true)
end
context 'without existing related issues' do
......
......@@ -96,12 +96,12 @@ describe Gitlab::Geo, lib: true do
describe 'license_allows?' do
it 'returns true if license has Geo addon' do
allow_any_instance_of(License).to receive(:feature_available?).with(:geo) { true }
stub_licensed_features(geo: true)
expect(described_class.license_allows?).to be_truthy
end
it 'returns false if license doesnt have Geo addon' do
allow_any_instance_of(License).to receive(:feature_available?).with(:geo) { false }
stub_licensed_features(geo: false)
expect(described_class.license_allows?).to be_falsey
end
......
......@@ -7,7 +7,7 @@ describe EE::User, models: true do
before do
# `auditor?` returns true only when the user is an auditor _and_ the auditor license
# add-on is present. We aren't testing this here, so we can assume that the add-on exists.
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { true }
stub_licensed_features(auditor_user: true)
end
it "does not set 'auditor' for an invalid access level" do
......
......@@ -1816,15 +1816,9 @@ describe User, models: true do
end
describe 'the GitLab_Auditor_User add-on' do
let(:license) { build(:license) }
before do
allow(::License).to receive(:current).and_return(license)
end
context 'creating an auditor user' do
it "does not allow creating an auditor user if the addon isn't enabled" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { false }
stub_licensed_features(auditor_user: false)
expect(build(:user, :auditor)).to be_invalid
end
......@@ -1836,13 +1830,13 @@ describe User, models: true do
end
it "allows creating an auditor user if the addon is enabled" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { true }
stub_licensed_features(auditor_user: true)
expect(build(:user, :auditor)).to be_valid
end
it "allows creating a regular user if the addon isn't enabled" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { false }
stub_licensed_features(auditor_user: false)
expect(build(:user)).to be_valid
end
......@@ -1850,25 +1844,25 @@ describe User, models: true do
context '#auditor?' do
it "returns true for an auditor user if the addon is enabled" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { true }
stub_licensed_features(auditor_user: true)
expect(build(:user, :auditor)).to be_auditor
end
it "returns false for an auditor user if the addon is not enabled" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { false }
stub_licensed_features(auditor_user: false)
expect(build(:user, :auditor)).not_to be_auditor
end
it "returns false for an auditor user if a license is not present" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { false }
stub_licensed_features(auditor_user: false)
expect(build(:user, :auditor)).not_to be_auditor
end
it "returns false for a non-auditor user even if the addon is present" do
allow_any_instance_of(License).to receive(:feature_available?).with(:auditor_user) { true }
stub_licensed_features(auditor_user: true)
expect(build(:user)).not_to be_auditor
end
......
......@@ -10,10 +10,6 @@ describe ProjectPolicy, models: true do
let(:admin) { create(:admin) }
let(:project) { create(:empty_project, :public, namespace: owner.namespace) }
before do
allow_any_instance_of(License).to receive(:feature_available?) { true }
end
let(:guest_permissions) do
%i[
read_project read_board read_list read_wiki read_issue read_label
......
......@@ -6,8 +6,7 @@ describe Projects::IssueLinksController do
let(:issue) { create :issue, project: project }
before do
allow_any_instance_of(License).to receive(:feature_available?) { false }
allow_any_instance_of(License).to receive(:feature_available?).with(:related_issues) { true }
stub_licensed_features(related_issues: true)
end
describe 'GET /*namespace_id/:project_id/issues/:issue_id/links' do
......
......@@ -11,8 +11,6 @@ describe EnvironmentEntity do
subject { entity.as_json }
before do
allow_any_instance_of(License).to receive(:feature_available?).and_return(false)
environment.project.team << [user, :master]
end
......@@ -46,7 +44,7 @@ describe EnvironmentEntity do
context 'with deployment service ready' do
before do
allow_any_instance_of(License).to receive(:feature_available?).with(:deploy_board).and_return(true)
stub_licensed_features(deploy_board: true)
allow(environment).to receive(:deployment_service_ready?).and_return(true)
end
......@@ -59,7 +57,7 @@ describe EnvironmentEntity do
context 'when license does not has the GitLab_DeployBoard add-on' do
before do
allow_any_instance_of(License).to receive(:feature_available?).with(:deploy_board).and_return(false)
stub_licensed_features(deploy_board: false)
allow(environment).to receive(:deployment_service_ready?).and_return(true)
end
......
......@@ -11,8 +11,7 @@ describe IssueLinks::CreateService, service: true do
end
before do
allow_any_instance_of(License).to receive(:feature_available?) { false }
allow_any_instance_of(License).to receive(:feature_available?).with(:related_issues) { true }
stub_licensed_features(related_issues: true)
project.team << [user, :developer]
end
......
......@@ -7,8 +7,7 @@ describe IssueLinks::ListService, service: true do
let(:user_role) { :developer }
before do
allow_any_instance_of(License).to receive(:feature_available?) { false }
allow_any_instance_of(License).to receive(:feature_available?).with(:related_issues) { true }
stub_licensed_features(related_issues: true)
project.team << [user, user_role]
end
......
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