diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-26 15:22:50 +0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-06-26 15:22:50 +0800 |
commit | ebbd786945c12f65062ef5b4809b4f13643e3c52 (patch) | |
tree | a015fcbaf2ab27d88f79122889ee409940f02a73 /test | |
parent | f50de54a6f0c59ab75526cfdb7896830130ffdf7 (diff) | |
parent | 4a72415555de19ca33c8ea16ee9ba26d1b73b078 (diff) | |
download | rails-ebbd786945c12f65062ef5b4809b4f13643e3c52.tar.gz rails-ebbd786945c12f65062ef5b4809b4f13643e3c52.tar.bz2 rails-ebbd786945c12f65062ef5b4809b4f13643e3c52.zip |
Merge pull request #163 from atombender/master
Support for PARTITION BY in window
Diffstat (limited to 'test')
-rw-r--r-- | test/nodes/test_window.rb | 12 | ||||
-rw-r--r-- | test/test_select_manager.rb | 41 |
2 files changed, 50 insertions, 3 deletions
diff --git a/test/nodes/test_window.rb b/test/nodes/test_window.rb index f09d16e441..9ec42be59f 100644 --- a/test/nodes/test_window.rb +++ b/test/nodes/test_window.rb @@ -7,9 +7,11 @@ module Arel it 'is equal with equal ivars' do window1 = Window.new window1.orders = [1, 2] + window1.partitions = [1] window1.frame 3 window2 = Window.new window2.orders = [1, 2] + window2.partitions = [1] window2.frame 3 array = [window1, window2] assert_equal 1, array.uniq.size @@ -18,9 +20,11 @@ module Arel it 'is not equal with different ivars' do window1 = Window.new window1.orders = [1, 2] + window1.partitions = [1] window1.frame 3 window2 = Window.new window2.orders = [1, 2] + window1.partitions = [1] window2.frame 4 array = [window1, window2] assert_equal 2, array.uniq.size @@ -33,9 +37,11 @@ module Arel it 'is equal with equal ivars' do window1 = NamedWindow.new 'foo' window1.orders = [1, 2] + window1.partitions = [1] window1.frame 3 window2 = NamedWindow.new 'foo' window2.orders = [1, 2] + window2.partitions = [1] window2.frame 3 array = [window1, window2] assert_equal 1, array.uniq.size @@ -44,9 +50,11 @@ module Arel it 'is not equal with different ivars' do window1 = NamedWindow.new 'foo' window1.orders = [1, 2] + window1.partitions = [1] window1.frame 3 window2 = NamedWindow.new 'bar' window2.orders = [1, 2] + window2.partitions = [1] window2.frame 3 array = [window1, window2] assert_equal 2, array.uniq.size @@ -68,6 +76,4 @@ module Arel end end end -end - - +end
\ No newline at end of file diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 4678901bb4..0b9756709d 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -716,6 +716,47 @@ module Arel } end + it 'takes an order with multiple columns' do + table = Table.new :users + manager = Arel::SelectManager.new Table.engine + manager.from table + manager.window('a_window').order(table['foo'].asc, table['bar'].desc) + manager.to_sql.must_be_like %{ + SELECT FROM "users" WINDOW "a_window" AS (ORDER BY "users"."foo" ASC, "users"."bar" DESC) + } + end + + it 'takes a partition' do + table = Table.new :users + manager = Arel::SelectManager.new Table.engine + manager.from table + manager.window('a_window').partition(table['bar']) + manager.to_sql.must_be_like %{ + SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar") + } + end + + it 'takes a partition and an order' do + table = Table.new :users + manager = Arel::SelectManager.new Table.engine + manager.from table + manager.window('a_window').partition(table['foo']).order(table['foo'].asc) + manager.to_sql.must_be_like %{ + SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."foo" + ORDER BY "users"."foo" ASC) + } + end + + it 'takes a partition with multiple columns' do + table = Table.new :users + manager = Arel::SelectManager.new Table.engine + manager.from table + manager.window('a_window').partition(table['bar'], table['baz']) + manager.to_sql.must_be_like %{ + SELECT FROM "users" WINDOW "a_window" AS (PARTITION BY "users"."bar", "users"."baz") + } + end + it 'takes a rows frame, unbounded preceding' do table = Table.new :users manager = Arel::SelectManager.new Table.engine |