arel 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/arel.rb +4 -3
- data/lib/arel/algebra.rb +1 -1
- data/lib/arel/algebra/attributes.rb +7 -0
- data/lib/arel/algebra/{attribute.rb → attributes/attribute.rb} +32 -0
- data/lib/arel/algebra/attributes/boolean.rb +21 -0
- data/lib/arel/algebra/attributes/decimal.rb +9 -0
- data/lib/arel/algebra/attributes/float.rb +9 -0
- data/lib/arel/algebra/attributes/integer.rb +10 -0
- data/lib/arel/algebra/attributes/string.rb +10 -0
- data/lib/arel/algebra/attributes/time.rb +6 -0
- data/lib/arel/algebra/predicates.rb +1 -0
- data/lib/arel/algebra/relations/operations/join.rb +4 -2
- data/lib/arel/algebra/relations/operations/order.rb +2 -1
- data/lib/arel/algebra/relations/operations/skip.rb +2 -1
- data/lib/arel/algebra/relations/operations/take.rb +2 -1
- data/lib/arel/algebra/relations/operations/where.rb +7 -6
- data/lib/arel/algebra/relations/relation.rb +2 -1
- data/lib/arel/algebra/relations/utilities/compound.rb +22 -2
- data/lib/arel/algebra/relations/utilities/externalization.rb +1 -1
- data/lib/arel/algebra/relations/utilities/nil.rb +2 -2
- data/lib/arel/engines/memory/predicates.rb +6 -0
- data/lib/arel/engines/memory/relations/array.rb +11 -4
- data/lib/arel/engines/memory/relations/compound.rb +1 -1
- data/lib/arel/engines/memory/relations/operations.rb +2 -2
- data/lib/arel/engines/sql.rb +1 -0
- data/lib/arel/engines/sql/attributes.rb +40 -0
- data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +0 -14
- data/lib/arel/engines/sql/predicates.rb +4 -0
- data/lib/arel/engines/sql/primitives.rb +0 -4
- data/lib/arel/engines/sql/relations/compiler.rb +5 -5
- data/lib/arel/engines/sql/relations/operations/join.rb +1 -1
- data/lib/arel/engines/sql/relations/relation.rb +1 -1
- data/lib/arel/engines/sql/relations/table.rb +6 -7
- data/lib/arel/engines/sql/relations/utilities/compound.rb +1 -1
- data/lib/arel/engines/sql/relations/utilities/nil.rb +1 -1
- data/lib/arel/session.rb +2 -2
- data/lib/arel/version.rb +3 -0
- data/spec/{arel/algebra → algebra}/unit/predicates/binary_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/predicates/equality_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/predicates/in_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/primitives/attribute_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/primitives/expression_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/primitives/value_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/alias_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/delete_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/group_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/insert_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/join_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/order_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/project_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/relation_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/skip_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/table_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/take_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/update_spec.rb +0 -0
- data/spec/{arel/algebra → algebra}/unit/relations/where_spec.rb +1 -0
- data/spec/{arel/algebra → algebra}/unit/session/session_spec.rb +0 -0
- data/spec/attributes/boolean_spec.rb +57 -0
- data/spec/attributes/float_spec.rb +119 -0
- data/spec/attributes/integer_spec.rb +119 -0
- data/spec/attributes/string_spec.rb +43 -0
- data/spec/attributes/time_spec.rb +22 -0
- data/spec/{arel/engines → engines}/memory/integration/joins/cross_engine_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/array_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/insert_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/join_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/order_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/project_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/skip_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/take_spec.rb +1 -1
- data/spec/{arel/engines → engines}/memory/unit/relations/where_spec.rb +1 -1
- data/spec/{arel/engines → engines}/sql/integration/joins/with_adjacency_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/integration/joins/with_aggregations_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/integration/joins/with_compounds_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/engine_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/binary_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/equality_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/in_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/predicates/predicates_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/attribute_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/expression_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/literal_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/primitives/value_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/alias_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/delete_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/from_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/group_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/having_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/insert_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/join_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/lock_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/order_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/project_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/skip_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/table_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/take_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/update_spec.rb +0 -0
- data/spec/{arel/engines → engines}/sql/unit/relations/where_spec.rb +0 -0
- data/spec/relations/join_spec.rb +40 -0
- data/spec/relations/relation_spec.rb +31 -0
- data/spec/shared/relation_spec.rb +142 -0
- data/spec/spec_helper.rb +17 -45
- data/spec/support/check.rb +6 -0
- data/spec/{connections → support/connections}/mysql_connection.rb +2 -4
- data/spec/{connections → support/connections}/oracle_connection.rb +3 -5
- data/spec/{connections → support/connections}/postgresql_connection.rb +2 -4
- data/spec/{connections → support/connections}/sqlite3_connection.rb +2 -4
- data/spec/support/guards.rb +28 -0
- data/spec/support/matchers.rb +4 -0
- data/spec/{matchers → support/matchers}/be_like.rb +1 -1
- data/spec/{matchers → support/matchers}/disambiguate_attributes.rb +1 -1
- data/spec/{matchers → support/matchers}/hash_the_same_as.rb +1 -1
- data/spec/support/matchers/have_rows.rb +18 -0
- data/spec/support/model.rb +58 -0
- data/spec/{schemas → support/schemas}/mysql_schema.rb +0 -0
- data/spec/{schemas → support/schemas}/oracle_schema.rb +0 -0
- data/spec/{schemas → support/schemas}/postgresql_schema.rb +0 -0
- data/spec/{schemas → support/schemas}/sqlite3_schema.rb +0 -0
- metadata +107 -163
- data/.gitignore +0 -6
- data/.gitmodules +0 -3
- data/Rakefile +0 -48
- data/Thorfile +0 -124
- data/arel.gemspec +0 -258
- data/doc/CONVENTIONS +0 -17
- data/doc/TODO +0 -118
- data/spec/doubles/hash.rb +0 -27
- data/spec/spec.opts +0 -3
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
describe "Attributes::String" do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@relation = Model.build do |r|
|
9
|
+
r.engine Testing::Engine.new
|
10
|
+
r.attribute :name, Attributes::String
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def type_cast(val)
|
15
|
+
@relation[:name].type_cast(val)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#type_cast" do
|
19
|
+
it "returns same value if passed a String" do
|
20
|
+
val = "hell"
|
21
|
+
type_cast(val).should eql(val)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns nil if passed nil" do
|
25
|
+
type_cast(nil).should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns String representation of Symbol" do
|
29
|
+
type_cast(:hello).should == "hello"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns string representation of Integer" do
|
33
|
+
type_cast(1).should == '1'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "calls #to_s on arbitrary objects" do
|
37
|
+
obj = Object.new
|
38
|
+
obj.extend Module.new { def to_s ; 'hello' ; end }
|
39
|
+
type_cast(obj).should == 'hello'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
describe "Attributes::Time" do
|
6
|
+
|
7
|
+
before :all do
|
8
|
+
@relation = Model.build do |r|
|
9
|
+
r.engine Testing::Engine.new
|
10
|
+
r.attribute :created_at, Attributes::Time
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def type_cast(val)
|
15
|
+
@relation[:created_at].type_cast(val)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#type_cast" do
|
19
|
+
it "works"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -7,7 +7,7 @@ module Arel
|
|
7
7
|
[1, 'bryan' ],
|
8
8
|
[2, 'emilio' ],
|
9
9
|
[3, 'nick']
|
10
|
-
], [:id, :name])
|
10
|
+
], [[:id, Attributes::Integer], [:name, Attributes::String]])
|
11
11
|
@photos = Table.new(:photos)
|
12
12
|
@photos.delete
|
13
13
|
@photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Arel" do
|
4
|
+
before :all do
|
5
|
+
@owner = Arel::Model.build do |r|
|
6
|
+
r.engine Arel::Testing::Engine.new
|
7
|
+
|
8
|
+
r.attribute :id, Arel::Attributes::Integer
|
9
|
+
end
|
10
|
+
|
11
|
+
@thing = Arel::Model.build do |r|
|
12
|
+
r.engine Arel::Testing::Engine.new
|
13
|
+
|
14
|
+
r.attribute :id, Arel::Attributes::Integer
|
15
|
+
r.attribute :owner_id, Arel::Attributes::Integer
|
16
|
+
r.attribute :age, Arel::Attributes::Integer
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "Join" do
|
21
|
+
before :all do
|
22
|
+
@relation = @thing.join(@owner).on(@thing[:owner_id].eq(@owner[:id]))
|
23
|
+
@expected = []
|
24
|
+
|
25
|
+
3.times do |owner_id|
|
26
|
+
@owner.insert([owner_id])
|
27
|
+
|
28
|
+
8.times do |i|
|
29
|
+
thing_id = owner_id * 8 + i
|
30
|
+
age = 2 * thing_id
|
31
|
+
|
32
|
+
@thing.insert([thing_id, owner_id, age])
|
33
|
+
@expected << Arel::Row.new(@relation, [thing_id, owner_id, age, owner_id])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it_should_behave_like 'A Relation'
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Arel" do
|
4
|
+
before :all do
|
5
|
+
@engine = Arel::Testing::Engine.new
|
6
|
+
@relation = Arel::Model.build do |r|
|
7
|
+
r.engine @engine
|
8
|
+
|
9
|
+
r.attribute :id, Arel::Attributes::Integer
|
10
|
+
r.attribute :name, Arel::Attributes::String
|
11
|
+
r.attribute :age, Arel::Attributes::Integer
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Relation" do
|
16
|
+
before :all do
|
17
|
+
@expected = (1..20).map { |i| @relation.insert([i, nil, 2 * i]) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it_should_behave_like 'A Relation'
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "Relation" do
|
24
|
+
describe "#insert" do
|
25
|
+
it "inserts the row into the engine" do
|
26
|
+
@relation.insert([1, 'Foo', 10])
|
27
|
+
@engine.rows.should == [[1, 'Foo', 10]]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
share_examples_for 'A Relation' do
|
2
|
+
|
3
|
+
before :all do
|
4
|
+
# The two needed instance variables need to be set in a
|
5
|
+
# before :all callback.
|
6
|
+
# @relation is the relation being tested here.
|
7
|
+
# @expected is an array of the elements that are expected to be in
|
8
|
+
# the relation.
|
9
|
+
%w[ @relation @expected ].each do |ivar|
|
10
|
+
raise "#{ivar} needs to be defined" unless instance_variable_get(ivar)
|
11
|
+
end
|
12
|
+
|
13
|
+
# There needs to be enough items to be able to run all the tests
|
14
|
+
raise "@expected needs to have at least 6 items" unless @expected.length >= 6
|
15
|
+
end
|
16
|
+
|
17
|
+
before :each do
|
18
|
+
@expected = @expected.dup
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#each" do
|
22
|
+
it "iterates over the rows in any order" do
|
23
|
+
@relation.should have_rows(@expected)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#where" do
|
28
|
+
before :all do
|
29
|
+
@expected = @expected.sort_by { |r| r[@relation[:age]] }
|
30
|
+
@pivot = @expected[@expected.length / 2]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "finds rows with an equal to predicate" do
|
34
|
+
expected = @expected.select { |r| r[@relation[:age]] == @pivot[@relation[:age]] }
|
35
|
+
@relation.where(@relation[:age].eq(@pivot[@relation[:age]])).should have_rows(expected)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "finds rows with a not predicate" do
|
39
|
+
expected = @expected.select { |r| r[@relation[:age]] != @pivot[@relation[:age]] }
|
40
|
+
@relation.where(@relation[:age].not(@pivot[@relation[:age]])).should have_rows(expected)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "finds rows with a less than predicate" do
|
44
|
+
expected = @expected.select { |r| r[@relation[:age]] < @pivot[@relation[:age]] }
|
45
|
+
@relation.where(@relation[:age].lt(@pivot[@relation[:age]])).should have_rows(expected)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "finds rows with a less than or equal to predicate" do
|
49
|
+
expected = @expected.select { |r| r[@relation[:age]] <= @pivot[@relation[:age]] }
|
50
|
+
@relation.where(@relation[:age].lteq(@pivot[@relation[:age]])).should have_rows(expected)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "finds rows with a greater than predicate" do
|
54
|
+
expected = @expected.select { |r| r[@relation[:age]] > @pivot[@relation[:age]] }
|
55
|
+
@relation.where(@relation[:age].gt(@pivot[@relation[:age]])).should have_rows(expected)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "finds rows with a greater than or equal to predicate" do
|
59
|
+
expected = @expected.select { |r| r[@relation[:age]] >= @pivot[@relation[:age]] }
|
60
|
+
@relation.where(@relation[:age].gteq(@pivot[@relation[:age]])).should have_rows(expected)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "finds rows with a matches predicate"
|
64
|
+
|
65
|
+
it "finds rows with an in predicate" do
|
66
|
+
pending
|
67
|
+
set = @expected[1..(@expected.length/2+1)]
|
68
|
+
@relation.all(:id.in => set.map { |r| r.id }).should have_resources(set)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#order" do
|
73
|
+
describe "by one attribute" do
|
74
|
+
before :all do
|
75
|
+
@expected.map! { |r| r[@relation[:age]] }
|
76
|
+
@expected.sort!
|
77
|
+
end
|
78
|
+
|
79
|
+
it "can be specified as ascending order" do
|
80
|
+
actual = []
|
81
|
+
@relation.order(@relation[:age].asc).each { |r| actual << r[@relation[:age]] }
|
82
|
+
actual.should == @expected
|
83
|
+
end
|
84
|
+
|
85
|
+
it "can be specified as descending order" do
|
86
|
+
actual = []
|
87
|
+
@relation.order(@relation[:age].desc).each { |r| actual << r[@relation[:age]] }
|
88
|
+
actual.should == @expected.reverse
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "by two attributes" do
|
93
|
+
it "works"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "#take" do
|
98
|
+
it "returns a relation" do
|
99
|
+
@relation.take(3).should be_a(Arel::Relation)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "returns X items from the collection" do
|
103
|
+
length = @expected.length
|
104
|
+
|
105
|
+
@relation.take(3).each do |resource|
|
106
|
+
@expected.delete_if { |r| r.tuple == resource.tuple }
|
107
|
+
end
|
108
|
+
|
109
|
+
@expected.length.should == length - 3
|
110
|
+
end
|
111
|
+
|
112
|
+
it "works with ordering" do
|
113
|
+
expected = @expected.sort_by { |r| [r[@relation[:age]], r[@relation[:id]]] }.map { |r| r[@relation[:id]] }
|
114
|
+
actual = @relation.order(@relation[:age].asc, @relation[:id].asc).take(3).map { |r| r[@relation[:id]] }
|
115
|
+
|
116
|
+
actual.should == expected[0,3]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#skip" do
|
121
|
+
it "returns a relation" do
|
122
|
+
@relation.skip(3).should be_a(Arel::Relation)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "skips X items from the collection" do
|
126
|
+
length = @expected.length
|
127
|
+
|
128
|
+
@relation.skip(3).each do |resource|
|
129
|
+
@expected.delete_if { |r| r.tuple == resource.tuple }
|
130
|
+
end
|
131
|
+
|
132
|
+
@expected.length.should == 3
|
133
|
+
end
|
134
|
+
|
135
|
+
it "works with ordering" do
|
136
|
+
expected = @expected.sort_by { |r| [r[@relation[:age]], r[@relation[:id]]] }.map { |r| r[@relation[:id]] }
|
137
|
+
actual = @relation.order(@relation[:age].asc, @relation[:id].asc).skip(3).map { |r| r[@relation[:id]] }
|
138
|
+
|
139
|
+
actual.should == expected[3..-1]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,58 +7,30 @@ require 'pp'
|
|
7
7
|
require 'fileutils'
|
8
8
|
require 'arel'
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
module AdapterGuards
|
15
|
-
def adapter_is(*names)
|
16
|
-
names = names.map(&:to_s)
|
17
|
-
names.each{|name| verify_adapter_name(name)}
|
18
|
-
yield if names.include? adapter_name
|
19
|
-
end
|
20
|
-
|
21
|
-
def adapter_is_not(*names)
|
22
|
-
names = names.map(&:to_s)
|
23
|
-
names.each{|name| verify_adapter_name(name)}
|
24
|
-
yield unless names.include? adapter_name
|
25
|
-
end
|
26
|
-
|
27
|
-
def adapter_name
|
28
|
-
name = ActiveRecord::Base.configurations["unit"][:adapter]
|
29
|
-
name = 'oracle' if name == 'oracle_enhanced'
|
30
|
-
verify_adapter_name(name)
|
31
|
-
name
|
32
|
-
end
|
33
|
-
|
34
|
-
def verify_adapter_name(name)
|
35
|
-
raise "Invalid adapter name: #{name}" unless valid_adapters.include?(name.to_s)
|
36
|
-
end
|
37
|
-
|
38
|
-
def valid_adapters
|
39
|
-
%w[mysql postgresql sqlite3 oracle]
|
40
|
-
end
|
10
|
+
if adapter = ENV['ADAPTER']
|
11
|
+
require "support/connections/#{adapter}_connection.rb"
|
41
12
|
end
|
42
13
|
|
43
|
-
|
44
|
-
|
45
|
-
# See: https://rspec.lighthouseapp.com/projects/5645/tickets/504
|
46
|
-
def check(*args)
|
47
|
-
end
|
14
|
+
Dir["#{dir}/{support,shared}/*.rb"].each do |file|
|
15
|
+
require file
|
48
16
|
end
|
49
17
|
|
50
18
|
Spec::Runner.configure do |config|
|
51
|
-
config.include
|
19
|
+
config.include Matchers
|
52
20
|
config.include AdapterGuards
|
53
21
|
config.include Check
|
54
22
|
|
55
|
-
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
23
|
+
if defined?(ActiveRecord::Base)
|
24
|
+
tmp = File.expand_path('../../tmp', __FILE__)
|
59
25
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
26
|
+
FileUtils.mkdir_p(tmp)
|
27
|
+
ActiveRecord::Base.logger = Logger.new("#{tmp}/debug.log")
|
28
|
+
ActiveRecord::Base.establish_connection("unit")
|
29
|
+
|
30
|
+
require "support/schemas/#{ENV['ADAPTER']}_schema.rb"
|
31
|
+
|
32
|
+
config.before do
|
33
|
+
Arel::Table.engine = Arel::Sql::Engine.new(ActiveRecord::Base)
|
34
|
+
end
|
35
|
+
end
|
64
36
|
end
|