aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations/attribute_spec.rb
blob: 78d602abf90f7655f8caa8ecaff12ab89559913d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Attribute do
  before do
    @relation1 = TableRelation.new(:foo)
    @relation2 = TableRelation.new(:bar)
  end
  
  describe '#eql?' do
    it "obtains if the relation and attribute name are identical" do
      Attribute.new(@relation1, :attribute_name).should be_eql(Attribute.new(@relation1, :attribute_name))
      Attribute.new(@relation1, :attribute_name).should_not be_eql(Attribute.new(@relation1, :another_attribute_name))
      Attribute.new(@relation1, :attribute_name).should_not be_eql(Attribute.new(@relation2, :attribute_name))
    end
  end
  
  describe 'predications' do
    before do
      @attribute1 = Attribute.new(@relation1, :attribute_name)
      @attribute2 = Attribute.new(@relation2, :attribute_name)
    end
    
    describe '==' do
      it "manufactures an equality predicate" do
        (@attribute1 == @attribute2).should == EqualityPredicate.new(@attribute1, @attribute2)
      end
    end
    
    describe '<' do
      it "manufactures a less-than predicate" do
        (@attribute1 < @attribute2).should == LessThanPredicate.new(@attribute1, @attribute2)
      end
    end
    
    describe '<=' do
      it "manufactures a less-than or equal-to predicate" do
        (@attribute1 <= @attribute2).should == LessThanOrEqualToPredicate.new(@attribute1, @attribute2)
      end
    end
    
    describe '>' do
      it "manufactures a greater-than predicate" do
        (@attribute1 > @attribute2).should == GreaterThanPredicate.new(@attribute1, @attribute2)
      end
    end
    
    describe '>=' do
      it "manufactures a greater-than or equal to predicate" do
        (@attribute1 >= @attribute2).should == GreaterThanOrEqualToPredicate.new(@attribute1, @attribute2)
      end
    end
    
    describe '=~' do
      it "manufactures a match predicate" do
        (@attribute1 =~ /.*/).should == MatchPredicate.new(@attribute1, @attribute2)
      end
    end
  end
  
  describe '#to_sql' do
    it "manufactures a column" do
      Attribute.new(@relation1, :attribute_name).to_sql.should == ColumnBuilder.new(@relation1.table, :attribute_name)
    end
  end
end