aboutsummaryrefslogtreecommitdiffstats
path: root/spec/engines/sql/unit/primitives/attribute_spec.rb
blob: c467d902ad4df02bd24da4eeba59fcb5c6add013 (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
require 'spec_helper'

module Arel
  describe Attribute do
    before do
      @relation = Table.new(:users)
      @attribute = @relation[:id]
    end

    describe '#column' do
      it "returns the corresponding column in the relation" do
        @attribute.column.should == @relation.column_for(@attribute)
      end
    end

    describe '#to_sql' do
      describe 'for a simple attribute' do
        it "manufactures sql with an alias" do
          sql = @attribute.to_sql

          adapter_is :mysql do
            sql.should be_like(%Q{`users`.`id`})
          end

          adapter_is :oracle do
            sql.should be_like(%Q{"USERS"."ID"})
          end

          adapter_is_not :mysql, :oracle do
            sql.should be_like(%Q{"users"."id"})
          end
        end
      end

      describe 'for an inexistent attribute' do
        it "manufactures sql" do
          sql = @relation[:does_not_exist].to_sql

          adapter_is :mysql do
            sql.should be_like(%Q{`users`.`does_not_exist`})
          end

          adapter_is :oracle do
            sql.should be_like(%Q{"USERS"."DOEST_NOT_EXIST"})
          end

          adapter_is_not :mysql, :oracle do
            sql.should be_like(%Q{"users"."does_not_exist"})
          end
        end
      end

    end
  end
end