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
|
end
|
||||||
|
|
||||||
def to_sql(formatter = nil)
|
def to_sql(formatter = nil)
|
||||||
"#{operand2.format(operand1)} #{predicate_sql} #{operand1.format(operand2)}"
|
"#{operand1.to_sql} #{predicate_sql} #{operand1.format(operand2)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def descend
|
def descend
|
||||||
|
|
|
@ -63,31 +63,31 @@ module ActiveRelation
|
||||||
|
|
||||||
module Predications
|
module Predications
|
||||||
def eq(other)
|
def eq(other)
|
||||||
Equality.new(self, other.bind(relation))
|
Equality.new(self, other)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lt(other)
|
def lt(other)
|
||||||
LessThan.new(self, other.bind(relation))
|
LessThan.new(self, other)
|
||||||
end
|
end
|
||||||
|
|
||||||
def lteq(other)
|
def lteq(other)
|
||||||
LessThanOrEqualTo.new(self, other.bind(relation))
|
LessThanOrEqualTo.new(self, other)
|
||||||
end
|
end
|
||||||
|
|
||||||
def gt(other)
|
def gt(other)
|
||||||
GreaterThan.new(self, other.bind(relation))
|
GreaterThan.new(self, other)
|
||||||
end
|
end
|
||||||
|
|
||||||
def gteq(other)
|
def gteq(other)
|
||||||
GreaterThanOrEqualTo.new(self, other.bind(relation))
|
GreaterThanOrEqualTo.new(self, other)
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches(regexp)
|
def matches(regexp)
|
||||||
Match.new(self, regexp.bind(relation))
|
Match.new(self, regexp)
|
||||||
end
|
end
|
||||||
|
|
||||||
def in(array)
|
def in(array)
|
||||||
In.new(self, array.bind(relation))
|
In.new(self, array)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
include Predications
|
include Predications
|
||||||
|
|
|
@ -24,7 +24,7 @@ module ActiveRelation
|
||||||
|
|
||||||
describe 'when relating an attribute and a value' do
|
describe 'when relating an attribute and a value' do
|
||||||
before do
|
before do
|
||||||
@value = "1-asdf".bind(@relation)
|
@value = "1-asdf"
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'when relating to an integer attribute' do
|
describe 'when relating to an integer attribute' do
|
||||||
|
@ -43,19 +43,6 @@ module ActiveRelation
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '==' do
|
describe '==' do
|
||||||
|
|
|
@ -35,7 +35,7 @@ module ActiveRelation
|
||||||
|
|
||||||
describe 'when relation to a nil value' do
|
describe 'when relation to a nil value' do
|
||||||
before do
|
before do
|
||||||
@nil = nil.bind(@relation1)
|
@nil = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it "manufactures an is null predicate" do
|
it "manufactures an is null predicate" do
|
||||||
|
|
|
@ -21,7 +21,7 @@ module ActiveRelation
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns self if the substituting to the same relation" do
|
it "returns self if the substituting to the same relation" do
|
||||||
@attribute.bind(@relation).should == @attribute
|
@attribute.should == @attribute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,43 +97,43 @@ module ActiveRelation
|
||||||
|
|
||||||
describe '#eq' do
|
describe '#eq' do
|
||||||
it "manufactures an equality predicate" 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
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#lt' do
|
describe '#lt' do
|
||||||
it "manufactures a less-than predicate" 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
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#lteq' do
|
describe '#lteq' do
|
||||||
it "manufactures a less-than or equal-to predicate" 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
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#gt' do
|
describe '#gt' do
|
||||||
it "manufactures a greater-than predicate" 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
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#gteq' do
|
describe '#gteq' do
|
||||||
it "manufactures a greater-than or equal-to predicate" 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
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#matches' do
|
describe '#matches' do
|
||||||
it "manufactures a match predicate" do
|
it "manufactures a match predicate" do
|
||||||
@attribute.matches(/.*/).should == Match.new(@attribute, /.*/.bind(@relation))
|
@attribute.matches(/.*/).should == Match.new(@attribute, /.*/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#in' do
|
describe '#in' do
|
||||||
it "manufactures an in predicate" 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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ ActiveRecord::Base.establish_connection 'test'
|
||||||
|
|
||||||
class Hash
|
class Hash
|
||||||
def shift
|
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)
|
delete(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue