Commit 231d9e0426b875eda9ea70baaf5dccbcdd463dab

Authored by Andrew8xx8
1 parent 6074896c

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,15 +20,23 @@ class ActivityObserver < ActiveRecord::Observer
20 end 20 end
21 end 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 Event.create( 24 Event.create(
26 project: record.project, 25 project: record.project,
27 target_id: record.id, 26 target_id: record.id,
28 target_type: record.class.name, 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 author_id: record.author_id_of_changes 39 author_id: record.author_id_of_changes
31 ) 40 )
32 - end  
33 end 41 end
34 end 42 end