From 8d3c67fbc44844d5565b580655ab9705d9fb8a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sun, 12 May 2013 10:49:49 -0700 Subject: Merge pull request #10556 from Empact/deprecate-schema-statements-distinct Deprecate SchemaStatements#distinct, and make SchemaStatements#columns_for_distinct nodoc. Conflicts: activerecord/CHANGELOG.md --- activerecord/CHANGELOG.md | 5 +++ .../abstract/schema_statements.rb | 3 +- .../adapters/postgresql/postgresql_adapter_test.rb | 36 ++++++++++++++-------- 3 files changed, 31 insertions(+), 13 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 789e7f41f9..772fd5999b 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,8 @@ +* Deprecate `ConnectionAdapters::SchemaStatements#distinct`, + as it is no longer used by internals. + + *Ben Woosley# + * Fix pending migrations error when loading schema and `ActiveRecord::Base.table_name_prefix` is not blank. diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 6e1f43cce6..8ffe150de6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -710,6 +710,7 @@ module ActiveRecord # distinct("posts.id", ["posts.created_at desc"]) # def distinct(columns, order_by) + ActiveSupport::Deprecation.warn("#distinct is deprecated and shall be removed from future releases.") "DISTINCT #{columns_for_distinct(columns, order_by)}" end @@ -718,7 +719,7 @@ module ActiveRecord # require the order columns appear in the SELECT. # # columns_for_distinct("posts.id", ["posts.created_at desc"]) - def columns_for_distinct(columns, orders) + def columns_for_distinct(columns, orders) # :nodoc: columns end diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index ff7eb86969..fb88ab7c09 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -226,8 +226,10 @@ module ActiveRecord end def test_distinct_zero_orders - assert_equal "DISTINCT posts.id", - @connection.distinct("posts.id", []) + assert_deprecated do + assert_equal "DISTINCT posts.id", + @connection.distinct("posts.id", []) + end end def test_columns_for_distinct_zero_orders @@ -236,8 +238,10 @@ module ActiveRecord end def test_distinct_one_order - assert_equal "DISTINCT posts.id, posts.created_at AS alias_0", - @connection.distinct("posts.id", ["posts.created_at desc"]) + assert_deprecated do + assert_equal "DISTINCT posts.id, posts.created_at AS alias_0", + @connection.distinct("posts.id", ["posts.created_at desc"]) + end end def test_columns_for_distinct_one_order @@ -246,8 +250,10 @@ module ActiveRecord end def test_distinct_few_orders - assert_equal "DISTINCT posts.id, posts.created_at AS alias_0, posts.position AS alias_1", - @connection.distinct("posts.id", ["posts.created_at desc", "posts.position asc"]) + assert_deprecated do + assert_equal "DISTINCT posts.id, posts.created_at AS alias_0, posts.position AS alias_1", + @connection.distinct("posts.id", ["posts.created_at desc", "posts.position asc"]) + end end def test_columns_for_distinct_few_orders @@ -256,8 +262,10 @@ module ActiveRecord end def test_distinct_blank_not_nil_orders - assert_equal "DISTINCT posts.id, posts.created_at AS alias_0", - @connection.distinct("posts.id", ["posts.created_at desc", "", " "]) + assert_deprecated do + assert_equal "DISTINCT posts.id, posts.created_at AS alias_0", + @connection.distinct("posts.id", ["posts.created_at desc", "", " "]) + end end def test_columns_for_distinct_blank_not_nil_orders @@ -270,8 +278,10 @@ module ActiveRecord def order.to_sql "posts.created_at desc" end - assert_equal "DISTINCT posts.id, posts.created_at AS alias_0", - @connection.distinct("posts.id", [order]) + assert_deprecated do + assert_equal "DISTINCT posts.id, posts.created_at AS alias_0", + @connection.distinct("posts.id", [order]) + end end def test_columns_for_distinct_with_arel_order @@ -284,8 +294,10 @@ module ActiveRecord end def test_distinct_with_nulls - assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls first"]) - assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"]) + assert_deprecated do + assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls first"]) + assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"]) + end end def test_columns_for_distinct_with_nulls -- cgit v1.2.3