diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-09-05 19:03:24 +0300 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2017-09-05 23:54:07 +0300 |
commit | 66cfb901c0df6eb5741721e901b66fbe82e183ce (patch) | |
tree | 89010ac7169b33eaae719fca19cc695eb7999a9d /spec/models/group_spec.rb | |
parent | b8b4993805c620f6c29f3189b6e151c47854c5b7 (diff) |
Optimize SQL queries used in Groups::GroupMembersController#create
The following optimizations were performed:
- Add new association to GroupMember and ProjectMember
This new association will allow us to check if a user is a member of a
Project or Group through a single query instead of two.
- Optimize retrieving of Members when adding multiple Users
Diffstat (limited to 'spec/models/group_spec.rb')
-rw-r--r-- | spec/models/group_spec.rb | 19 |
1 files changed, 3 insertions, 16 deletions
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index f9cd12c0ff3..f36d6eeb327 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -9,6 +9,7 @@ describe Group do it { is_expected.to have_many(:users).through(:group_members) } it { is_expected.to have_many(:owners).through(:group_members) } it { is_expected.to have_many(:requesters).dependent(:destroy) } + it { is_expected.to have_many(:members_and_requesters) } it { is_expected.to have_many(:project_group_links).dependent(:destroy) } it { is_expected.to have_many(:shared_projects).through(:project_group_links) } it { is_expected.to have_many(:notification_settings).dependent(:destroy) } @@ -25,22 +26,8 @@ describe Group do group.add_developer(developer) end - describe '#members' do - it 'includes members and exclude requesters' do - member_user_ids = group.members.pluck(:user_id) - - expect(member_user_ids).to include(developer.id) - expect(member_user_ids).not_to include(requester.id) - end - end - - describe '#requesters' do - it 'does not include requesters' do - requester_user_ids = group.requesters.pluck(:user_id) - - expect(requester_user_ids).to include(requester.id) - expect(requester_user_ids).not_to include(developer.id) - end + it_behaves_like 'members and requesters associations' do + let(:namespace) { group } end end end |