diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-08-31 00:51:31 -0700 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-08-31 00:51:31 -0700 |
commit | ed954ebae24b5f7308e6f5e7250320342f3d9a41 (patch) | |
tree | d0e8bb0992aadc9b57b9c4af6acb00951af4cd19 /spec | |
parent | 65abd8b20ab047016e2fc30e5cd1edf5bf4554ea (diff) | |
parent | 2703fe3e72f0084139a76c5a8332f9402cae0cf1 (diff) | |
download | gitlab-ce-ed954ebae24b5f7308e6f5e7250320342f3d9a41.tar.gz |
Merge pull request #1326 from AlexDenisov/issue_status_changed_notifications
Issue status changed notifications
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mailers/notify_spec.rb | 23 | ||||
-rw-r--r-- | spec/observers/issue_observer_spec.rb | 69 |
2 files changed, 85 insertions, 7 deletions
diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index 60f3231ce91..cf50b429f23 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -91,6 +91,29 @@ describe Notify do should have_body_text /#{project_issue_path project, issue}/ end end + + describe 'status changed' do + let(:current_user) { Factory.create :user, email: "current@email.com" } + let(:status) { 'closed' } + subject { Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user) } + + it 'has the correct subject' do + should have_subject /changed issue ##{issue.id} \| #{issue.title}/i + end + + it 'contains the new status' do + should have_body_text /#{status}/i + end + + it 'contains the user name' do + should have_body_text /#{current_user.name}/i + end + + it 'contains a link to the issue' do + should have_body_text /#{project_issue_path project, issue}/ + end + end + end context 'for merge requests' do diff --git a/spec/observers/issue_observer_spec.rb b/spec/observers/issue_observer_spec.rb index c6a405f1c1b..b5943f2c539 100644 --- a/spec/observers/issue_observer_spec.rb +++ b/spec/observers/issue_observer_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' describe IssueObserver do let(:some_user) { double(:user, id: 1) } let(:assignee) { double(:user, id: 2) } - let(:issue) { double(:issue, id: 42, assignee: assignee) } + let(:author) { double(:user, id: 3) } + let(:issue) { double(:issue, id: 42, assignee: assignee, author: author) } before(:each) { subject.stub(:current_user).and_return(some_user) } @@ -67,36 +68,90 @@ describe IssueObserver do end end - context 'a status "closed" note' do - it 'is created if the issue is being closed' do + context 'a status "closed"' do + it 'note is created if the issue is being closed' do issue.should_receive(:is_being_closed?).and_return(true) Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') subject.after_update(issue) end - it 'is not created if the issue is not being closed' do + it 'note is not created if the issue is not being closed' do issue.should_receive(:is_being_closed?).and_return(false) Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed') subject.after_update(issue) end + + it 'notification is delivered if the issue being closed' do + issue.stub(:is_being_closed?).and_return(true) + Notify.should_receive(:issue_status_changed_email).twice + Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') + + subject.after_update(issue) + end + + it 'notification is not delivered if the issue not being closed' do + issue.stub(:is_being_closed?).and_return(false) + Notify.should_not_receive(:issue_status_changed_email) + Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed') + + subject.after_update(issue) + end + + it 'notification is delivered only to author if the issue being closed' do + issue_without_assignee = double(:issue, id: 42, author: author, assignee: nil) + issue_without_assignee.stub(:is_being_reassigned?).and_return(false) + issue_without_assignee.stub(:is_being_closed?).and_return(true) + issue_without_assignee.stub(:is_being_reopened?).and_return(false) + Notify.should_receive(:issue_status_changed_email).once + Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed') + + subject.after_update(issue_without_assignee) + end end - context 'a status "reopened" note' do - it 'is created if the issue is being reopened' do + context 'a status "reopened"' do + it 'note is created if the issue is being reopened' do issue.should_receive(:is_being_reopened?).and_return(true) Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') subject.after_update(issue) end - it 'is not created if the issue is not being reopened' do + it 'note is not created if the issue is not being reopened' do issue.should_receive(:is_being_reopened?).and_return(false) Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'reopened') subject.after_update(issue) end + + it 'notification is delivered if the issue being reopened' do + issue.stub(:is_being_reopened?).and_return(true) + Notify.should_receive(:issue_status_changed_email).twice + Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') + + subject.after_update(issue) + end + + it 'notification is not delivered if the issue not being reopened' do + issue.stub(:is_being_reopened?).and_return(false) + Notify.should_not_receive(:issue_status_changed_email) + Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'reopened') + + subject.after_update(issue) + end + + it 'notification is delivered only to author if the issue being reopened' do + issue_without_assignee = double(:issue, id: 42, author: author, assignee: nil) + issue_without_assignee.stub(:is_being_reassigned?).and_return(false) + issue_without_assignee.stub(:is_being_closed?).and_return(false) + issue_without_assignee.stub(:is_being_reopened?).and_return(true) + Notify.should_receive(:issue_status_changed_email).once + Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened') + + subject.after_update(issue_without_assignee) + end end end |