Commit c1870909 authored by Timothy Andrew's avatar Timothy Andrew

Fix build.

There were failures related to cross-spec contamination of the `License` mocks.
parent 9b071cd9
......@@ -1494,9 +1494,15 @@ 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(:add_ons).and_return({})
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_Auditor_User') { false }
expect(build(:user, :auditor)).to be_invalid
end
......@@ -1508,13 +1514,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(:add_ons).and_return({ 'GitLab_Auditor_User' => 1 })
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_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(:add_ons).and_return({})
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_Auditor_User') { false }
expect(build(:user)).to be_valid
end
......@@ -1522,25 +1528,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(:add_ons).and_return({ 'GitLab_Auditor_User' => 1 })
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_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(:add_ons).and_return({})
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_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(License).to receive(:current).and_return nil
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_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(:add_ons).and_return({ 'GitLab_Auditor_User' => 1 })
allow_any_instance_of(License).to receive(:add_on?).with('GitLab_Auditor_User') { true }
expect(build(:user)).not_to be_auditor
end
......@@ -1549,6 +1555,12 @@ describe User, models: true do
context 'access_level=' do
let(:user) { build(:user) }
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(:add_on?).with('GitLab_Auditor_User') { true }
end
it 'does nothing for an invalid access level' do
user.access_level = :invalid_access_level
......
......@@ -17,7 +17,7 @@ describe API::License, api: true do
expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months
expect(json_response['active_users']).to eq 1
expect(json_response['licensee']).not_to be_empty
expect(json_response['add_ons']).to eq({ 'GitLab_FileLocks' => 1 })
expect(json_response['add_ons']).to eq({ 'GitLab_FileLocks' => 1, 'GitLab_Auditor_User' => 1 })
end
it 'denies access if not admin' do
......
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