Commit 356430c3c0e8aed3f8c9f2e181aaeaeaa4f1d693
1 parent
02924de3
Exists in
master
and in
4 other branches
Add method for an issue to know whether it is being closed
Update IssueObserver to create a Note on the issue its being closed.
Showing
4 changed files
with
55 additions
and
9 deletions
Show diff stats
app/models/issue.rb
app/models/issue_observer.rb
... | ... | @@ -7,6 +7,7 @@ class IssueObserver < ActiveRecord::Observer |
7 | 7 | |
8 | 8 | def after_change(issue) |
9 | 9 | send_reassigned_email(issue) if issue.is_being_reassigned? |
10 | + Note.create_status_change_note(issue, current_user, 'closed') if issue.is_being_closed? | |
10 | 11 | end |
11 | 12 | |
12 | 13 | def send_reassigned_email(issue) |
... | ... | @@ -16,5 +17,4 @@ class IssueObserver < ActiveRecord::Observer |
16 | 17 | Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was) |
17 | 18 | end |
18 | 19 | end |
19 | - | |
20 | 20 | end | ... | ... |
spec/models/issue_observer_spec.rb
... | ... | @@ -26,18 +26,41 @@ describe IssueObserver do |
26 | 26 | end |
27 | 27 | |
28 | 28 | context 'when an issue is changed' do |
29 | - it 'sends a reassigned email, if the issue is being reassigned' do | |
30 | - issue.should_receive(:is_being_reassigned?).and_return(true) | |
31 | - subject.should_receive(:send_reassigned_email).with(issue) | |
29 | + before(:each) do | |
30 | + issue.stub(:is_being_reassigned?).and_return(false) | |
31 | + issue.stub(:is_being_closed?).and_return(false) | |
32 | + end | |
33 | + | |
34 | + context 'a reassigned email' do | |
35 | + it 'is sent if the issue is being reassigned' do | |
36 | + issue.should_receive(:is_being_reassigned?).and_return(true) | |
37 | + subject.should_receive(:send_reassigned_email).with(issue) | |
38 | + | |
39 | + subject.after_change(issue) | |
40 | + end | |
41 | + | |
42 | + it 'is not sent if the issue is not being reassigned' do | |
43 | + issue.should_receive(:is_being_reassigned?).and_return(false) | |
44 | + subject.should_not_receive(:send_reassigned_email) | |
32 | 45 | |
33 | - subject.after_change(issue) | |
46 | + subject.after_change(issue) | |
47 | + end | |
34 | 48 | end |
35 | 49 | |
36 | - it 'does not send a reassigned email, if the issue was not reassigned' do | |
37 | - issue.should_receive(:is_being_reassigned?).and_return(false) | |
38 | - subject.should_not_receive(:send_reassigned_email) | |
50 | + context 'a status "closed" note' do | |
51 | + it 'is created if the issue is being closed' do | |
52 | + issue.should_receive(:is_being_closed?).and_return(true) | |
53 | + Note.should_receive(:create_status_change_note).with(issue, some_user, 'closed') | |
54 | + | |
55 | + subject.after_change(issue) | |
56 | + end | |
39 | 57 | |
40 | - subject.after_change(issue) | |
58 | + it 'is not created if the issue is not being closed' do | |
59 | + issue.should_receive(:is_being_closed?).and_return(false) | |
60 | + Note.should_not_receive(:create_status_change_note).with(issue, some_user, 'closed') | |
61 | + | |
62 | + subject.after_change(issue) | |
63 | + end | |
41 | 64 | end |
42 | 65 | end |
43 | 66 | ... | ... |
spec/models/issue_spec.rb
... | ... | @@ -36,6 +36,25 @@ describe Issue do |
36 | 36 | end |
37 | 37 | end |
38 | 38 | |
39 | + describe '#is_being_closed?' do | |
40 | + it 'returns true if the closed attribute has changed and is now true' do | |
41 | + subject.closed = true | |
42 | + subject.is_being_closed?.should be_true | |
43 | + end | |
44 | + it 'returns false if the closed attribute has changed and is now false' do | |
45 | + issue = Factory.create(:issue, | |
46 | + :closed => true, | |
47 | + :author => Factory(:user), | |
48 | + :assignee => Factory(:user), | |
49 | + :project => Factory.create(:project)) | |
50 | + issue.closed = false | |
51 | + issue.is_being_closed?.should be_false | |
52 | + end | |
53 | + it 'returns false if the closed attribute has not changed' do | |
54 | + subject.is_being_closed?.should be_false | |
55 | + end | |
56 | + end | |
57 | + | |
39 | 58 | describe "plus 1" do |
40 | 59 | let(:project) { Factory(:project) } |
41 | 60 | subject { | ... | ... |