From a1a6fbc189d0cb8c44606eafcb8bda7a010554c0 Mon Sep 17 00:00:00 2001 From: Alexander Staubo Date: Wed, 22 Feb 2012 15:25:10 +0100 Subject: Support ANSI SQL2003 window functions. --- test/nodes/test_over.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/nodes/test_over.rb (limited to 'test/nodes/test_over.rb') diff --git a/test/nodes/test_over.rb b/test/nodes/test_over.rb new file mode 100644 index 0000000000..fcc5078e7b --- /dev/null +++ b/test/nodes/test_over.rb @@ -0,0 +1,40 @@ +require 'helper' + +describe Arel::Nodes::Over do + describe 'with literal' do + it 'should reference the window definition by name' do + table = Arel::Table.new :users + table[:id].count.over('foo').to_sql.must_be_like %{ + COUNT("users"."id") OVER "foo" + } + end + end + + describe 'with SQL literal' do + it 'should reference the window definition by name' do + table = Arel::Table.new :users + table[:id].count.over(Arel.sql('foo')).to_sql.must_be_like %{ + COUNT("users"."id") OVER foo + } + end + end + + describe 'with no expression' do + it 'should use empty definition' do + table = Arel::Table.new :users + table[:id].count.over.to_sql.must_be_like %{ + COUNT("users"."id") OVER () + } + end + end + + describe 'with expression' do + it 'should use definition in sub-expression' do + table = Arel::Table.new :users + window = Arel::Nodes::Window.new.order(table['foo']) + table[:id].count.over(window).to_sql.must_be_like %{ + COUNT("users"."id") OVER (ORDER BY \"users\".\"foo\") + } + end + end +end -- cgit v1.2.3