aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafael.franca@plataformatec.com.br>2015-02-19 09:08:10 -0200
committerRafael Mendonça França <rafael.franca@plataformatec.com.br>2015-02-19 09:08:51 -0200
commite28721baf275891ab8cb4e91e33877d52f5f26e8 (patch)
tree5419e4858b8b5b25edd16b6af561162c96485b10 /activerecord
parent41b9730c6d033ea7f38fae4d18347c5370ff7b6c (diff)
downloadrails-e28721baf275891ab8cb4e91e33877d52f5f26e8.tar.gz
rails-e28721baf275891ab8cb4e91e33877d52f5f26e8.tar.bz2
rails-e28721baf275891ab8cb4e91e33877d52f5f26e8.zip
Copy edit the suppressor documentation
[ci skip]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md26
-rw-r--r--activerecord/lib/active_record/suppressor.rb30
-rw-r--r--activerecord/test/cases/suppressor_test.rb1
3 files changed, 28 insertions, 29 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index e52c142dc2..57d135d1aa 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,29 +1,29 @@
-* Add ActiveRecord::Base.suppress to prevent the receiver from being saved
+* Add `ActiveRecord::Base.suppress` to prevent the receiver from being saved
during the given block.
For example, here's a pattern of creating notifications when new comments
are posted. (The notification may in turn trigger an email, a push
notification, or just appear in the UI somewhere):
- class Comment < ActiveRecord::Base
- belongs_to :commentable, polymorphic: true
- after_create -> { Notification.create! comment: self,
- recipients: commentable.recipients }
- end
+ class Comment < ActiveRecord::Base
+ belongs_to :commentable, polymorphic: true
+ after_create -> { Notification.create! comment: self,
+ recipients: commentable.recipients }
+ end
That's what you want the bulk of the time. New comment creates a new
Notification. But there may well be off cases, like copying a commentable
and its comments, where you don't want that. So you'd have a concern
something like this:
- module Copyable
- def copy_to(destination)
- Notification.suppress do
- # Copy logic that creates new comments that we do not want triggering
- # notifications.
+ module Copyable
+ def copy_to(destination)
+ Notification.suppress do
+ # Copy logic that creates new comments that we do not want triggering
+ # notifications.
+ end
+ end
end
- end
- end
*Michael Ryan*
diff --git a/activerecord/lib/active_record/suppressor.rb b/activerecord/lib/active_record/suppressor.rb
index b47f02143c..5c46d7cc9c 100644
--- a/activerecord/lib/active_record/suppressor.rb
+++ b/activerecord/lib/active_record/suppressor.rb
@@ -5,26 +5,26 @@ module ActiveRecord
# For example, here's a pattern of creating notifications when new comments
# are posted. (The notification may in turn trigger an email, a push
# notification, or just appear in the UI somewhere):
- #
- # class Comment < ActiveRecord::Base
- # belongs_to :commentable, polymorphic: true
- # after_create -> { Notification.create! comment: self,
- # recipients: commentable.recipients }
- # end
- #
+ #
+ # class Comment < ActiveRecord::Base
+ # belongs_to :commentable, polymorphic: true
+ # after_create -> { Notification.create! comment: self,
+ # recipients: commentable.recipients }
+ # end
+ #
# That's what you want the bulk of the time. New comment creates a new
# Notification. But there may well be off cases, like copying a commentable
# and its comments, where you don't want that. So you'd have a concern
# something like this:
- #
- # module Copyable
- # def copy_to(destination)
- # Notification.suppress do
- # # Copy logic that creates new comments that we do not want
- # # triggering notifications.
+ #
+ # module Copyable
+ # def copy_to(destination)
+ # Notification.suppress do
+ # # Copy logic that creates new comments that we do not want
+ # # triggering notifications.
+ # end
# end
# end
- # end
module Suppressor
extend ActiveSupport::Concern
@@ -38,7 +38,7 @@ module ActiveRecord
end
# Ignore saving events if we're in suppression mode.
- def save!(*args)
+ def save!(*args) # :nodoc:
SuppressorRegistry.suppressed[self.class.name] ? self : super
end
end
diff --git a/activerecord/test/cases/suppressor_test.rb b/activerecord/test/cases/suppressor_test.rb
index 011d712bb8..1c449d42fe 100644
--- a/activerecord/test/cases/suppressor_test.rb
+++ b/activerecord/test/cases/suppressor_test.rb
@@ -3,7 +3,6 @@ require 'models/notification'
require 'models/user'
class SuppressorTest < ActiveRecord::TestCase
-
def test_suppresses_creation_of_record_generated_by_callback
assert_difference -> { User.count } do
assert_no_difference -> { Notification.count } do