Commit c7bd99b04053421726012d77f85919b1d6fc0387
1 parent
e3e8b9fc
Exists in
master
and in
4 other branches
refactor issue observer spec
Showing
2 changed files
with
16 additions
and
66 deletions
Show diff stats
spec/observers/issue_observer_spec.rb
| ... | ... | @@ -11,7 +11,9 @@ describe IssueObserver do |
| 11 | 11 | let(:closed_unassigned_issue) { create(:closed_issue, author: author) } |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - before(:each) { subject.stub(:current_user).and_return(some_user) } | |
| 14 | + before { subject.stub(:current_user).and_return(some_user) } | |
| 15 | + before { subject.stub(notification: mock('NotificationService').as_null_object) } | |
| 16 | + | |
| 15 | 17 | |
| 16 | 18 | subject { IssueObserver.instance } |
| 17 | 19 | |
| ... | ... | @@ -25,15 +27,8 @@ describe IssueObserver do |
| 25 | 27 | end |
| 26 | 28 | end |
| 27 | 29 | |
| 28 | - it 'sends an email to the assignee' do | |
| 29 | - Notify.should_receive(:new_issue_email).with(mock_issue.id) | |
| 30 | - | |
| 31 | - subject.after_create(mock_issue) | |
| 32 | - end | |
| 33 | - | |
| 34 | - it 'does not send an email to the assignee if assignee created the issue' do | |
| 35 | - subject.stub(:current_user).and_return(assignee) | |
| 36 | - Notify.should_not_receive(:new_issue_email) | |
| 30 | + it 'trigger notification to send emails' do | |
| 31 | + subject.should_receive(:notification) | |
| 37 | 32 | |
| 38 | 33 | subject.after_create(mock_issue) |
| 39 | 34 | end |
| ... | ... | @@ -47,16 +42,14 @@ describe IssueObserver do |
| 47 | 42 | assigned_issue.close |
| 48 | 43 | end |
| 49 | 44 | |
| 50 | - it 'notification is delivered if the issue being closed' do | |
| 51 | - Notify.should_receive(:issue_status_changed_email).twice | |
| 45 | + it 'trigger notification to send emails' do | |
| 46 | + subject.should_receive(:notification) | |
| 52 | 47 | |
| 53 | 48 | assigned_issue.close |
| 54 | 49 | end |
| 55 | 50 | |
| 56 | - it 'notification is delivered only to author if the issue being closed' do | |
| 57 | - Notify.should_receive(:issue_status_changed_email).once | |
| 51 | + it 'creates a note' do | |
| 58 | 52 | Note.should_receive(:create_status_change_note).with(unassigned_issue, some_user, 'closed') |
| 59 | - | |
| 60 | 53 | unassigned_issue.close |
| 61 | 54 | end |
| 62 | 55 | end |
| ... | ... | @@ -68,14 +61,13 @@ describe IssueObserver do |
| 68 | 61 | closed_assigned_issue.reopen |
| 69 | 62 | end |
| 70 | 63 | |
| 71 | - it 'notification is delivered if the issue being reopened' do | |
| 72 | - Notify.should_receive(:issue_status_changed_email).twice | |
| 64 | + it 'trigger notification to send emails' do | |
| 65 | + subject.should_receive(:notification) | |
| 73 | 66 | |
| 74 | 67 | closed_assigned_issue.reopen |
| 75 | 68 | end |
| 76 | 69 | |
| 77 | - it 'notification is delivered only to author if the issue being reopened' do | |
| 78 | - Notify.should_receive(:issue_status_changed_email).once | |
| 70 | + it 'create a note' do | |
| 79 | 71 | Note.should_receive(:create_status_change_note).with(closed_unassigned_issue, some_user, 'reopened') |
| 80 | 72 | |
| 81 | 73 | closed_unassigned_issue.reopen |
| ... | ... | @@ -98,61 +90,20 @@ describe IssueObserver do |
| 98 | 90 | end |
| 99 | 91 | end |
| 100 | 92 | |
| 101 | - context 'a reassigned email' do | |
| 102 | - it 'is sent if the issue is being reassigned' do | |
| 93 | + context 'notification' do | |
| 94 | + it 'triggered if the issue is being reassigned' do | |
| 103 | 95 | mock_issue.should_receive(:is_being_reassigned?).and_return(true) |
| 104 | - subject.should_receive(:send_reassigned_email).with(mock_issue) | |
| 96 | + subject.should_receive(:notification) | |
| 105 | 97 | |
| 106 | 98 | subject.after_update(mock_issue) |
| 107 | 99 | end |
| 108 | 100 | |
| 109 | - it 'is not sent if the issue is not being reassigned' do | |
| 101 | + it 'is not triggered if the issue is not being reassigned' do | |
| 110 | 102 | mock_issue.should_receive(:is_being_reassigned?).and_return(false) |
| 111 | - subject.should_not_receive(:send_reassigned_email) | |
| 103 | + subject.should_not_receive(:notification) | |
| 112 | 104 | |
| 113 | 105 | subject.after_update(mock_issue) |
| 114 | 106 | end |
| 115 | 107 | end |
| 116 | 108 | end |
| 117 | - | |
| 118 | - describe '#send_reassigned_email' do | |
| 119 | - let(:previous_assignee) { double(:user, id: 3) } | |
| 120 | - | |
| 121 | - before(:each) do | |
| 122 | - mock_issue.stub(:assignee_id).and_return(assignee.id) | |
| 123 | - mock_issue.stub(:assignee_id_was).and_return(previous_assignee.id) | |
| 124 | - end | |
| 125 | - | |
| 126 | - def it_sends_a_reassigned_email_to(recipient) | |
| 127 | - Notify.should_receive(:reassigned_issue_email).with(recipient, mock_issue.id, previous_assignee.id) | |
| 128 | - end | |
| 129 | - | |
| 130 | - def it_does_not_send_a_reassigned_email_to(recipient) | |
| 131 | - Notify.should_not_receive(:reassigned_issue_email).with(recipient, mock_issue.id, previous_assignee.id) | |
| 132 | - end | |
| 133 | - | |
| 134 | - it 'sends a reassigned email to the previous and current assignees' do | |
| 135 | - it_sends_a_reassigned_email_to assignee.id | |
| 136 | - it_sends_a_reassigned_email_to previous_assignee.id | |
| 137 | - | |
| 138 | - subject.send(:send_reassigned_email, mock_issue) | |
| 139 | - end | |
| 140 | - | |
| 141 | - context 'does not send an email to the user who made the reassignment' do | |
| 142 | - it 'if the user is the assignee' do | |
| 143 | - subject.stub(:current_user).and_return(assignee) | |
| 144 | - it_sends_a_reassigned_email_to previous_assignee.id | |
| 145 | - it_does_not_send_a_reassigned_email_to assignee.id | |
| 146 | - | |
| 147 | - subject.send(:send_reassigned_email, mock_issue) | |
| 148 | - end | |
| 149 | - it 'if the user is the previous assignee' do | |
| 150 | - subject.stub(:current_user).and_return(previous_assignee) | |
| 151 | - it_sends_a_reassigned_email_to assignee.id | |
| 152 | - it_does_not_send_a_reassigned_email_to previous_assignee.id | |
| 153 | - | |
| 154 | - subject.send(:send_reassigned_email, mock_issue) | |
| 155 | - end | |
| 156 | - end | |
| 157 | - end | |
| 158 | 109 | end | ... | ... |
spec/services/notification_service_spec.rb