diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/nodes/test_window.rb | 12 | ||||
-rw-r--r-- | test/test_insert_manager.rb | 11 | ||||
-rw-r--r-- | test/test_select_manager.rb | 41 | ||||
-rw-r--r-- | test/visitors/test_dot.rb | 8 |
4 files changed, 62 insertions, 10 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_insert_manager.rb b/test/test_insert_manager.rb index 4e82ca34c0..9cfd01262b 100644 --- a/test/test_insert_manager.rb +++ b/test/test_insert_manager.rb @@ -78,14 +78,19 @@ module Arel } end - it 'takes an empty list' do + it 'noop for empty list' do + table = Table.new(:users) manager = Arel::InsertManager.new Table.engine + manager.insert [[table[:id], 1]] manager.insert [] + manager.to_sql.must_be_like %{ + INSERT INTO "users" ("id") VALUES (1) + } end end describe 'into' do - it 'takes an engine' do + it 'takes a Table and chains' do manager = Arel::InsertManager.new Table.engine manager.into(Table.new(:users)).must_equal manager end @@ -126,7 +131,7 @@ module Arel end describe "combo" do - it "puts shit together" do + it "combines columns and values list in order" do table = Table.new :users manager = Arel::InsertManager.new Table.engine manager.into table diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 8880e325e4..3380bbec6f 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -732,6 +732,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 diff --git a/test/visitors/test_dot.rb b/test/visitors/test_dot.rb index ee7fc7886c..7763350f5c 100644 --- a/test/visitors/test_dot.rb +++ b/test/visitors/test_dot.rb @@ -17,13 +17,13 @@ module Arel ].each do |klass| define_method("test_#{klass.name.gsub('::', '_')}") do op = klass.new(:a, "z") - @visitor.accept op + @visitor.accept op, Collectors::PlainString.new end end def test_named_function func = Nodes::NamedFunction.new 'omg', 'omg' - @visitor.accept func + @visitor.accept func, Collectors::PlainString.new end # unary ops @@ -41,7 +41,7 @@ module Arel ].each do |klass| define_method("test_#{klass.name.gsub('::', '_')}") do op = klass.new(:a) - @visitor.accept op + @visitor.accept op, Collectors::PlainString.new end end @@ -68,7 +68,7 @@ module Arel ].each do |klass| define_method("test_#{klass.name.gsub('::', '_')}") do binary = klass.new(:a, :b) - @visitor.accept binary + @visitor.accept binary, Collectors::PlainString.new end end end |