diff options
author | Pierre de La Morinerie <pierre@capitainetrain.com> | 2014-02-17 18:49:42 +0100 |
---|---|---|
committer | Pierre de La Morinerie <pierre@capitainetrain.com> | 2014-02-19 18:25:18 +0100 |
commit | 96dded3ec8401e9832b3888338f37c846bd43583 (patch) | |
tree | ae782ede2d7b2668c7cc659a1ebb03b086916502 /spec/mailers | |
parent | 57cb1ca7917f27f2c7500858fb66d53b3ea49783 (diff) | |
download | gitlab-ce-96dded3ec8401e9832b3888338f37c846bd43583.tar.gz |
Send emails from the author
This changes the email "From" field from "gitlab@example.com" to either:
* "John Doe <gitlab@example.com>" if the author of the action is known,
* "GitLab <gitlab@example.com>" otherwise.
Rationale: this allow mails to appear as if they were sent by the
author. It appears in the mailbox more like a real discussion between
the sender and the receiver ("John sent: we should refactor this") and
less like a robot notifying about something.
Diffstat (limited to 'spec/mailers')
-rw-r--r-- | spec/mailers/notify_spec.rb | 90 |
1 files changed, 73 insertions, 17 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index fae726b965b..26b7ca876fc 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -4,6 +4,7 @@ describe Notify do include EmailSpec::Helpers include EmailSpec::Matchers + let(:gitlab_sender) { Gitlab.config.gitlab.email_from } let(:recipient) { create(:user, email: 'recipient@example.com') } let(:project) { create(:project) } @@ -13,12 +14,22 @@ describe Notify do end end + shared_examples 'an email sent from GitLab' do + it 'is sent from GitLab' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq('GitLab') + sender.address.should eq(gitlab_sender) + end + end + describe 'for new users, the email' do let(:example_site_path) { root_path } let(:new_user) { create(:user, email: 'newguy@example.com', created_by_id: 1) } subject { Notify.new_user_email(new_user.id, new_user.password) } + it_behaves_like 'an email sent from GitLab' + it 'is sent to the new user' do should deliver_to new_user.email end @@ -47,6 +58,8 @@ describe Notify do subject { Notify.new_user_email(new_user.id, new_user.password) } + it_behaves_like 'an email sent from GitLab' + it 'is sent to the new user' do should deliver_to new_user.email end @@ -73,6 +86,8 @@ describe Notify do subject { Notify.new_ssh_key_email(key.id) } + it_behaves_like 'an email sent from GitLab' + it 'is sent to the new user' do should deliver_to key.user.email end @@ -114,17 +129,24 @@ describe Notify do context 'for a project' do describe 'items that are assignable, the email' do + let(:current_user) { create(:user, email: "current@email.com") } let(:assignee) { create(:user, email: 'assignee@example.com') } let(:previous_assignee) { create(:user, name: 'Previous Assignee') } shared_examples 'an assignee email' do + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq(current_user.name) + sender.address.should eq(gitlab_sender) + end + it 'is sent to the assignee' do should deliver_to assignee.email end end context 'for issues' do - let(:issue) { create(:issue, assignee: assignee, project: project ) } + let(:issue) { create(:issue, author: current_user, assignee: assignee, project: project ) } describe 'that are new' do subject { Notify.new_issue_email(issue.assignee_id, issue.id) } @@ -132,7 +154,7 @@ describe Notify do it_behaves_like 'an assignee email' it 'has the correct subject' do - should have_subject /#{project.name} \| New issue ##{issue.iid} \| #{issue.title}/ + should have_subject /#{project.name} \| #{issue.title} \(##{issue.iid}\)/ end it 'contains a link to the new issue' do @@ -141,14 +163,18 @@ describe Notify do end describe 'that have been reassigned' do - before(:each) { issue.stub(:assignee_id_was).and_return(previous_assignee.id) } - - subject { Notify.reassigned_issue_email(recipient.id, issue.id, previous_assignee.id) } + subject { Notify.reassigned_issue_email(recipient.id, issue.id, previous_assignee.id, current_user) } it_behaves_like 'a multiple recipients email' + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq(current_user.name) + sender.address.should eq(gitlab_sender) + end + it 'has the correct subject' do - should have_subject /Changed issue ##{issue.iid} \| #{issue.title}/ + should have_subject /#{issue.title} \(##{issue.iid}\)/ end it 'contains the name of the previous assignee' do @@ -165,12 +191,17 @@ describe Notify do end describe 'status changed' do - let(:current_user) { create(:user, email: "current@email.com") } let(:status) { 'closed' } subject { Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) } + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq(current_user.name) + sender.address.should eq(gitlab_sender) + end + it 'has the correct subject' do - should have_subject /Changed issue ##{issue.iid} \| #{issue.title}/i + should have_subject /#{issue.title} \(##{issue.iid}\)/i end it 'contains the new status' do @@ -189,7 +220,7 @@ describe Notify do end context 'for merge requests' do - let(:merge_request) { create(:merge_request, assignee: assignee, source_project: project, target_project: project) } + let(:merge_request) { create(:merge_request, author: current_user, assignee: assignee, source_project: project, target_project: project) } describe 'that are new' do subject { Notify.new_merge_request_email(merge_request.assignee_id, merge_request.id) } @@ -197,7 +228,7 @@ describe Notify do it_behaves_like 'an assignee email' it 'has the correct subject' do - should have_subject /New merge request ##{merge_request.iid}/ + should have_subject /#{merge_request.title} \(!#{merge_request.iid}\)/ end it 'contains a link to the new merge request' do @@ -214,14 +245,18 @@ describe Notify do end describe 'that are reassigned' do - before(:each) { merge_request.stub(:assignee_id_was).and_return(previous_assignee.id) } - - subject { Notify.reassigned_merge_request_email(recipient.id, merge_request.id, previous_assignee.id) } + subject { Notify.reassigned_merge_request_email(recipient.id, merge_request.id, previous_assignee.id, current_user.id) } it_behaves_like 'a multiple recipients email' + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq(current_user.name) + sender.address.should eq(gitlab_sender) + end + it 'has the correct subject' do - should have_subject /Changed merge request ##{merge_request.iid}/ + should have_subject /#{merge_request.title} \(!#{merge_request.iid}\)/ end it 'contains the name of the previous assignee' do @@ -245,6 +280,8 @@ describe Notify do let(:user) { create(:user) } subject { Notify.project_was_moved_email(project.id, user.id) } + it_behaves_like 'an email sent from GitLab' + it 'has the correct subject' do should have_subject /Project was moved/ end @@ -265,6 +302,9 @@ describe Notify do project: project, user: user) } subject { Notify.project_access_granted_email(users_project.id) } + + it_behaves_like 'an email sent from GitLab' + it 'has the correct subject' do should have_subject /Access to project was granted/ end @@ -285,6 +325,12 @@ describe Notify do end shared_examples 'a note email' do + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq(note_author.name) + sender.address.should eq(gitlab_sender) + end + it 'is sent to the given recipient' do should deliver_to recipient.email end @@ -324,7 +370,7 @@ describe Notify do it_behaves_like 'a note email' it 'has the correct subject' do - should have_subject /Note for commit #{commit.short_id}/ + should have_subject /#{commit.title} \(#{commit.short_id}\)/ end it 'contains a link to the commit' do @@ -342,7 +388,7 @@ describe Notify do it_behaves_like 'a note email' it 'has the correct subject' do - should have_subject /Note for merge request ##{merge_request.iid}/ + should have_subject /#{merge_request.title} \(!#{merge_request.iid}\)/ end it 'contains a link to the merge request note' do @@ -360,7 +406,7 @@ describe Notify do it_behaves_like 'a note email' it 'has the correct subject' do - should have_subject /Note for issue ##{issue.iid}/ + should have_subject /#{issue.title} \(##{issue.iid}\)/ end it 'contains a link to the issue note' do @@ -377,6 +423,8 @@ describe Notify do subject { Notify.group_access_granted_email(membership.id) } + it_behaves_like 'an email sent from GitLab' + it 'has the correct subject' do should have_subject /Access to group was granted/ end @@ -401,6 +449,8 @@ describe Notify do subject { ActionMailer::Base.deliveries.last } + it_behaves_like 'an email sent from GitLab' + it 'is sent to the new user' do should deliver_to 'new-email@mail.com' end @@ -421,6 +471,12 @@ describe Notify do subject { Notify.repository_push_email(project.id, 'devs@company.name', user.id, 'master', compare) } + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + sender.display_name.should eq(user.name) + sender.address.should eq(gitlab_sender) + end + it 'is sent to recipient' do should deliver_to 'devs@company.name' end |