diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-21 09:33:41 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-11-21 09:33:41 -0800 |
commit | 6b266c21b2cc649505e5f31c74e1f450f3287981 (patch) | |
tree | 542f558dccdd8ab4a75b84dbda66eabe09055b39 /activerecord/test | |
parent | f058e565c1f7ab36199887a56696edb01d85e2cf (diff) | |
parent | 2197e1f36575d90712da62abd6cbc27bf1feba6b (diff) | |
download | rails-6b266c21b2cc649505e5f31c74e1f450f3287981.tar.gz rails-6b266c21b2cc649505e5f31c74e1f450f3287981.tar.bz2 rails-6b266c21b2cc649505e5f31c74e1f450f3287981.zip |
Merge pull request #8289 from semaperepelitsa/pg_adapter_refactoring_squashed
Refactoring, testing and documenting pg_connection.distinct
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb index f1362dd15f..872204c644 100644 --- a/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb +++ b/activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb @@ -216,6 +216,35 @@ module ActiveRecord assert_equal "(number > 100)", index.where end + def test_distinct_zero_orders + assert_equal "DISTINCT posts.id", + @connection.distinct("posts.id", []) + 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"]) + 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"]) + 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", "", " "]) + end + + def test_distinct_with_arel_order + order = Object.new + 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]) + 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"]) |