diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-10 11:47:03 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-09-10 11:47:03 -0700 |
commit | 9fdaf497cb346696ea538308b77ec07f051cd569 (patch) | |
tree | 9b9af29488f27ec631ddfc5a65ab1a1defaceb4d | |
parent | 6032d40c1d1c7a7681f145c30b4c26386395ba45 (diff) | |
download | rails-9fdaf497cb346696ea538308b77ec07f051cd569.tar.gz rails-9fdaf497cb346696ea538308b77ec07f051cd569.tar.bz2 rails-9fdaf497cb346696ea538308b77ec07f051cd569.zip |
added a greater than node
-rw-r--r-- | lib/arel/attributes/attribute.rb | 4 | ||||
-rw-r--r-- | lib/arel/nodes.rb | 1 | ||||
-rw-r--r-- | lib/arel/nodes/greater_than.rb | 6 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 4 | ||||
-rw-r--r-- | spec/arel/attributes/attribute_spec.rb | 16 |
5 files changed, 31 insertions, 0 deletions
diff --git a/lib/arel/attributes/attribute.rb b/lib/arel/attributes/attribute.rb index 62bef5f1cf..d77574f33e 100644 --- a/lib/arel/attributes/attribute.rb +++ b/lib/arel/attributes/attribute.rb @@ -28,6 +28,10 @@ module Arel def gteq right Nodes::GreaterThanOrEqual.new self, right end + + def gt right + Nodes::GreaterThan.new self, right + end end class String < Attribute; end diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb index 6a6c6ece77..1215f3f00c 100644 --- a/lib/arel/nodes.rb +++ b/lib/arel/nodes.rb @@ -2,6 +2,7 @@ require 'arel/nodes/binary' require 'arel/nodes/equality' require 'arel/nodes/or' require 'arel/nodes/and' +require 'arel/nodes/greater_than' require 'arel/nodes/greater_than_or_equal' require 'arel/nodes/in' diff --git a/lib/arel/nodes/greater_than.rb b/lib/arel/nodes/greater_than.rb new file mode 100644 index 0000000000..2e03cc2e18 --- /dev/null +++ b/lib/arel/nodes/greater_than.rb @@ -0,0 +1,6 @@ +module Arel + module Nodes + class GreaterThan < Arel::Nodes::Binary + end + end +end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 2b34fb63dc..093deedee5 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -113,6 +113,10 @@ module Arel "#{visit o.left} >= #{visit o.right}" end + def visit_Arel_Nodes_GreaterThan o + "#{visit o.left} > #{visit o.right}" + end + def visit_Arel_Nodes_StringJoin o "#{visit o.left} #{visit o.right}" end diff --git a/spec/arel/attributes/attribute_spec.rb b/spec/arel/attributes/attribute_spec.rb index ee12aa2371..ae0f70c5ba 100644 --- a/spec/arel/attributes/attribute_spec.rb +++ b/spec/arel/attributes/attribute_spec.rb @@ -3,6 +3,22 @@ require 'spec_helper' module Arel module Attributes describe 'attribute' do + describe '#gt' do + it 'should create a GreaterThan node' do + relation = Table.new(:users) + relation[:id].gt(10).should be_kind_of Nodes::GreaterThan + end + + it 'should generate >= in sql' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.where relation[:id].gt(10) + mgr.to_sql.should be_like %{ + SELECT "users"."id" FROM "users" WHERE "users"."id" > 10 + } + end + end + describe '#gteq' do it 'should create a GreaterThanOrEqual node' do relation = Table.new(:users) |