1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/spec/relations/attribute_spec.rb

91 lines
2.6 KiB
Ruby
Raw Normal View History

2007-12-30 14:35:44 -05:00
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe Attribute do
before do
@relation1 = TableRelation.new(:foo)
@relation2 = TableRelation.new(:bar)
end
2008-01-05 18:24:46 -05:00
describe '#aliazz' do
2008-01-05 16:00:39 -05:00
it "manufactures an aliased attributed" do
pending
end
2008-01-05 18:24:46 -05:00
it "should be renamed to #alias!" do
pending
@relation1.alias
end
end
describe '#qualified_name' do
it "manufactures an attribute name prefixed with the relation's name" do
@relation1[:id].qualified_name.should == 'foo.id'
end
end
describe '#qualify' do
it "manufactures an attribute aliased with that attributes qualified name" do
@relation1[:id].qualify == @relation1[:id].qualify
end
2008-01-05 16:00:39 -05:00
end
2007-12-31 02:59:29 -05:00
describe '#eql?' do
2007-12-30 14:35:44 -05:00
it "obtains if the relation and attribute name are identical" do
2008-01-05 18:24:46 -05:00
Attribute.new(@relation1, :name).should be_eql(Attribute.new(@relation1, :name))
Attribute.new(@relation1, :name).should_not be_eql(Attribute.new(@relation1, :another_name))
Attribute.new(@relation1, :name).should_not be_eql(Attribute.new(@relation2, :name))
2007-12-30 14:35:44 -05:00
end
end
2007-12-31 02:59:29 -05:00
describe 'predications' do
2007-12-30 14:35:44 -05:00
before do
2008-01-05 18:24:46 -05:00
@attribute1 = Attribute.new(@relation1, :name)
@attribute2 = Attribute.new(@relation2, :name)
2007-12-30 14:35:44 -05:00
end
2007-12-31 02:59:29 -05:00
describe '==' do
2007-12-30 14:35:44 -05:00
it "manufactures an equality predicate" do
(@attribute1 == @attribute2).should == EqualityPredicate.new(@attribute1, @attribute2)
end
end
2007-12-31 02:59:29 -05:00
describe '<' do
2007-12-30 14:35:44 -05:00
it "manufactures a less-than predicate" do
(@attribute1 < @attribute2).should == LessThanPredicate.new(@attribute1, @attribute2)
end
end
2007-12-31 02:59:29 -05:00
describe '<=' do
2007-12-30 14:35:44 -05:00
it "manufactures a less-than or equal-to predicate" do
(@attribute1 <= @attribute2).should == LessThanOrEqualToPredicate.new(@attribute1, @attribute2)
end
end
2007-12-31 02:59:29 -05:00
describe '>' do
2007-12-30 14:35:44 -05:00
it "manufactures a greater-than predicate" do
(@attribute1 > @attribute2).should == GreaterThanPredicate.new(@attribute1, @attribute2)
end
end
2007-12-31 02:59:29 -05:00
describe '>=' do
2007-12-30 14:35:44 -05:00
it "manufactures a greater-than or equal to predicate" do
(@attribute1 >= @attribute2).should == GreaterThanOrEqualToPredicate.new(@attribute1, @attribute2)
end
end
2007-12-31 02:59:29 -05:00
describe '=~' do
2007-12-30 14:35:44 -05:00
it "manufactures a match predicate" do
(@attribute1 =~ /.*/).should == MatchPredicate.new(@attribute1, @attribute2)
end
end
2007-12-31 02:59:29 -05:00
end
describe '#to_sql' do
it "manufactures a column" do
2008-01-05 18:24:46 -05:00
Attribute.new(@relation1, :name, :alias).to_sql.should == SelectsBuilder.new do
column :foo, :name, :alias
2008-01-01 19:44:33 -05:00
end
2007-12-31 02:59:29 -05:00
end
2007-12-30 14:35:44 -05:00
end
end