mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
removed binding for attributes and predicates
This commit is contained in:
parent
8887dcce12
commit
89eff9708d
6 changed files with 19 additions and 32 deletions
|
@ -25,7 +25,7 @@ module ActiveRelation
|
|||
end
|
||||
|
||||
def to_sql(formatter = nil)
|
||||
"#{operand2.format(operand1)} #{predicate_sql} #{operand1.format(operand2)}"
|
||||
"#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}"
|
||||
end
|
||||
|
||||
def descend
|
||||
|
|
|
@ -63,31 +63,31 @@ module ActiveRelation
|
|||
|
||||
module Predications
|
||||
def eq(other)
|
||||
Equality.new(self, other.bind(relation))
|
||||
Equality.new(self, other)
|
||||
end
|
||||
|
||||
def lt(other)
|
||||
LessThan.new(self, other.bind(relation))
|
||||
LessThan.new(self, other)
|
||||
end
|
||||
|
||||
def lteq(other)
|
||||
LessThanOrEqualTo.new(self, other.bind(relation))
|
||||
LessThanOrEqualTo.new(self, other)
|
||||
end
|
||||
|
||||
def gt(other)
|
||||
GreaterThan.new(self, other.bind(relation))
|
||||
GreaterThan.new(self, other)
|
||||
end
|
||||
|
||||
def gteq(other)
|
||||
GreaterThanOrEqualTo.new(self, other.bind(relation))
|
||||
GreaterThanOrEqualTo.new(self, other)
|
||||
end
|
||||
|
||||
def matches(regexp)
|
||||
Match.new(self, regexp.bind(relation))
|
||||
Match.new(self, regexp)
|
||||
end
|
||||
|
||||
def in(array)
|
||||
In.new(self, array.bind(relation))
|
||||
In.new(self, array)
|
||||
end
|
||||
end
|
||||
include Predications
|
||||
|
|
|
@ -24,7 +24,7 @@ module ActiveRelation
|
|||
|
||||
describe 'when relating an attribute and a value' do
|
||||
before do
|
||||
@value = "1-asdf".bind(@relation)
|
||||
@value = "1-asdf"
|
||||
end
|
||||
|
||||
describe 'when relating to an integer attribute' do
|
||||
|
@ -43,19 +43,6 @@ module ActiveRelation
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when relating two values' do
|
||||
before do
|
||||
@value = "1-asdf".bind(@relation)
|
||||
@another_value = 2.bind(@relation)
|
||||
end
|
||||
|
||||
it 'formats values appropos of their type' do
|
||||
ConcreteBinary.new(string = @value, integer = @another_value).to_sql.should be_like("
|
||||
'1-asdf' <=> 2
|
||||
")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '==' do
|
||||
|
|
|
@ -35,7 +35,7 @@ module ActiveRelation
|
|||
|
||||
describe 'when relation to a nil value' do
|
||||
before do
|
||||
@nil = nil.bind(@relation1)
|
||||
@nil = nil
|
||||
end
|
||||
|
||||
it "manufactures an is null predicate" do
|
||||
|
|
|
@ -21,7 +21,7 @@ module ActiveRelation
|
|||
end
|
||||
|
||||
it "returns self if the substituting to the same relation" do
|
||||
@attribute.bind(@relation).should == @attribute
|
||||
@attribute.should == @attribute
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -97,43 +97,43 @@ module ActiveRelation
|
|||
|
||||
describe '#eq' do
|
||||
it "manufactures an equality predicate" do
|
||||
@attribute.eq('name').should == Equality.new(@attribute, 'name'.bind(@relation))
|
||||
@attribute.eq('name').should == Equality.new(@attribute, 'name')
|
||||
end
|
||||
end
|
||||
|
||||
describe '#lt' do
|
||||
it "manufactures a less-than predicate" do
|
||||
@attribute.lt(10).should == LessThan.new(@attribute, 10.bind(@relation))
|
||||
@attribute.lt(10).should == LessThan.new(@attribute, 10)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#lteq' do
|
||||
it "manufactures a less-than or equal-to predicate" do
|
||||
@attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10.bind(@relation))
|
||||
@attribute.lteq(10).should == LessThanOrEqualTo.new(@attribute, 10)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#gt' do
|
||||
it "manufactures a greater-than predicate" do
|
||||
@attribute.gt(10).should == GreaterThan.new(@attribute, 10.bind(@relation))
|
||||
@attribute.gt(10).should == GreaterThan.new(@attribute, 10)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#gteq' do
|
||||
it "manufactures a greater-than or equal-to predicate" do
|
||||
@attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10.bind(@relation))
|
||||
@attribute.gteq(10).should == GreaterThanOrEqualTo.new(@attribute, 10)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#matches' do
|
||||
it "manufactures a match predicate" do
|
||||
@attribute.matches(/.*/).should == Match.new(@attribute, /.*/.bind(@relation))
|
||||
@attribute.matches(/.*/).should == Match.new(@attribute, /.*/)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#in' do
|
||||
it "manufactures an in predicate" do
|
||||
@attribute.in(1..30).should == In.new(@attribute, (1..30).bind(@relation))
|
||||
@attribute.in(1..30).should == In.new(@attribute, (1..30))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,7 +19,7 @@ ActiveRecord::Base.establish_connection 'test'
|
|||
|
||||
class Hash
|
||||
def shift
|
||||
returning to_a.sort { |(key1, value1), (key2, value2)| key1.hash <=> key2.hash }.shift do |key, value|
|
||||
returning to_a.sort { |(key1, value1), (key2, value2)| key1.hash <=> key2.hash }.shift do |key, _|
|
||||
delete(key)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue