summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-06-02 16:14:02 +0200
committerRémy Coutable <remy@rymai.me>2016-06-14 13:07:26 +0200
commit6d103a2f4764441b1650ba6d790732056c9a8516 (patch)
tree127216b5b120e88a53f7def0da28658f2150b682 /spec
parentd75edf1a9854b2ab609c7d3acf5eee1ca89e8db9 (diff)
downloadgitlab-ce-6d103a2f4764441b1650ba6d790732056c9a8516.tar.gz
Factorize members mails into a new Emails::Members module
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'spec')
-rw-r--r--spec/mailers/notify_spec.rb256
1 files changed, 179 insertions, 77 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb
index 2d86038030e..a86ec865b5d 100644
--- a/spec/mailers/notify_spec.rb
+++ b/spec/mailers/notify_spec.rb
@@ -407,23 +407,16 @@ describe Notify do
project.request_access(user)
project.project_members.find_by(created_by_id: user.id)
end
- subject { Notify.project_access_requested_email(project_member.id) }
+ subject { Notify.member_access_requested_email('project', project_member.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
- it 'has the correct subject' do
- is_expected.to have_subject /Request to join #{project.name_with_namespace} project/
- end
-
- it 'contains name of project' do
- is_expected.to have_body_text /#{project.name}/
- end
-
- it 'contains new user role' do
- is_expected.to have_body_text /#{project_member.human_access}/
- end
+ it { is_expected.to have_subject "Request to join the #{project.name_with_namespace} project" }
+ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
+ it { is_expected.to have_body_text /#{project.web_url}/ }
+ it { is_expected.to have_body_text /#{project_member.human_access}/ }
end
describe 'project access denied' do
@@ -433,42 +426,99 @@ describe Notify do
project.request_access(user)
project.project_members.find_by(created_by_id: user.id)
end
- subject { Notify.project_access_denied_email(project.id, user.id) }
+ subject { Notify.member_access_denied_email('project', project.id, user.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
- it 'has the correct subject' do
- is_expected.to have_subject /Access to #{project.name_with_namespace} project was denied/
- end
-
- it 'contains name of project' do
- is_expected.to have_body_text /#{project.name}/
- end
+ it { is_expected.to have_subject "Access to the #{project.name_with_namespace} project was denied" }
+ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
+ it { is_expected.to have_body_text /#{project.web_url}/ }
end
describe 'project access changed' do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:project_member) { create(:project_member, project: project, user: user) }
- subject { Notify.project_access_granted_email(project_member.id) }
+ subject { Notify.member_access_granted_email('project', project_member.id) }
it_behaves_like 'an email sent from GitLab'
it_behaves_like 'it should not have Gmail Actions links'
it_behaves_like "a user cannot unsubscribe through footer link"
- it 'has the correct subject' do
- is_expected.to have_subject /Access to #{project.name_with_namespace} project was granted/
- end
+ it { is_expected.to have_subject "Access to the #{project.name_with_namespace} project was granted" }
+ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
+ it { is_expected.to have_body_text /#{project.web_url}/ }
+ it { is_expected.to have_body_text /#{project_member.human_access}/ }
+ end
- it 'contains name of project' do
- is_expected.to have_body_text /#{project.name}/
+ def invite_to_project(project:, email:, inviter:)
+ ProjectMember.add_user(project.project_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter)
+
+ project.project_members.invite.last
+ end
+
+ describe 'project invitation' do
+ let(:project) { create(:project) }
+ let(:master) { create(:user).tap { |u| project.team << [u, :master] } }
+ let(:project_member) { invite_to_project(project: project, email: 'toto@example.com', inviter: master) }
+
+ subject { Notify.member_invited_email('project', project_member.id, project_member.invite_token) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ it { is_expected.to have_subject "Invitation to join the #{project.name_with_namespace} project" }
+ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
+ it { is_expected.to have_body_text /#{project.web_url}/ }
+ it { is_expected.to have_body_text /#{project_member.human_access}/ }
+ it { is_expected.to have_body_text /#{project_member.invite_token}/ }
+ end
+
+ describe 'project invitation accepted' do
+ let(:project) { create(:project) }
+ let(:invited_user) { create(:user) }
+ let(:master) { create(:user).tap { |u| project.team << [u, :master] } }
+ let(:project_member) do
+ invitee = invite_to_project(project: project, email: 'toto@example.com', inviter: master)
+ invitee.accept_invite!(invited_user)
+ invitee
end
- it 'contains new user role' do
- is_expected.to have_body_text /#{project_member.human_access}/
+ subject { Notify.member_invite_accepted_email('project', project_member.id) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ it { is_expected.to have_subject 'Invitation accepted' }
+ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
+ it { is_expected.to have_body_text /#{project.web_url}/ }
+ it { is_expected.to have_body_text /#{project_member.invite_email}/ }
+ it { is_expected.to have_body_text /#{invited_user.name}/ }
+ end
+
+ describe 'project invitation declined' do
+ let(:project) { create(:project) }
+ let(:master) { create(:user).tap { |u| project.team << [u, :master] } }
+ let(:project_member) do
+ invitee = invite_to_project(project: project, email: 'toto@example.com', inviter: master)
+ invitee.decline_invite!
+ invitee
end
+
+ subject { Notify.member_invite_declined_email('project', project.id, project_member.invite_email, master.id) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ it { is_expected.to have_subject 'Invitation declined' }
+ it { is_expected.to have_body_text /#{project.name_with_namespace}/ }
+ it { is_expected.to have_body_text /#{project.web_url}/ }
+ it { is_expected.to have_body_text /#{project_member.invite_email}/ }
end
context 'items that are noteable, the email for a note' do
@@ -583,75 +633,127 @@ describe Notify do
end
end
- describe 'group access requested' do
- let(:group) { create(:group) }
- let(:user) { create(:user) }
- let(:group_member) do
- group.request_access(user)
- group.group_members.find_by(created_by_id: user.id)
- end
- subject { Notify.group_access_requested_email(group_member.id) }
+ context 'for a group' do
+ describe 'group access requested' do
+ let(:group) { create(:group) }
+ let(:user) { create(:user) }
+ let(:group_member) do
+ group.request_access(user)
+ group.group_members.find_by(created_by_id: user.id)
+ end
+ subject { Notify.member_access_requested_email('group', group_member.id) }
- it_behaves_like 'an email sent from GitLab'
- it_behaves_like 'it should not have Gmail Actions links'
- it_behaves_like "a user cannot unsubscribe through footer link"
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
- it 'has the correct subject' do
- is_expected.to have_subject /Request to join #{group.name} group/
+ it { is_expected.to have_subject "Request to join the #{group.name} group" }
+ it { is_expected.to have_body_text /#{group.name}/ }
+ it { is_expected.to have_body_text /#{group.web_url}/ }
+ it { is_expected.to have_body_text /#{group_member.human_access}/ }
end
- it 'contains name of group' do
- is_expected.to have_body_text /#{group.name}/
- end
+ describe 'group access denied' do
+ let(:group) { create(:group) }
+ let(:user) { create(:user) }
+ let(:group_member) do
+ group.request_access(user)
+ group.group_members.find_by(created_by_id: user.id)
+ end
+ subject { Notify.member_access_denied_email('group', group.id, user.id) }
- it 'contains new user role' do
- is_expected.to have_body_text /#{group_member.human_access}/
- end
- end
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
- describe 'group access denied' do
- let(:group) { create(:group) }
- let(:user) { create(:user) }
- let(:group_member) do
- group.request_access(user)
- group.group_members.find_by(created_by_id: user.id)
+ it { is_expected.to have_subject "Access to the #{group.name} group was denied" }
+ it { is_expected.to have_body_text /#{group.name}/ }
+ it { is_expected.to have_body_text /#{group.web_url}/ }
end
- subject { Notify.group_access_denied_email(group.id, user.id) }
- it_behaves_like 'an email sent from GitLab'
- it_behaves_like 'it should not have Gmail Actions links'
- it_behaves_like "a user cannot unsubscribe through footer link"
+ describe 'group access changed' do
+ let(:group) { create(:group) }
+ let(:user) { create(:user) }
+ let(:group_member) { create(:group_member, group: group, user: user) }
- it 'has the correct subject' do
- is_expected.to have_subject /Access to #{group.name} group was denied/
+ subject { Notify.member_access_granted_email('group', group_member.id) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ it { is_expected.to have_subject "Access to the #{group.name} group was granted" }
+ it { is_expected.to have_body_text /#{group.name}/ }
+ it { is_expected.to have_body_text /#{group.web_url}/ }
+ it { is_expected.to have_body_text /#{group_member.human_access}/ }
end
- it 'contains name of group' do
- is_expected.to have_body_text /#{group.name}/
+ def invite_to_group(group:, email:, inviter:)
+ GroupMember.add_user(group.group_members, 'toto@example.com', Gitlab::Access::DEVELOPER, inviter)
+
+ group.group_members.invite.last
end
- end
- describe 'group access changed' do
- let(:group) { create(:group) }
- let(:user) { create(:user) }
- let(:membership) { create(:group_member, group: group, user: user) }
+ describe 'group invitation' do
+ let(:group) { create(:group) }
+ let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
+ let(:group_member) { invite_to_group(group: group, email: 'toto@example.com', inviter: owner) }
- subject { Notify.group_access_granted_email(membership.id) }
+ subject { Notify.member_invited_email('group', group_member.id, group_member.invite_token) }
- it_behaves_like 'an email sent from GitLab'
- it_behaves_like 'it should not have Gmail Actions links'
- it_behaves_like "a user cannot unsubscribe through footer link"
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
- it 'has the correct subject' do
- is_expected.to have_subject /Access to #{group.name} group was granted/
+ it { is_expected.to have_subject "Invitation to join the #{group.name} group" }
+ it { is_expected.to have_body_text /#{group.name}/ }
+ it { is_expected.to have_body_text /#{group.web_url}/ }
+ it { is_expected.to have_body_text /#{group_member.human_access}/ }
+ it { is_expected.to have_body_text /#{group_member.invite_token}/ }
end
- it 'contains name of project' do
- is_expected.to have_body_text /#{group.name}/
+ describe 'group invitation accepted' do
+ let(:group) { create(:group) }
+ let(:invited_user) { create(:user) }
+ let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
+ let(:group_member) do
+ invitee = invite_to_group(group: group, email: 'toto@example.com', inviter: owner)
+ invitee.accept_invite!(invited_user)
+ invitee
+ end
+
+ subject { Notify.member_invite_accepted_email('group', group_member.id) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ it { is_expected.to have_subject 'Invitation accepted' }
+ it { is_expected.to have_body_text /#{group.name}/ }
+ it { is_expected.to have_body_text /#{group.web_url}/ }
+ it { is_expected.to have_body_text /#{group_member.invite_email}/ }
+ it { is_expected.to have_body_text /#{invited_user.name}/ }
end
- it 'contains new user role' do
- is_expected.to have_body_text /#{membership.human_access}/
+ describe 'group invitation declined' do
+ let(:group) { create(:group) }
+ let(:owner) { create(:user).tap { |u| group.add_user(u, Gitlab::Access::OWNER) } }
+ let(:group_member) do
+ invitee = invite_to_group(group: group, email: 'toto@example.com', inviter: owner)
+ invitee.decline_invite!
+ invitee
+ end
+
+ subject { Notify.member_invite_declined_email('group', group.id, group_member.invite_email, owner.id) }
+
+ it_behaves_like 'an email sent from GitLab'
+ it_behaves_like 'it should not have Gmail Actions links'
+ it_behaves_like "a user cannot unsubscribe through footer link"
+
+ it { is_expected.to have_subject 'Invitation declined' }
+ it { is_expected.to have_body_text /#{group.name}/ }
+ it { is_expected.to have_body_text /#{group.web_url}/ }
+ it { is_expected.to have_body_text /#{group_member.invite_email}/ }
end
end