Commit a1acada0 authored by charlie ablett's avatar charlie ablett

Merge branch 'kerrizor/refactor-visibility_level_checker-spec' into 'master'

Refactor visibility_level_checker spec

See merge request gitlab-org/gitlab!45076
parents ac7ad4ab b32b80a0
...@@ -5,16 +5,13 @@ require 'spec_helper' ...@@ -5,16 +5,13 @@ require 'spec_helper'
RSpec.describe Gitlab::VisibilityLevelChecker do RSpec.describe Gitlab::VisibilityLevelChecker do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project) } let(:project) { create(:project) }
let(:visibility_level_checker) { }
let(:override_params) { {} } let(:override_params) { {} }
subject { described_class.new(user, project, project_params: override_params) }
describe '#level_restricted?' do describe '#level_restricted?' do
subject(:result) { described_class.new(user, project, project_params: override_params).level_restricted? }
context 'when visibility level is allowed' do context 'when visibility level is allowed' do
it 'returns false with nil for visibility level' do it 'returns false with nil for visibility level' do
result = subject.level_restricted?
expect(result.restricted?).to eq(false) expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil expect(result.visibility_level).to be_nil
end end
...@@ -25,12 +22,26 @@ RSpec.describe Gitlab::VisibilityLevelChecker do ...@@ -25,12 +22,26 @@ RSpec.describe Gitlab::VisibilityLevelChecker do
stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC]) stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
end end
it 'returns true and visibility name' do context 'for public project' do
project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC) before do
result = subject.level_restricted? project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
end
context 'for non-admin user' do
it 'returns true and visibility name' do
expect(result.restricted?).to eq(true)
expect(result.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
end
end
context 'for admin user' do
let(:user) { create(:user, :admin) }
expect(result.restricted?).to eq(true) it 'returns false and a nil visibility level' do
expect(result.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC) expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil
end
end
end end
context 'overridden visibility' do context 'overridden visibility' do
...@@ -50,8 +61,6 @@ RSpec.describe Gitlab::VisibilityLevelChecker do ...@@ -50,8 +61,6 @@ RSpec.describe Gitlab::VisibilityLevelChecker do
let(:override_visibility) { 'public' } let(:override_visibility) { 'public' }
it 'returns true and visibility name' do it 'returns true and visibility name' do
result = subject.level_restricted?
expect(result.restricted?).to eq(true) expect(result.restricted?).to eq(true)
expect(result.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC) expect(result.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
end end
...@@ -61,8 +70,6 @@ RSpec.describe Gitlab::VisibilityLevelChecker do ...@@ -61,8 +70,6 @@ RSpec.describe Gitlab::VisibilityLevelChecker do
let(:override_visibility) { 'publik' } let(:override_visibility) { 'publik' }
it 'returns false with nil for visibility level' do it 'returns false with nil for visibility level' do
result = subject.level_restricted?
expect(result.restricted?).to eq(false) expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil expect(result.visibility_level).to be_nil
end end
...@@ -72,8 +79,6 @@ RSpec.describe Gitlab::VisibilityLevelChecker do ...@@ -72,8 +79,6 @@ RSpec.describe Gitlab::VisibilityLevelChecker do
let(:override_params) { {} } let(:override_params) { {} }
it 'returns false with nil for visibility level' do it 'returns false with nil for visibility level' do
result = subject.level_restricted?
expect(result.restricted?).to eq(false) expect(result.restricted?).to eq(false)
expect(result.visibility_level).to be_nil expect(result.visibility_level).to be_nil
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