From 13e00df17999857013983051da26a0e15d6f23a5 Mon Sep 17 00:00:00 2001 From: Michael Munroe Date: Mon, 25 Jun 2018 21:26:42 -0400 Subject: Add example for no_touching? in active_record/no_touching for api docs [ci skip] There was no example code for ActiveRecord::NoTouching#no_touching?. This PR adds an example for the API docs. --- activerecord/lib/active_record/no_touching.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/no_touching.rb b/activerecord/lib/active_record/no_touching.rb index 754c891884..697076bdae 100644 --- a/activerecord/lib/active_record/no_touching.rb +++ b/activerecord/lib/active_record/no_touching.rb @@ -43,6 +43,13 @@ module ActiveRecord end end + # Returns +true+ if the class has +no_touching+ set, +false+ otherwise. + # + # Project.no_touching do + # Project.first.no_touching? # true + # Message.first.no_touching? # false + # end + # def no_touching? NoTouching.applied_to?(self.class) end -- cgit v1.2.3 From cc0e84f9bfa89750ceca38db47ce5657cc373c3d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Tue, 26 Jun 2018 17:26:02 +0900 Subject: Remove `ActiveSupport::Concern` from `ActiveRecord::Aggregations` `include Aggregations` no longer needs to invoke `extend Aggregations::ClassMethods` since 657060b. --- activerecord/lib/active_record/aggregations.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 7286837ac7..3250e29b82 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -3,8 +3,6 @@ module ActiveRecord # See ActiveRecord::Aggregations::ClassMethods for documentation module Aggregations - extend ActiveSupport::Concern - def initialize_dup(*) # :nodoc: @aggregation_cache = {} super -- cgit v1.2.3 From 634c53ac0ec6e4036870d79783daa403bf46dad2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 26 Jun 2018 09:15:55 -0700 Subject: Call initialize after allocate If someone calls allocate on the object, they'd better also call an initialization routine too (you can't expect allocate to do any initialization work). Before this commit, AR objects that are instantiated from the database would call `define_attribute_methods` twice. --- activerecord/lib/active_record/core.rb | 5 ----- activerecord/test/cases/attribute_methods_test.rb | 13 ------------- 2 files changed, 18 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index e1a0b2ecf8..e03c86f48c 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -139,11 +139,6 @@ module ActiveRecord end module ClassMethods # :nodoc: - def allocate - define_attribute_methods - super - end - def initialize_find_by_cache # :nodoc: @find_by_statement_cache = { true => Concurrent::Map.new, false => Concurrent::Map.new } end diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index 434d32846c..0bfd46a522 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -163,19 +163,6 @@ class AttributeMethodsTest < ActiveRecord::TestCase assert_equal "10", keyboard.read_attribute_before_type_cast(:key_number) end - # Syck calls respond_to? before actually calling initialize. - test "respond_to? with an allocated object" do - klass = Class.new(ActiveRecord::Base) do - self.table_name = "topics" - end - - topic = klass.allocate - assert_not_respond_to topic, "nothingness" - assert_not_respond_to topic, :nothingness - assert_respond_to topic, "title" - assert_respond_to topic, :title - end - # IRB inspects the return value of MyModel.allocate. test "allocated objects can be inspected" do topic = Topic.allocate -- cgit v1.2.3