Commit 1c41a8fda4d20b78f3a27212900209844820bdc9
1 parent
f53baa7c
Exists in
master
and in
1 other branch
Remove Obeservers
Rails 4 and Mongoid 4 dont have Observers anymore, so we should remove them to make easier future migrations
Showing
7 changed files
with
16 additions
and
25 deletions
Show diff stats
app/models/comment.rb
@@ -5,6 +5,8 @@ class Comment | @@ -5,6 +5,8 @@ class Comment | ||
5 | after_create :increase_counter_cache | 5 | after_create :increase_counter_cache |
6 | before_destroy :decrease_counter_cache | 6 | before_destroy :decrease_counter_cache |
7 | 7 | ||
8 | + after_create :deliver_email, :if => :emailable? | ||
9 | + | ||
8 | field :body, :type => String | 10 | field :body, :type => String |
9 | index(:user_id => 1) | 11 | index(:user_id => 1) |
10 | 12 | ||
@@ -14,6 +16,10 @@ class Comment | @@ -14,6 +16,10 @@ class Comment | ||
14 | 16 | ||
15 | validates_presence_of :body | 17 | validates_presence_of :body |
16 | 18 | ||
19 | + def deliver_email | ||
20 | + Mailer.comment_notification(self).deliver | ||
21 | + end | ||
22 | + | ||
17 | def notification_recipients | 23 | def notification_recipients |
18 | app.notification_recipients - [user.email] | 24 | app.notification_recipients - [user.email] |
19 | end | 25 | end |
app/models/comment_observer.rb
app/models/deploy.rb
@@ -14,6 +14,7 @@ class Deploy | @@ -14,6 +14,7 @@ class Deploy | ||
14 | 14 | ||
15 | after_create :resolve_app_errs, :if => :should_resolve_app_errs? | 15 | after_create :resolve_app_errs, :if => :should_resolve_app_errs? |
16 | after_create :store_cached_attributes_on_problems | 16 | after_create :store_cached_attributes_on_problems |
17 | + after_create :deliver_email | ||
17 | 18 | ||
18 | validates_presence_of :username, :environment | 19 | validates_presence_of :username, :environment |
19 | 20 | ||
@@ -34,5 +35,12 @@ class Deploy | @@ -34,5 +35,12 @@ class Deploy | ||
34 | def store_cached_attributes_on_problems | 35 | def store_cached_attributes_on_problems |
35 | Problem.where(:app_id => app.id).each(&:cache_app_attributes) | 36 | Problem.where(:app_id => app.id).each(&:cache_app_attributes) |
36 | end | 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 | end | 45 | end |
38 | 46 |
app/models/deploy_observer.rb
config/application.rb
@@ -29,9 +29,6 @@ module Errbit | @@ -29,9 +29,6 @@ module Errbit | ||
29 | # :all can be used as a placeholder for all plugins not explicitly named. | 29 | # :all can be used as a placeholder for all plugins not explicitly named. |
30 | # config.plugins = [ :exception_notification, :ssl_requirement, :all ] | 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 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. | 32 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. |
36 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. | 33 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. |
37 | # config.time_zone = 'Central Time (US & Canada)' | 34 | # config.time_zone = 'Central Time (US & Canada)' |
@@ -54,9 +51,6 @@ module Errbit | @@ -54,9 +51,6 @@ module Errbit | ||
54 | # IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode. | 51 | # IssueTracker subclasses use inheritance, so preloading models provides querying consistency in dev mode. |
55 | config.mongoid.preload_models = true | 52 | config.mongoid.preload_models = true |
56 | 53 | ||
57 | - # Set up observers | ||
58 | - config.mongoid.observers = :deploy_observer, :comment_observer | ||
59 | - | ||
60 | # Configure the default encoding used in templates for Ruby 1.9. | 54 | # Configure the default encoding used in templates for Ruby 1.9. |
61 | config.encoding = "utf-8" | 55 | config.encoding = "utf-8" |
62 | 56 |
spec/models/comment_observer_spec.rb
spec/models/deploy_observer_spec.rb
1 | require 'spec_helper' | 1 | require 'spec_helper' |
2 | 2 | ||
3 | -describe DeployObserver do | 3 | +describe "Callback on Deploy" do |
4 | context 'when a Deploy is saved' do | 4 | context 'when a Deploy is saved' do |
5 | context 'and the app should notify on deploys' do | 5 | context 'and the app should notify on deploys' do |
6 | it 'should send an email notification' do | 6 | it 'should send an email notification' do |