Commit 02924de3e1555bcd89097353ffb7eb552113b42e
1 parent
00ec81ea
Exists in
master
and in
4 other branches
Add method to Note to create notes about status changes.
Showing
2 changed files
with
27 additions
and
0 deletions
Show diff stats
app/models/note.rb
| @@ -42,6 +42,14 @@ class Note < ActiveRecord::Base | @@ -42,6 +42,14 @@ class Note < ActiveRecord::Base | ||
| 42 | 42 | ||
| 43 | mount_uploader :attachment, AttachmentUploader | 43 | mount_uploader :attachment, AttachmentUploader |
| 44 | 44 | ||
| 45 | + def self.create_status_change_note(noteable, author, status) | ||
| 46 | + create({ :noteable => noteable, | ||
| 47 | + :project => noteable.project, | ||
| 48 | + :author => author, | ||
| 49 | + :note => "_Status changed to #{status}_" }, | ||
| 50 | + :without_protection => true) | ||
| 51 | + end | ||
| 52 | + | ||
| 45 | def notify | 53 | def notify |
| 46 | @notify ||= false | 54 | @notify ||= false |
| 47 | end | 55 | end |
spec/models/note_spec.rb
| @@ -70,6 +70,25 @@ describe Note do | @@ -70,6 +70,25 @@ describe Note do | ||
| 70 | end | 70 | end |
| 71 | end | 71 | end |
| 72 | 72 | ||
| 73 | + describe '#create_status_change_note' do | ||
| 74 | + let(:project) { Factory.create(:project) } | ||
| 75 | + let(:thing) { Factory.create(:issue, :project => project) } | ||
| 76 | + let(:author) { Factory(:user) } | ||
| 77 | + let(:status) { 'new_status' } | ||
| 78 | + | ||
| 79 | + subject { Note.create_status_change_note(thing, author, status) } | ||
| 80 | + | ||
| 81 | + it 'creates and saves a Note' do | ||
| 82 | + should be_a Note | ||
| 83 | + subject.id.should_not be_nil | ||
| 84 | + end | ||
| 85 | + | ||
| 86 | + its(:noteable) { should == thing } | ||
| 87 | + its(:project) { should == thing.project } | ||
| 88 | + its(:author) { should == author } | ||
| 89 | + its(:note) { should =~ /Status changed to #{status}/ } | ||
| 90 | + end | ||
| 91 | + | ||
| 73 | describe :authorization do | 92 | describe :authorization do |
| 74 | before do | 93 | before do |
| 75 | @p1 = project | 94 | @p1 = project |