debian-mirror-gitlab/spec/finders/projects_finder_spec.rb

96 lines
2.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe ProjectsFinder do
2015-11-26 14:37:03 +05:30
describe '#execute' do
let(:user) { create(:user) }
2016-06-02 11:05:42 +05:30
let(:group) { create(:group, :public) }
2014-09-02 18:07:02 +05:30
2015-12-23 02:04:40 +05:30
let!(:private_project) do
create(:project, :private, name: 'A', path: 'A')
end
let!(:internal_project) do
create(:project, :internal, group: group, name: 'B', path: 'B')
end
let!(:public_project) do
create(:project, :public, group: group, name: 'C', path: 'C')
end
2014-09-02 18:07:02 +05:30
2016-06-02 11:05:42 +05:30
let!(:shared_project) do
create(:project, :private, name: 'D', path: 'D')
end
2015-11-26 14:37:03 +05:30
let(:finder) { described_class.new }
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
describe 'without a group' do
describe 'without a user' do
subject { finder.execute }
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
it { is_expected.to eq([public_project]) }
end
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
describe 'with a user' do
subject { finder.execute(user) }
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
describe 'without private projects' do
it { is_expected.to eq([public_project, internal_project]) }
end
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
describe 'with private projects' do
before do
private_project.team.add_user(user, Gitlab::Access::MASTER)
end
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
it do
is_expected.to eq([public_project, internal_project,
private_project])
end
end
end
end
describe 'with a group' do
describe 'without a user' do
subject { finder.execute(nil, group: group) }
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
it { is_expected.to eq([public_project]) }
end
2014-09-02 18:07:02 +05:30
2015-11-26 14:37:03 +05:30
describe 'with a user' do
subject { finder.execute(user, group: group) }
2014-09-02 18:07:02 +05:30
2016-06-02 11:05:42 +05:30
describe 'without shared projects' do
it { is_expected.to eq([public_project, internal_project]) }
end
describe 'with shared projects and group membership' do
before do
group.add_user(user, Gitlab::Access::DEVELOPER)
shared_project.project_group_links.
create(group_access: Gitlab::Access::MASTER, group: group)
end
it do
is_expected.to eq([shared_project, public_project, internal_project])
end
end
describe 'with shared projects and project membership' do
before do
shared_project.team.add_user(user, Gitlab::Access::DEVELOPER)
shared_project.project_group_links.
create(group_access: Gitlab::Access::MASTER, group: group)
end
it do
is_expected.to eq([shared_project, public_project, internal_project])
end
end
2015-11-26 14:37:03 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
end