BigW Consortium Gitlab

members_helper_spec.rb 3.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
require 'spec_helper'

describe MembersHelper do
  describe '#action_member_permission' do
    let(:project_member) { build(:project_member) }
    let(:group_member) { build(:group_member) }

    it { expect(action_member_permission(:admin, project_member)).to eq :admin_project_member }
    it { expect(action_member_permission(:admin, group_member)).to eq :admin_group_member }
  end

  describe '#remove_member_message' do
13
    let(:requester) { create(:user) }
14
    let(:project) { create(:project, :public, :access_requestable) }
15 16 17
    let(:project_member) { build(:project_member, project: project) }
    let(:project_member_invite) { build(:project_member, project: project).tap { |m| m.generate_invite_token! } }
    let(:project_member_request) { project.request_access(requester) }
18
    let(:group) { create(:group, :access_requestable) }
19 20 21 22
    let(:group_member) { build(:group_member, group: group) }
    let(:group_member_invite) { build(:group_member, group: group).tap { |m| m.generate_invite_token! } }
    let(:group_member_request) { group.request_access(requester) }

23 24 25 26 27 28 29 30
    it { expect(remove_member_message(project_member)).to eq "Are you sure you want to remove #{project_member.user.name} from the #{project.name_with_namespace} project?" }
    it { expect(remove_member_message(project_member_invite)).to eq "Are you sure you want to revoke the invitation for #{project_member_invite.invite_email} to join the #{project.name_with_namespace} project?" }
    it { expect(remove_member_message(project_member_request)).to eq "Are you sure you want to deny #{requester.name}'s request to join the #{project.name_with_namespace} project?" }
    it { expect(remove_member_message(project_member_request, user: requester)).to eq "Are you sure you want to withdraw your access request for the #{project.name_with_namespace} project?" }
    it { expect(remove_member_message(group_member)).to eq "Are you sure you want to remove #{group_member.user.name} from the #{group.name} group?" }
    it { expect(remove_member_message(group_member_invite)).to eq "Are you sure you want to revoke the invitation for #{group_member_invite.invite_email} to join the #{group.name} group?" }
    it { expect(remove_member_message(group_member_request)).to eq "Are you sure you want to deny #{requester.name}'s request to join the #{group.name} group?" }
    it { expect(remove_member_message(group_member_request, user: requester)).to eq "Are you sure you want to withdraw your access request for the #{group.name} group?" }
31 32 33
  end

  describe '#remove_member_title' do
34
    let(:requester) { create(:user) }
35
    let(:project) { create(:project, :public, :access_requestable) }
36 37
    let(:project_member) { build(:project_member, project: project) }
    let(:project_member_request) { project.request_access(requester) }
38
    let(:group) { create(:group, :access_requestable) }
39 40 41
    let(:group_member) { build(:group_member, group: group) }
    let(:group_member_request) { group.request_access(requester) }

42 43 44 45
    it { expect(remove_member_title(project_member)).to eq 'Remove user from project' }
    it { expect(remove_member_title(project_member_request)).to eq 'Deny access request from project' }
    it { expect(remove_member_title(group_member)).to eq 'Remove user from group' }
    it { expect(remove_member_title(group_member_request)).to eq 'Deny access request from group' }
46 47 48
  end

  describe '#leave_confirmation_message' do
49
    let(:project) { build_stubbed(:project) }
50 51 52
    let(:group) { build_stubbed(:group) }
    let(:user) { build_stubbed(:user) }

53 54
    it { expect(leave_confirmation_message(project)).to eq "Are you sure you want to leave the \"#{project.name_with_namespace}\" project?" }
    it { expect(leave_confirmation_message(group)).to eq "Are you sure you want to leave the \"#{group.name}\" group?" }
55 56
  end
end