From 00d1482fefa1cf9c3753b58f4fe9b580c52ae935 Mon Sep 17 00:00:00 2001 From: Samuel Kadolph Date: Fri, 27 May 2011 17:21:40 -0400 Subject: Include Arel::Predicates to Arel::Nodes::Function so you can do table[:id].count.eq(2) --- test/nodes/test_count.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/nodes') diff --git a/test/nodes/test_count.rb b/test/nodes/test_count.rb index afa423e8f5..be53b86855 100644 --- a/test/nodes/test_count.rb +++ b/test/nodes/test_count.rb @@ -15,4 +15,13 @@ describe Arel::Nodes::Count do } end end + + describe "eq" do + it "should compare the count" do + table = Arel::Table.new :users + table[:id].count.eq(2).to_sql.must_be_like %{ + COUNT("users"."id") = 2 + } + end + end end -- cgit v1.2.3 From ba3578a22f824da3478b6dceb100deb9f41a56e9 Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Tue, 14 Jun 2011 17:43:22 -0400 Subject: Break Ordering into Ascending/Descending nodes, allow reversal --- test/nodes/test_ascending.rb | 34 ++++++++++++++++++++++++++++++++++ test/nodes/test_descending.rb | 34 ++++++++++++++++++++++++++++++++++ test/nodes/test_infix_operation.rb | 4 ++-- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 test/nodes/test_ascending.rb create mode 100644 test/nodes/test_descending.rb (limited to 'test/nodes') diff --git a/test/nodes/test_ascending.rb b/test/nodes/test_ascending.rb new file mode 100644 index 0000000000..0e2c4810c6 --- /dev/null +++ b/test/nodes/test_ascending.rb @@ -0,0 +1,34 @@ +require 'helper' + +module Arel + module Nodes + class TestAscending < MiniTest::Unit::TestCase + def test_construct + ascending = Ascending.new 'zomg' + assert_equal 'zomg', ascending.expr + end + + def test_reverse + ascending = Ascending.new 'zomg' + descending = ascending.reverse + assert_kind_of Descending, descending + assert_equal ascending.expr, descending.expr + end + + def test_direction + ascending = Ascending.new 'zomg' + assert_equal :asc, ascending.direction + end + + def test_ascending? + ascending = Ascending.new 'zomg' + assert ascending.ascending? + end + + def test_descending? + ascending = Ascending.new 'zomg' + assert !ascending.descending? + end + end + end +end diff --git a/test/nodes/test_descending.rb b/test/nodes/test_descending.rb new file mode 100644 index 0000000000..424f8298cd --- /dev/null +++ b/test/nodes/test_descending.rb @@ -0,0 +1,34 @@ +require 'helper' + +module Arel + module Nodes + class TestDescending < MiniTest::Unit::TestCase + def test_construct + descending = Descending.new 'zomg' + assert_equal 'zomg', descending.expr + end + + def test_reverse + descending = Descending.new 'zomg' + ascending = descending.reverse + assert_kind_of Ascending, ascending + assert_equal descending.expr, ascending.expr + end + + def test_direction + descending = Descending.new 'zomg' + assert_equal :desc, descending.direction + end + + def test_ascending? + descending = Descending.new 'zomg' + assert !descending.ascending? + end + + def test_descending? + descending = Descending.new 'zomg' + assert descending.descending? + end + end + end +end diff --git a/test/nodes/test_infix_operation.rb b/test/nodes/test_infix_operation.rb index db3216eeee..3d2eb0d9c6 100644 --- a/test/nodes/test_infix_operation.rb +++ b/test/nodes/test_infix_operation.rb @@ -21,9 +21,9 @@ module Arel def test_opertaion_ordering operation = InfixOperation.new :+, 1, 2 ordering = operation.desc - assert_kind_of Ordering, ordering + assert_kind_of Descending, ordering assert_equal operation, ordering.expr - assert_equal :desc, ordering.direction + assert ordering.descending? end end end -- cgit v1.2.3