Commit 50bc6a38e425576d75232daede21769a7e742254
Exists in
master
and in
1 other branch
Merge pull request #582 from arthurnn/remove_observer
Remove Observers
Showing
7 changed files
with
16 additions
and
25 deletions
Show diff stats
app/models/comment.rb
... | ... | @@ -5,6 +5,8 @@ class Comment |
5 | 5 | after_create :increase_counter_cache |
6 | 6 | before_destroy :decrease_counter_cache |
7 | 7 | |
8 | + after_create :deliver_email, :if => :emailable? | |
9 | + | |
8 | 10 | field :body, :type => String |
9 | 11 | index(:user_id => 1) |
10 | 12 | |
... | ... | @@ -14,6 +16,10 @@ class Comment |
14 | 16 | |
15 | 17 | validates_presence_of :body |
16 | 18 | |
19 | + def deliver_email | |
20 | + Mailer.comment_notification(self).deliver | |
21 | + end | |
22 | + | |
17 | 23 | def notification_recipients |
18 | 24 | app.notification_recipients - [user.email] |
19 | 25 | end | ... | ... |
app/models/comment_observer.rb
app/models/deploy.rb
... | ... | @@ -14,6 +14,7 @@ class Deploy |
14 | 14 | |
15 | 15 | after_create :resolve_app_errs, :if => :should_resolve_app_errs? |
16 | 16 | after_create :store_cached_attributes_on_problems |
17 | + after_create :deliver_email | |
17 | 18 | |
18 | 19 | validates_presence_of :username, :environment |
19 | 20 | |
... | ... | @@ -34,5 +35,12 @@ class Deploy |
34 | 35 | def store_cached_attributes_on_problems |
35 | 36 | Problem.where(:app_id => app.id).each(&:cache_app_attributes) |
36 | 37 | end |
38 | + | |
39 | + def deliver_email | |
40 | + if app.notify_on_deploys? && app.notification_recipients.any? | |
41 | + Mailer.deploy_notification(self).deliver | |
42 | + end | |
43 | + end | |
44 | + | |
37 | 45 | end |
38 | 46 | ... | ... |
app/models/deploy_observer.rb
config/application.rb
... | ... | @@ -29,9 +29,6 @@ module Errbit |
29 | 29 | # :all can be used as a placeholder for all plugins not explicitly named. |
30 | 30 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] |
31 | 31 | |
32 | - # Activate observers that should always be running. | |
33 | - # config.active_record.observers = :cacher, :garbage_collector, :forum_observer | |
34 | - | |
35 | 32 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. |
36 | 33 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. |
37 | 34 | # config.time_zone = 'Central Time (US & Canada)' |
... | ... | @@ -54,9 +51,6 @@ module Errbit |
54 | 51 | # IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode. |
55 | 52 | config.mongoid.preload_models = true |
56 | 53 | |
57 | - # Set up observers | |
58 | - config.mongoid.observers = :deploy_observer, :comment_observer | |
59 | - | |
60 | 54 | # Configure the default encoding used in templates for Ruby 1.9. |
61 | 55 | config.encoding = "utf-8" |
62 | 56 | ... | ... |
spec/models/comment_observer_spec.rb
spec/models/deploy_observer_spec.rb