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