From fe634ee61bc60e0417c440f572bb879828677911 Mon Sep 17 00:00:00 2001 From: Andrew Greenberg Date: Sat, 18 Sep 2010 08:59:36 -0700 Subject: [PATCH 1/3] repair rails console autocompletion; Arel provided a deprecation notification by overriding Arel::Attributes::Predications.instance_methods, returning an array of symbols rather than the usual array of strings. The patch corrects this bug, and further uses ActiveSupport.Deprecation instead of the routine logger. --- lib/arel/algebra/attributes/attribute.rb | 4 ++-- spec/algebra/unit/primitives/attribute_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb index e829a54..1a1c058 100644 --- a/lib/arel/algebra/attributes/attribute.rb +++ b/lib/arel/algebra/attributes/attribute.rb @@ -101,8 +101,8 @@ module Arel Predications = Class.new do def self.instance_methods *args - warn "this module is deprecated, please use the PREDICATES constant" - PREDICATES + ActiveSupport::Deprecation.warn "this module is deprecated, please use the PREDICATES constant" + PREDICATES.collect(&:to_s) end end diff --git a/spec/algebra/unit/primitives/attribute_spec.rb b/spec/algebra/unit/primitives/attribute_spec.rb index 4026c0d..b484f8e 100644 --- a/spec/algebra/unit/primitives/attribute_spec.rb +++ b/spec/algebra/unit/primitives/attribute_spec.rb @@ -78,6 +78,16 @@ module Arel before do @attribute = Attribute.new(@relation, :name) end + + describe 'class.instance_methods' do + it "should use ActiveSupport deprecation logger" do + ActiveSupport::Deprecation.should_receive(:warn) + Attribute::Predications.instance_methods + end + it "should return a sortable list" do + lambda{Attribute::Predications.instance_methods.sort!}.should_not raise_error + end + end describe '#eq' do it "manufactures an equality predicate" do -- 1.7.2 From a84a483f455c3e1333c1a54fceb61d735ee5d5e2 Mon Sep 17 00:00:00 2001 From: Andrew Greenberg Date: Sat, 18 Sep 2010 10:50:40 -0700 Subject: [PATCH 2/3] Converted Predications from class to module; removed deprecation warning on instance_methods; added deprecation warning on inclusion --- lib/arel/algebra/attributes/attribute.rb | 6 ++++-- spec/algebra/unit/primitives/attribute_spec.rb | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb index 1a1c058..8b22575 100644 --- a/lib/arel/algebra/attributes/attribute.rb +++ b/lib/arel/algebra/attributes/attribute.rb @@ -99,11 +99,13 @@ module Arel :not_in_any, :not_in_all ] - Predications = Class.new do + Predications = Module.new do def self.instance_methods *args - ActiveSupport::Deprecation.warn "this module is deprecated, please use the PREDICATES constant" PREDICATES.collect(&:to_s) end + def self.included *args + ActiveSupport::Deprecation.warn "this module is deprecated, please use the PREDICATES constant" + end end def eq(other) diff --git a/spec/algebra/unit/primitives/attribute_spec.rb b/spec/algebra/unit/primitives/attribute_spec.rb index b484f8e..916c72b 100644 --- a/spec/algebra/unit/primitives/attribute_spec.rb +++ b/spec/algebra/unit/primitives/attribute_spec.rb @@ -80,13 +80,22 @@ module Arel end describe 'class.instance_methods' do - it "should use ActiveSupport deprecation logger" do - ActiveSupport::Deprecation.should_receive(:warn) - Attribute::Predications.instance_methods + it "should be a module" do + Attribute::Predications.class.should == Module end - it "should return a sortable list" do + it "should return a sortable list" do lambda{Attribute::Predications.instance_methods.sort!}.should_not raise_error end + it "should use use log a Rails deprecation warning upon inclusion in any class" do + ActiveSupport::Deprecation.should_receive(:warn) + Class.new do + include Attribute::Predications + end + end + it "should not log warning in response to #instance_methods" do + ActiveSupport::Deprecation.should_not_receive(:warn) + Attribute::Predications.instance_methods + end end describe '#eq' do -- 1.7.2 From d986f2a4398402260273022c96cd75371a83d444 Mon Sep 17 00:00:00 2001 From: Andrew Greenberg Date: Tue, 21 Sep 2010 14:28:26 -0700 Subject: [PATCH 3/3] Add test to confirm that sort works when added to Object.instance_methods; test works in 1.8.7, but fails in 1.9. Repair with Ruby version check --- lib/arel/algebra/attributes/attribute.rb | 7 ++++++- spec/algebra/unit/primitives/attribute_spec.rb | 3 +++ 2 files changed, 9 insertions(+), 1 deletions(-) diff --git a/lib/arel/algebra/attributes/attribute.rb b/lib/arel/algebra/attributes/attribute.rb index 8b22575..bf31e3b 100644 --- a/lib/arel/algebra/attributes/attribute.rb +++ b/lib/arel/algebra/attributes/attribute.rb @@ -101,8 +101,13 @@ module Arel Predications = Module.new do def self.instance_methods *args - PREDICATES.collect(&:to_s) + if RUBY_VERSION < "1.9" + PREDICATES.collect(&:to_s) + else + PREDICATES + end end + def self.included *args ActiveSupport::Deprecation.warn "this module is deprecated, please use the PREDICATES constant" end diff --git a/spec/algebra/unit/primitives/attribute_spec.rb b/spec/algebra/unit/primitives/attribute_spec.rb index 916c72b..0635a82 100644 --- a/spec/algebra/unit/primitives/attribute_spec.rb +++ b/spec/algebra/unit/primitives/attribute_spec.rb @@ -86,6 +86,9 @@ module Arel it "should return a sortable list" do lambda{Attribute::Predications.instance_methods.sort!}.should_not raise_error end + it "should return a sortable list, when merged with instance methods of Object" do + lambda{(Attribute::Predications.instance_methods+Object.instance_methods).sort!}.should_not raise_error + end it "should use use log a Rails deprecation warning upon inclusion in any class" do ActiveSupport::Deprecation.should_receive(:warn) Class.new do -- 1.7.2