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') 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 From 2db4ec6a28a59a3f74a4979ae5bc117e5c7573c4 Mon Sep 17 00:00:00 2001 From: Alexander Staubo Date: Thu, 23 Feb 2012 14:06:05 +0100 Subject: Add #extract, which produces ANSI SQL function EXTRACT( from ). --- test/nodes/test_extract.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/nodes/test_extract.rb (limited to 'test/nodes') diff --git a/test/nodes/test_extract.rb b/test/nodes/test_extract.rb new file mode 100644 index 0000000000..bd1dfa4750 --- /dev/null +++ b/test/nodes/test_extract.rb @@ -0,0 +1,19 @@ +require 'helper' + +describe Arel::Nodes::Extract do + it "should extract field" do + table = Arel::Table.new :users + table[:timestamp].extract('date').to_sql.must_be_like %{ + EXTRACT(DATE FROM "users"."timestamp") + } + end + + describe "as" do + it 'should alias the extract' do + table = Arel::Table.new :users + table[:timestamp].extract('date').as('foo').to_sql.must_be_like %{ + EXTRACT(DATE FROM "users"."timestamp") AS foo + } + end + end +end -- cgit v1.2.3 From 74aadecc4f58e73704ac6a6fdaf25e48832374cf Mon Sep 17 00:00:00 2001 From: Alexander Staubo Date: Thu, 23 Feb 2012 14:16:44 +0100 Subject: Must support aliases for OVER operator. --- test/nodes/test_over.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/nodes') diff --git a/test/nodes/test_over.rb b/test/nodes/test_over.rb index fcc5078e7b..0bdd665e56 100644 --- a/test/nodes/test_over.rb +++ b/test/nodes/test_over.rb @@ -1,6 +1,15 @@ require 'helper' describe Arel::Nodes::Over do + describe 'as' do + it 'should alias the expression' do + table = Arel::Table.new :users + table[:id].count.over.as('foo').to_sql.must_be_like %{ + COUNT("users"."id") OVER () AS foo + } + end + end + describe 'with literal' do it 'should reference the window definition by name' do table = Arel::Table.new :users -- cgit v1.2.3