diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-08-14 17:29:41 -0300 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-08-15 14:34:16 -0300 |
commit | 38ba59bedd8b7e2f1a4de08725d6e000bf4fde42 (patch) | |
tree | 819858b4be2bc9226a5a3738df1a4a057731621f /spec/controllers | |
parent | 903281454277805813eefd200d4279c6c4426a70 (diff) | |
download | gitlab-ce-38ba59bedd8b7e2f1a4de08725d6e000bf4fde42.tar.gz |
Fix starrers counters after searching
Diffstat (limited to 'spec/controllers')
-rw-r--r-- | spec/controllers/projects/starrers_controller_spec.rb | 152 |
1 files changed, 112 insertions, 40 deletions
diff --git a/spec/controllers/projects/starrers_controller_spec.rb b/spec/controllers/projects/starrers_controller_spec.rb index 59d258e99ce..7085cba08d5 100644 --- a/spec/controllers/projects/starrers_controller_spec.rb +++ b/spec/controllers/projects/starrers_controller_spec.rb @@ -3,23 +3,33 @@ require 'spec_helper' describe Projects::StarrersController do - let(:user) { create(:user) } - let(:private_user) { create(:user, private_profile: true) } + let(:user_1) { create(:user, name: 'John') } + let(:user_2) { create(:user, name: 'Michael') } + let(:private_user) { create(:user, name: 'Michael Douglas', private_profile: true) } let(:admin) { create(:user, admin: true) } - let(:project) { create(:project, :public, :repository) } + let(:project) { create(:project, :public) } before do - user.toggle_star(project) + user_1.toggle_star(project) + user_2.toggle_star(project) private_user.toggle_star(project) end describe 'GET index' do - def get_starrers - get :index, - params: { - namespace_id: project.namespace, - project_id: project - } + def get_starrers(search: nil) + get :index, params: { namespace_id: project.namespace, project_id: project, search: search } + end + + def user_ids + assigns[:starrers].map { |s| s['user_id'] } + end + + shared_examples 'starrers counts' do + it 'starrers counts are correct' do + expect(assigns[:total_count]).to eq(3) + expect(assigns[:public_count]).to eq(2) + expect(assigns[:private_count]).to eq(1) + end end context 'when project is public' do @@ -28,55 +38,118 @@ describe Projects::StarrersController do end context 'when no user is logged in' do + context 'with no searching' do + before do + get_starrers + end + + it 'only users with public profiles are visible' do + expect(user_ids).to contain_exactly(user_1.id, user_2.id) + end + + include_examples 'starrers counts' + end + + context 'when searching by user' do + before do + get_starrers(search: 'Michael') + end + + it 'only users with public profiles are visible' do + expect(user_ids).to contain_exactly(user_2.id) + end + + include_examples 'starrers counts' + end + end + + context 'when public user is logged in' do before do - get_starrers + sign_in(user_1) end - it 'only public starrers are visible' do - user_ids = assigns[:starrers].map { |s| s['user_id'] } - expect(user_ids).to include(user.id) - expect(user_ids).not_to include(private_user.id) + context 'with no searching' do + before do + get_starrers + end + + it 'their star is also visible' do + expect(user_ids).to contain_exactly(user_1.id, user_2.id) + end + + include_examples 'starrers counts' end - it 'public/private starrers counts are correct' do - expect(assigns[:public_count]).to eq(1) - expect(assigns[:private_count]).to eq(1) + context 'when searching by user' do + before do + get_starrers(search: 'Michael') + end + + it 'only users with public profiles are visible' do + expect(user_ids).to contain_exactly(user_2.id) + end + + include_examples 'starrers counts' end end context 'when private user is logged in' do before do sign_in(private_user) - - get_starrers end - it 'their star is also visible' do - user_ids = assigns[:starrers].map { |s| s['user_id'] } - expect(user_ids).to include(user.id, private_user.id) + context 'with no searching' do + before do + get_starrers + end + + it 'their star is also visible' do + expect(user_ids).to contain_exactly(user_1.id, user_2.id, private_user.id) + end + + include_examples 'starrers counts' end - it 'public/private starrers counts are correct' do - expect(assigns[:public_count]).to eq(1) - expect(assigns[:private_count]).to eq(1) + context 'when searching by user' do + before do + get_starrers(search: 'Michael') + end + + it 'only users with public profiles are visible' do + expect(user_ids).to contain_exactly(user_2.id, private_user.id) + end + + include_examples 'starrers counts' end end context 'when admin is logged in' do before do sign_in(admin) - - get_starrers end - it 'all stars are visible' do - user_ids = assigns[:starrers].map { |s| s['user_id'] } - expect(user_ids).to include(user.id, private_user.id) + context 'with no searching' do + before do + get_starrers + end + + it 'all users are visible' do + expect(user_ids).to include(user_1.id, user_2.id, private_user.id) + end + + include_examples 'starrers counts' end - it 'public/private starrers counts are correct' do - expect(assigns[:public_count]).to eq(1) - expect(assigns[:private_count]).to eq(1) + context 'when searching by user' do + before do + get_starrers(search: 'Michael') + end + + it 'public and private starrers are visible' do + expect(user_ids).to contain_exactly(user_2.id, private_user.id) + end + + include_examples 'starrers counts' end end end @@ -95,15 +168,14 @@ describe Projects::StarrersController do context 'when user is logged in' do before do sign_in(project.creator) - end - - it 'only public starrers are visible' do get_starrers + end - user_ids = assigns[:starrers].map { |s| s['user_id'] } - expect(user_ids).to include(user.id) - expect(user_ids).not_to include(private_user.id) + it 'only users with public profiles are visible' do + expect(user_ids).to contain_exactly(user_1.id, user_2.id) end + + include_examples 'starrers counts' end end end |