2019-08-03 06:57:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-05 06:49:58 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe StarredProjectsFinder do
|
2019-02-05 06:49:58 -05:00
|
|
|
let(:project1) { create(:project, :public, :empty_repo) }
|
|
|
|
let(:project2) { create(:project, :public, :empty_repo) }
|
2020-12-07 16:10:08 -05:00
|
|
|
let(:private_project) { create(:project, :private, :empty_repo) }
|
2019-02-05 06:49:58 -05:00
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:other_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
user.toggle_star(project1)
|
|
|
|
user.toggle_star(project2)
|
2020-12-07 16:10:08 -05:00
|
|
|
|
|
|
|
private_project.add_maintainer(user)
|
|
|
|
user.toggle_star(private_project)
|
2019-02-05 06:49:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
let(:finder) { described_class.new(user, params: {}, current_user: current_user) }
|
|
|
|
|
|
|
|
subject { finder.execute }
|
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
context 'user has a public profile' do
|
|
|
|
describe 'as same user' do
|
|
|
|
let(:current_user) { user }
|
2019-02-05 06:49:58 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
it { is_expected.to contain_exactly(project1, project2, private_project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'as other user' do
|
|
|
|
let(:current_user) { other_user }
|
2019-02-05 06:49:58 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
it { is_expected.to contain_exactly(project1, project2) }
|
|
|
|
end
|
2019-02-05 06:49:58 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
describe 'as no user' do
|
|
|
|
let(:current_user) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(project1, project2) }
|
|
|
|
end
|
2019-02-05 06:49:58 -05:00
|
|
|
end
|
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
context 'user has a private profile' do
|
|
|
|
before do
|
|
|
|
user.update!(private_profile: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'as same user' do
|
|
|
|
let(:current_user) { user }
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(project1, project2, private_project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'as other user' do
|
|
|
|
context 'user does not have access to view the private profile' do
|
|
|
|
let(:current_user) { other_user }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user has access to view the private profile', :enable_admin_mode do
|
|
|
|
let(:current_user) { create(:admin) }
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(project1, project2, private_project) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'as no user' do
|
|
|
|
let(:current_user) { nil }
|
2019-02-05 06:49:58 -05:00
|
|
|
|
2020-12-07 16:10:08 -05:00
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
2019-02-05 06:49:58 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|