Commit 231d9e0426b875eda9ea70baaf5dccbcdd463dab
1 parent
6074896c
Exists in
master
and in
4 other branches
Observer refactored to use StateMachine events
Showing
1 changed file
with
12 additions
and
4 deletions
Show diff stats
app/observers/activity_observer.rb
| ... | ... | @@ -20,15 +20,23 @@ class ActivityObserver < ActiveRecord::Observer |
| 20 | 20 | end |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | - def after_save(record) | |
| 24 | - if record.changed.include?("closed") && record.author_id_of_changes | |
| 23 | + def after_close(record, transition) | |
| 25 | 24 | Event.create( |
| 26 | 25 | project: record.project, |
| 27 | 26 | target_id: record.id, |
| 28 | 27 | target_type: record.class.name, |
| 29 | - action: (record.closed ? Event::CLOSED : Event::REOPENED), | |
| 28 | + action: Event::CLOSED, | |
| 29 | + author_id: record.author_id_of_changes | |
| 30 | + ) | |
| 31 | + end | |
| 32 | + | |
| 33 | + def after_reopen(record, transition) | |
| 34 | + Event.create( | |
| 35 | + project: record.project, | |
| 36 | + target_id: record.id, | |
| 37 | + target_type: record.class.name, | |
| 38 | + action: Event::REOPENED, | |
| 30 | 39 | author_id: record.author_id_of_changes |
| 31 | 40 | ) |
| 32 | - end | |
| 33 | 41 | end |
| 34 | 42 | end | ... | ... |