aboutsummaryrefslogtreecommitdiffstats
path: root/test/nodes/test_over.rb
diff options
context:
space:
mode:
authorAlexander Staubo <alex@origo.no>2012-02-22 15:25:10 +0100
committerAlexander Staubo <alex@origo.no>2012-02-22 15:25:10 +0100
commita1a6fbc189d0cb8c44606eafcb8bda7a010554c0 (patch)
tree05bb006e6a5b39e5796d5eae302642c169ba7d5b /test/nodes/test_over.rb
parent6e427e589820278908e7a746749eb9b79b0f85e3 (diff)
downloadrails-a1a6fbc189d0cb8c44606eafcb8bda7a010554c0.tar.gz
rails-a1a6fbc189d0cb8c44606eafcb8bda7a010554c0.tar.bz2
rails-a1a6fbc189d0cb8c44606eafcb8bda7a010554c0.zip
Support ANSI SQL2003 window functions.
Diffstat (limited to 'test/nodes/test_over.rb')
-rw-r--r--test/nodes/test_over.rb40
1 files changed, 40 insertions, 0 deletions
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