|
3 | 3 | describe IssueObserver do
|
4 | 4 | let(:some_user) { double(:user, id: 1) }
|
5 | 5 | let(:assignee) { double(:user, id: 2) }
|
6 |
| - let(:issue) { double(:issue, id: 42, assignee: assignee) } |
| 6 | + let(:author) { double(:user, id: 3) } |
| 7 | + let(:issue) { double(:issue, id: 42, assignee: assignee, author: author) } |
7 | 8 |
|
8 | 9 | before(:each) { subject.stub(:current_user).and_return(some_user) }
|
9 | 10 |
|
|
67 | 68 | end
|
68 | 69 | end
|
69 | 70 |
|
70 |
| - context 'a status "closed" note' do |
71 |
| - it 'is created if the issue is being closed' do |
| 71 | + context 'a status "closed"' do |
| 72 | + it 'note is created if the issue is being closed' do |
72 | 73 | issue.should_receive(:is_being_closed?).and_return(true)
|
73 | 74 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed')
|
74 | 75 |
|
75 | 76 | subject.after_update(issue)
|
76 | 77 | end
|
77 | 78 |
|
78 |
| - it 'is not created if the issue is not being closed' do |
| 79 | + it 'note is not created if the issue is not being closed' do |
79 | 80 | issue.should_receive(:is_being_closed?).and_return(false)
|
80 | 81 | Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed')
|
81 | 82 |
|
82 | 83 | subject.after_update(issue)
|
83 | 84 | end
|
| 85 | + |
| 86 | + it 'notification is delivered if the issue being closed' do |
| 87 | + issue.stub(:is_being_closed?).and_return(true) |
| 88 | + Notify.should_receive(:issue_status_changed_email).twice |
| 89 | + Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') |
| 90 | + |
| 91 | + subject.after_update(issue) |
| 92 | + end |
| 93 | + |
| 94 | + it 'notification is not delivered if the issue not being closed' do |
| 95 | + issue.stub(:is_being_closed?).and_return(false) |
| 96 | + Notify.should_not_receive(:issue_status_changed_email) |
| 97 | + Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed') |
| 98 | + |
| 99 | + subject.after_update(issue) |
| 100 | + end |
| 101 | + |
| 102 | + it 'notification is delivered only to author if the issue being closed' do |
| 103 | + issue_without_assignee = double(:issue, id: 42, author: author, assignee: nil) |
| 104 | + issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
| 105 | + issue_without_assignee.stub(:is_being_closed?).and_return(true) |
| 106 | + issue_without_assignee.stub(:is_being_reopened?).and_return(false) |
| 107 | + Notify.should_receive(:issue_status_changed_email).once |
| 108 | + Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'closed') |
| 109 | + |
| 110 | + subject.after_update(issue_without_assignee) |
| 111 | + end |
84 | 112 | end
|
85 | 113 |
|
86 |
| - context 'a status "reopened" note' do |
87 |
| - it 'is created if the issue is being reopened' do |
| 114 | + context 'a status "reopened"' do |
| 115 | + it 'note is created if the issue is being reopened' do |
88 | 116 | issue.should_receive(:is_being_reopened?).and_return(true)
|
89 | 117 | Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened')
|
90 | 118 |
|
91 | 119 | subject.after_update(issue)
|
92 | 120 | end
|
93 | 121 |
|
94 |
| - it 'is not created if the issue is not being reopened' do |
| 122 | + it 'note is not created if the issue is not being reopened' do |
95 | 123 | issue.should_receive(:is_being_reopened?).and_return(false)
|
96 | 124 | Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'reopened')
|
97 | 125 |
|
98 | 126 | subject.after_update(issue)
|
99 | 127 | end
|
| 128 | + |
| 129 | + it 'notification is delivered if the issue being reopened' do |
| 130 | + issue.stub(:is_being_reopened?).and_return(true) |
| 131 | + Notify.should_receive(:issue_status_changed_email).twice |
| 132 | + Note.should_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
| 133 | + |
| 134 | + subject.after_update(issue) |
| 135 | + end |
| 136 | + |
| 137 | + it 'notification is not delivered if the issue not being reopened' do |
| 138 | + issue.stub(:is_being_reopened?).and_return(false) |
| 139 | + Notify.should_not_receive(:issue_status_changed_email) |
| 140 | + Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'reopened') |
| 141 | + |
| 142 | + subject.after_update(issue) |
| 143 | + end |
| 144 | + |
| 145 | + it 'notification is delivered only to author if the issue being reopened' do |
| 146 | + issue_without_assignee = double(:issue, id: 42, author: author, assignee: nil) |
| 147 | + issue_without_assignee.stub(:is_being_reassigned?).and_return(false) |
| 148 | + issue_without_assignee.stub(:is_being_closed?).and_return(false) |
| 149 | + issue_without_assignee.stub(:is_being_reopened?).and_return(true) |
| 150 | + Notify.should_receive(:issue_status_changed_email).once |
| 151 | + Note.should_receive(:create_status_change_note).with(issue_without_assignee, some_user, 'reopened') |
| 152 | + |
| 153 | + subject.after_update(issue_without_assignee) |
| 154 | + end |
100 | 155 | end
|
101 | 156 | end
|
102 | 157 |
|
|
0 commit comments