diff options
author | Rémy Coutable <remy@rymai.me> | 2016-06-02 19:05:06 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-06-14 14:18:14 +0300 |
commit | 515205d3c1c6655302ed0ae44cc5954dead7ae79 (patch) | |
tree | 5ac24884eb0e6faf56e1e460260303fbdb14b9cf /spec/models/member_spec.rb | |
parent | 6d103a2f4764441b1650ba6d790732056c9a8516 (diff) |
UI and copywriting improvements
+ Move 'Edit Project/Group' out of membership-related partial
+ Show the access request buttons only to logged-in users
+ Put the request access buttons out of in a more visible button
+ Improve the copy in the #remove_member_message helper
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec/models/member_spec.rb')
-rw-r--r-- | spec/models/member_spec.rb | 103 |
1 files changed, 69 insertions, 34 deletions
diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index a3d525d8d56..3ed3202ac6c 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -55,45 +55,78 @@ describe Member, models: true do end end - describe 'Scopes' do + describe 'Scopes & finders' do before do project = create(:project) - @invited_member = build(:project_member, user: nil).tap { |m| m.generate_invite_token! } - @accepted_invite_member = build(:project_member, user: nil).tap { |m| m.generate_invite_token! && m.accept_invite!(build(:user)) } + group = create(:group) + @owner_user = create(:user).tap { |u| group.add_owner(u) } + @owner = group.members.find_by(user_id: @owner_user.id) + + @master_user = create(:user).tap { |u| project.team << [u, :master] } + @master = project.members.find_by(user_id: @master_user.id) + + ProjectMember.add_user(project.members, 'toto1@example.com', Gitlab::Access::DEVELOPER, @master_user) + @invited_member = project.members.invite.find_by_invite_email('toto1@example.com') + + accepted_invite_user = build(:user) + ProjectMember.add_user(project.members, 'toto2@example.com', Gitlab::Access::DEVELOPER, @master_user) + @accepted_invite_member = project.members.invite.find_by_invite_email('toto2@example.com').tap { |u| u.accept_invite!(accepted_invite_user) } requested_user = create(:user).tap { |u| project.request_access(u) } - @requested_member = project.project_members.find_by(created_by_id: requested_user.id) + @requested_member = project.members.request.find_by(user_id: requested_user.id) + accepted_request_user = create(:user).tap { |u| project.request_access(u) } - @accepted_request_member = project.project_members.find_by(created_by_id: accepted_request_user.id).tap { |m| m.accept_request } + @accepted_request_member = project.members.request.find_by(user_id: accepted_request_user.id).tap { |m| m.accept_request } end - describe '#invite' do + describe '.invite' do + it { expect(described_class.invite).not_to include @master } it { expect(described_class.invite).to include @invited_member } it { expect(described_class.invite).not_to include @accepted_invite_member } it { expect(described_class.invite).not_to include @requested_member } it { expect(described_class.invite).not_to include @accepted_request_member } end - describe '#request' do + describe '.non_invite' do + it { expect(described_class.non_invite).to include @master } + it { expect(described_class.non_invite).not_to include @invited_member } + it { expect(described_class.non_invite).to include @accepted_invite_member } + it { expect(described_class.non_invite).to include @requested_member } + it { expect(described_class.non_invite).to include @accepted_request_member } + end + + describe '.request' do + it { expect(described_class.request).not_to include @master } it { expect(described_class.request).not_to include @invited_member } it { expect(described_class.request).not_to include @accepted_invite_member } it { expect(described_class.request).to include @requested_member } it { expect(described_class.request).not_to include @accepted_request_member } end - describe '#non_request' do + describe '.non_request' do + it { expect(described_class.non_request).to include @master } it { expect(described_class.non_request).to include @invited_member } it { expect(described_class.non_request).to include @accepted_invite_member } it { expect(described_class.non_request).not_to include @requested_member } it { expect(described_class.non_request).to include @accepted_request_member } end - describe '#non_pending' do + describe '.non_pending' do + it { expect(described_class.non_pending).to include @master } it { expect(described_class.non_pending).not_to include @invited_member } it { expect(described_class.non_pending).to include @accepted_invite_member } it { expect(described_class.non_pending).not_to include @requested_member } it { expect(described_class.non_pending).to include @accepted_request_member } end + + describe '.owners_and_masters' do + it { expect(described_class.owners_and_masters).to include @owner } + it { expect(described_class.owners_and_masters).to include @master } + it { expect(described_class.owners_and_masters).not_to include @invited_member } + it { expect(described_class.owners_and_masters).not_to include @accepted_invite_member } + it { expect(described_class.owners_and_masters).not_to include @requested_member } + it { expect(described_class.owners_and_masters).not_to include @accepted_request_member } + end end describe "Delegate methods" do @@ -101,6 +134,18 @@ describe Member, models: true do it { is_expected.to respond_to(:user_email) } end + describe 'Callbacks' do + describe 'after_destroy :post_decline_request, if: :request?' do + let(:member) { create(:project_member, requested_at: Time.now.utc) } + + it 'calls #post_decline_request' do + expect(member).to receive(:post_decline_request) + + member.destroy + end + end + end + describe ".add_user" do let!(:user) { create(:user) } let(:project) { create(:project) } @@ -139,18 +184,9 @@ describe Member, models: true do end describe '#accept_request' do - let(:user) { create(:user) } - let(:member) { create(:project_member, requested_at: Time.now.utc, user: nil, created_by: user) } - - it 'returns true' do - expect(member.accept_request).to be_truthy - end + let(:member) { create(:project_member, requested_at: Time.now.utc) } - it 'sets the user' do - member.accept_request - - expect(member.user).to eq(user) - end + it { expect(member.accept_request).to be_truthy } it 'clears requested_at' do member.accept_request @@ -165,25 +201,24 @@ describe Member, models: true do end end - describe '#decline_request' do - let(:user) { create(:user) } - let(:member) { create(:project_member, requested_at: Time.now.utc, user: nil, created_by: user) } + describe '#invite?' do + subject { create(:project_member, invite_email: "user@example.com", user: nil) } - it 'returns true' do - expect(member.decline_request).to be_truthy - end + it { is_expected.to be_invite } + end - it 'destroys the member' do - member.decline_request + describe '#request?' do + subject { create(:project_member, requested_at: Time.now.utc) } - expect(member).to be_destroyed - end + it { is_expected.to be_request } + end - it 'calls #after_decline_request' do - expect(member).to receive(:after_decline_request) + describe '#pending?' do + let(:invited_member) { create(:project_member, invite_email: "user@example.com", user: nil) } + let(:requester) { create(:project_member, requested_at: Time.now.utc) } - member.decline_request - end + it { expect(invited_member).to be_invite } + it { expect(requester).to be_pending } end describe "#accept_invite!" do |