diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-29 18:49:12 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-29 18:49:12 +0900 |
commit | 302d739855306f9061f1f2357844cb8d76f20ae9 (patch) | |
tree | e219a57c33e4f72035d0f330c6ddc55ca7c05e9c | |
parent | e6c177e07cd4ea42df751b5baef8858efa97dfbd (diff) | |
download | rails-302d739855306f9061f1f2357844cb8d76f20ae9.tar.gz rails-302d739855306f9061f1f2357844cb8d76f20ae9.tar.bz2 rails-302d739855306f9061f1f2357844cb8d76f20ae9.zip |
Extract `_raise_record_not_touched_error`
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 22 | ||||
-rw-r--r-- | activerecord/lib/active_record/touch_later.rb | 7 |
2 files changed, 13 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index adfd564695..a58c5fd48a 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -849,12 +849,7 @@ module ActiveRecord # ball.touch(:updated_at) # => raises ActiveRecordError # def touch(*names, time: nil) - unless persisted? - raise ActiveRecordError, <<-MSG.squish - cannot touch on a new or destroyed record object. Consider using - persisted?, new_record?, or destroyed? before touching - MSG - end + _raise_record_not_touched_error unless persisted? attribute_names = timestamp_attributes_for_update_in_model attribute_names |= names.map!(&:to_s).map! { |name| @@ -954,14 +949,21 @@ module ActiveRecord @_association_destroy_exception = nil end + def _raise_readonly_record_error + raise ReadOnlyRecord, "#{self.class} is marked as readonly" + end + + def _raise_record_not_touched_error + raise ActiveRecordError, <<~MSG.squish + Cannot touch on a new or destroyed record object. Consider using + persisted?, new_record?, or destroyed? before touching. + MSG + end + # The name of the method used to touch a +belongs_to+ association when the # +:touch+ option is used. def belongs_to_touch_method :touch end - - def _raise_readonly_record_error - raise ReadOnlyRecord, "#{self.class} is marked as readonly" - end end end diff --git a/activerecord/lib/active_record/touch_later.rb b/activerecord/lib/active_record/touch_later.rb index 980e42664b..b60cc96165 100644 --- a/activerecord/lib/active_record/touch_later.rb +++ b/activerecord/lib/active_record/touch_later.rb @@ -10,12 +10,7 @@ module ActiveRecord end def touch_later(*names) # :nodoc: - unless persisted? - raise ActiveRecordError, <<-MSG.squish - cannot touch on a new or destroyed record object. Consider using - persisted?, new_record?, or destroyed? before touching - MSG - end + _raise_record_not_touched_error unless persisted? @_defer_touch_attrs ||= timestamp_attributes_for_update_in_model @_defer_touch_attrs |= names |