aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-10 11:39:50 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-10 11:39:50 -0700
commit6032d40c1d1c7a7681f145c30b4c26386395ba45 (patch)
treede49d1734e3d3088304b8c092ea1cbd72d5e65fc
parente7648f26921d66f1375645808a5266d8e0e3edcf (diff)
downloadrails-6032d40c1d1c7a7681f145c30b4c26386395ba45.tar.gz
rails-6032d40c1d1c7a7681f145c30b4c26386395ba45.tar.bz2
rails-6032d40c1d1c7a7681f145c30b4c26386395ba45.zip
added greater than or equal to node
-rw-r--r--lib/arel/attributes/attribute.rb4
-rw-r--r--lib/arel/nodes.rb1
-rw-r--r--lib/arel/nodes/greater_than_or_equal.rb6
-rw-r--r--lib/arel/visitors/to_sql.rb4
-rw-r--r--spec/arel/attributes/attribute_spec.rb16
5 files changed, 31 insertions, 0 deletions
diff --git a/lib/arel/attributes/attribute.rb b/lib/arel/attributes/attribute.rb
index bd47aa12fd..62bef5f1cf 100644
--- a/lib/arel/attributes/attribute.rb
+++ b/lib/arel/attributes/attribute.rb
@@ -24,6 +24,10 @@ module Arel
def average
Nodes::Avg.new [self], Nodes::SqlLiteral.new('avg_id')
end
+
+ def gteq right
+ Nodes::GreaterThanOrEqual.new self, right
+ end
end
class String < Attribute; end
diff --git a/lib/arel/nodes.rb b/lib/arel/nodes.rb
index 89e28f138c..6a6c6ece77 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_or_equal'
require 'arel/nodes/in'
require 'arel/nodes/lock'
diff --git a/lib/arel/nodes/greater_than_or_equal.rb b/lib/arel/nodes/greater_than_or_equal.rb
new file mode 100644
index 0000000000..a8cfaab04e
--- /dev/null
+++ b/lib/arel/nodes/greater_than_or_equal.rb
@@ -0,0 +1,6 @@
+module Arel
+ module Nodes
+ class GreaterThanOrEqual < Arel::Nodes::Binary
+ end
+ end
+end
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb
index dc3dbc14c0..2b34fb63dc 100644
--- a/lib/arel/visitors/to_sql.rb
+++ b/lib/arel/visitors/to_sql.rb
@@ -109,6 +109,10 @@ module Arel
"#{visit o.relation} #{quote_table_name o.name}"
end
+ def visit_Arel_Nodes_GreaterThanOrEqual 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 fb6954dc7e..ee12aa2371 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 '#gteq' do
+ it 'should create a GreaterThanOrEqual node' do
+ relation = Table.new(:users)
+ relation[:id].gteq(10).should be_kind_of Nodes::GreaterThanOrEqual
+ end
+
+ it 'should generate >= in sql' do
+ relation = Table.new(:users)
+ mgr = relation.project relation[:id]
+ mgr.where relation[:id].gteq(10)
+ mgr.to_sql.should be_like %{
+ SELECT "users"."id" FROM "users" WHERE "users"."id" >= 10
+ }
+ end
+ end
+
describe '#average' do
it 'should create a AVG node' do
relation = Table.new(:users)