[CE] Reduce differences with EE in users_finder_spec.rb
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
9e171a530f
commit
0750638f80
4 changed files with 36 additions and 47 deletions
|
@ -34,7 +34,7 @@ describe MergeRequestsFinder do
|
||||||
it 'includes all merge requests when user has access exceluding merge requests from projects the user does not have access to' do
|
it 'includes all merge requests when user has access exceluding merge requests from projects the user does not have access to' do
|
||||||
private_project = allow_gitaly_n_plus_1 { create(:project, :private, group: group) }
|
private_project = allow_gitaly_n_plus_1 { create(:project, :private, group: group) }
|
||||||
private_project.add_guest(user)
|
private_project.add_guest(user)
|
||||||
private_mr = create(:merge_request, :simple, author: user, source_project: private_project, target_project: private_project)
|
create(:merge_request, :simple, author: user, source_project: private_project, target_project: private_project)
|
||||||
params = { group_id: group.id }
|
params = { group_id: group.id }
|
||||||
|
|
||||||
merge_requests = described_class.new(user, params).execute
|
merge_requests = described_class.new(user, params).execute
|
||||||
|
|
|
@ -2,10 +2,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe UsersFinder do
|
describe UsersFinder do
|
||||||
describe '#execute' do
|
describe '#execute' do
|
||||||
let!(:user1) { create(:user, username: 'johndoe') }
|
include_context 'UsersFinder#execute filter by project context'
|
||||||
let!(:user2) { create(:user, :blocked, username: 'notsorandom') }
|
|
||||||
let!(:external_user) { create(:user, :external) }
|
|
||||||
let!(:omniauth_user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
|
|
||||||
|
|
||||||
context 'with a normal user' do
|
context 'with a normal user' do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
@ -13,43 +10,43 @@ describe UsersFinder do
|
||||||
it 'returns all users' do
|
it 'returns all users' do
|
||||||
users = described_class.new(user).execute
|
users = described_class.new(user).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user, user1, user2, omniauth_user)
|
expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by username' do
|
it 'filters by username' do
|
||||||
users = described_class.new(user, username: 'johndoe').execute
|
users = described_class.new(user, username: 'johndoe').execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user1)
|
expect(users).to contain_exactly(normal_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by username (case insensitive)' do
|
it 'filters by username (case insensitive)' do
|
||||||
users = described_class.new(user, username: 'joHNdoE').execute
|
users = described_class.new(user, username: 'joHNdoE').execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user1)
|
expect(users).to contain_exactly(normal_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by search' do
|
it 'filters by search' do
|
||||||
users = described_class.new(user, search: 'orando').execute
|
users = described_class.new(user, search: 'orando').execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user2)
|
expect(users).to contain_exactly(blocked_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by blocked users' do
|
it 'filters by blocked users' do
|
||||||
users = described_class.new(user, blocked: true).execute
|
users = described_class.new(user, blocked: true).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user2)
|
expect(users).to contain_exactly(blocked_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by active users' do
|
it 'filters by active users' do
|
||||||
users = described_class.new(user, active: true).execute
|
users = described_class.new(user, active: true).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user, user1, omniauth_user)
|
expect(users).to contain_exactly(user, normal_user, omniauth_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns no external users' do
|
it 'returns no external users' do
|
||||||
users = described_class.new(user, external: true).execute
|
users = described_class.new(user, external: true).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user, user1, user2, omniauth_user)
|
expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by created_at' do
|
it 'filters by created_at' do
|
||||||
|
@ -69,7 +66,7 @@ describe UsersFinder do
|
||||||
custom_attributes: { foo: 'bar' }
|
custom_attributes: { foo: 'bar' }
|
||||||
).execute
|
).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user, user1, user2, omniauth_user)
|
expect(users).to contain_exactly(user, normal_user, blocked_user, omniauth_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -85,20 +82,20 @@ describe UsersFinder do
|
||||||
it 'returns all users' do
|
it 'returns all users' do
|
||||||
users = described_class.new(admin).execute
|
users = described_class.new(admin).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(admin, user1, user2, external_user, omniauth_user)
|
expect(users).to contain_exactly(admin, normal_user, blocked_user, external_user, omniauth_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'filters by custom attributes' do
|
it 'filters by custom attributes' do
|
||||||
create :user_custom_attribute, user: user1, key: 'foo', value: 'foo'
|
create :user_custom_attribute, user: normal_user, key: 'foo', value: 'foo'
|
||||||
create :user_custom_attribute, user: user1, key: 'bar', value: 'bar'
|
create :user_custom_attribute, user: normal_user, key: 'bar', value: 'bar'
|
||||||
create :user_custom_attribute, user: user2, key: 'foo', value: 'foo'
|
create :user_custom_attribute, user: blocked_user, key: 'foo', value: 'foo'
|
||||||
|
|
||||||
users = described_class.new(
|
users = described_class.new(
|
||||||
admin,
|
admin,
|
||||||
custom_attributes: { foo: 'foo', bar: 'bar' }
|
custom_attributes: { foo: 'foo', bar: 'bar' }
|
||||||
).execute
|
).execute
|
||||||
|
|
||||||
expect(users).to contain_exactly(user1)
|
expect(users).to contain_exactly(normal_user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
RSpec.shared_context 'UsersFinder#execute filter by project context' do
|
||||||
|
set(:normal_user) { create(:user, username: 'johndoe') }
|
||||||
|
set(:blocked_user) { create(:user, :blocked, username: 'notsorandom') }
|
||||||
|
set(:external_user) { create(:user, :external) }
|
||||||
|
set(:omniauth_user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
|
||||||
|
end
|
|
@ -10,14 +10,6 @@ RSpec.shared_examples 'snippet visibility' do
|
||||||
set(:member) { create(:user) }
|
set(:member) { create(:user) }
|
||||||
set(:external) { create(:user, :external) }
|
set(:external) { create(:user, :external) }
|
||||||
|
|
||||||
let!(:snippet_type_visibilities) do
|
|
||||||
{
|
|
||||||
public: Snippet::PUBLIC,
|
|
||||||
internal: Snippet::INTERNAL,
|
|
||||||
private: Snippet::PRIVATE
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
context "For project snippets" do
|
context "For project snippets" do
|
||||||
let!(:users) do
|
let!(:users) do
|
||||||
{
|
{
|
||||||
|
@ -29,14 +21,6 @@ RSpec.shared_examples 'snippet visibility' do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:project_feature_visibilities) do
|
|
||||||
{
|
|
||||||
enabled: ProjectFeature::ENABLED,
|
|
||||||
private: ProjectFeature::PRIVATE,
|
|
||||||
disabled: ProjectFeature::DISABLED
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
where(:project_type, :feature_visibility, :user_type, :snippet_type, :outcome) do
|
where(:project_type, :feature_visibility, :user_type, :snippet_type, :outcome) do
|
||||||
[
|
[
|
||||||
# Public projects
|
# Public projects
|
||||||
|
@ -277,26 +261,26 @@ RSpec.shared_examples 'snippet visibility' do
|
||||||
|
|
||||||
where(:snippet_visibility, :user_type, :outcome) do
|
where(:snippet_visibility, :user_type, :outcome) do
|
||||||
[
|
[
|
||||||
[:public, :unauthenticated, true],
|
[Snippet::PUBLIC, :unauthenticated, true],
|
||||||
[:public, :external, true],
|
[Snippet::PUBLIC, :external, true],
|
||||||
[:public, :non_member, true],
|
[Snippet::PUBLIC, :non_member, true],
|
||||||
[:public, :author, true],
|
[Snippet::PUBLIC, :author, true],
|
||||||
|
|
||||||
[:internal, :unauthenticated, false],
|
[Snippet::INTERNAL, :unauthenticated, false],
|
||||||
[:internal, :external, false],
|
[Snippet::INTERNAL, :external, false],
|
||||||
[:internal, :non_member, true],
|
[Snippet::INTERNAL, :non_member, true],
|
||||||
[:internal, :author, true],
|
[Snippet::INTERNAL, :author, true],
|
||||||
|
|
||||||
[:private, :unauthenticated, false],
|
[Snippet::PRIVATE, :unauthenticated, false],
|
||||||
[:private, :external, false],
|
[Snippet::PRIVATE, :external, false],
|
||||||
[:private, :non_member, false],
|
[Snippet::PRIVATE, :non_member, false],
|
||||||
[:private, :author, true]
|
[Snippet::PRIVATE, :author, true]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
with_them do
|
with_them do
|
||||||
let!(:user) { users[user_type] }
|
let!(:user) { users[user_type] }
|
||||||
let!(:snippet) { create(:personal_snippet, visibility_level: snippet_type_visibilities[snippet_visibility], author: author) }
|
let!(:snippet) { create(:personal_snippet, visibility_level: snippet_visibility, author: author) }
|
||||||
|
|
||||||
context "For personal and #{params[:snippet_visibility]} snippets with #{params[:user_type]} user" do
|
context "For personal and #{params[:snippet_visibility]} snippets with #{params[:user_type]} user" do
|
||||||
it 'should agree with read_personal_snippet policy' do
|
it 'should agree with read_personal_snippet policy' do
|
||||||
|
|
Loading…
Reference in a new issue