From cf4f05a7d4a2051cf3593bc7c3a6a216e74e797a Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Sat, 18 Mar 2017 15:15:24 +0900 Subject: Delegate `uniq` to `records` This fixes CI failure due to 48f3be8c. `Enumerable#uniq` was introduced since Ruby 2.4. We should delegate `uniq` to `records` explicitly. And since b644964b `ActiveRecord::Relation` includes `Enumerable` so delegating `map` is unneeded. --- activerecord/lib/active_record/relation/delegation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation/delegation.rb b/activerecord/lib/active_record/relation/delegation.rb index 0612151584..7b704c7e66 100644 --- a/activerecord/lib/active_record/relation/delegation.rb +++ b/activerecord/lib/active_record/relation/delegation.rb @@ -36,7 +36,7 @@ module ActiveRecord # may vary depending on the klass of a relation, so we create a subclass of Relation # for each different klass, and the delegations are compiled into that subclass only. - delegate :to_xml, :encode_with, :length, :collect, :map, :each, :all?, :include?, :to_ary, :join, + delegate :to_xml, :encode_with, :length, :collect, :uniq, :each, :all?, :include?, :to_ary, :join, :[], :&, :|, :+, :-, :sample, :reverse, :compact, :in_groups, :in_groups_of, :to_sentence, :to_formatted_s, :as_json, :shuffle, :split, :index, to: :records -- cgit v1.2.3 From 4c1d22183c9ed4dea74ef60a3cca1891fa588b74 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 20 Mar 2017 00:17:37 +0900 Subject: Evaluate the default block only when necessary Follow up of #28453. --- activerecord/lib/active_record/associations/belongs_to_association.rb | 4 ++-- activerecord/lib/active_record/associations/builder/belongs_to.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 4a4f88bb94..a2432e389a 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -21,8 +21,8 @@ module ActiveRecord self.target = record end - def default(record) - writer(record) if reader.nil? + def default(&block) + writer(instance_exec(&block)) if reader.nil? end def reset diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 50a1c39ccf..2b9dd8aae8 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -121,7 +121,7 @@ module ActiveRecord::Associations::Builder # :nodoc: def self.add_default_callbacks(model, reflection) model.before_validation lambda { |o| - o.association(reflection.name).default o.instance_exec(&reflection.options[:default]) + o.association(reflection.name).default(&reflection.options[:default]) } end -- cgit v1.2.3