mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
added a greater than node
This commit is contained in:
parent
6032d40c1d
commit
9fdaf497cb
5 changed files with 31 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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'
|
||||
|
|
6
lib/arel/nodes/greater_than.rb
Normal file
6
lib/arel/nodes/greater_than.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
module Arel
|
||||
module Nodes
|
||||
class GreaterThan < Arel::Nodes::Binary
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue