arel-compat 0.4.0

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.
Files changed (164) hide show
  1. data/History.txt +25 -0
  2. data/README.markdown +182 -0
  3. data/lib/arel.rb +13 -0
  4. data/lib/arel/algebra.rb +10 -0
  5. data/lib/arel/algebra/attributes.rb +7 -0
  6. data/lib/arel/algebra/attributes/attribute.rb +270 -0
  7. data/lib/arel/algebra/attributes/boolean.rb +21 -0
  8. data/lib/arel/algebra/attributes/decimal.rb +9 -0
  9. data/lib/arel/algebra/attributes/float.rb +9 -0
  10. data/lib/arel/algebra/attributes/integer.rb +10 -0
  11. data/lib/arel/algebra/attributes/string.rb +10 -0
  12. data/lib/arel/algebra/attributes/time.rb +6 -0
  13. data/lib/arel/algebra/core_extensions.rb +4 -0
  14. data/lib/arel/algebra/core_extensions/class.rb +32 -0
  15. data/lib/arel/algebra/core_extensions/hash.rb +11 -0
  16. data/lib/arel/algebra/core_extensions/object.rb +30 -0
  17. data/lib/arel/algebra/core_extensions/symbol.rb +9 -0
  18. data/lib/arel/algebra/expression.rb +43 -0
  19. data/lib/arel/algebra/header.rb +67 -0
  20. data/lib/arel/algebra/ordering.rb +23 -0
  21. data/lib/arel/algebra/predicates.rb +190 -0
  22. data/lib/arel/algebra/relations.rb +17 -0
  23. data/lib/arel/algebra/relations/operations/alias.rb +7 -0
  24. data/lib/arel/algebra/relations/operations/from.rb +6 -0
  25. data/lib/arel/algebra/relations/operations/group.rb +12 -0
  26. data/lib/arel/algebra/relations/operations/having.rb +17 -0
  27. data/lib/arel/algebra/relations/operations/join.rb +69 -0
  28. data/lib/arel/algebra/relations/operations/lock.rb +12 -0
  29. data/lib/arel/algebra/relations/operations/order.rb +19 -0
  30. data/lib/arel/algebra/relations/operations/project.rb +20 -0
  31. data/lib/arel/algebra/relations/operations/skip.rb +7 -0
  32. data/lib/arel/algebra/relations/operations/take.rb +11 -0
  33. data/lib/arel/algebra/relations/operations/where.rb +17 -0
  34. data/lib/arel/algebra/relations/relation.rb +136 -0
  35. data/lib/arel/algebra/relations/row.rb +26 -0
  36. data/lib/arel/algebra/relations/utilities/compound.rb +54 -0
  37. data/lib/arel/algebra/relations/utilities/externalization.rb +24 -0
  38. data/lib/arel/algebra/relations/utilities/nil.rb +7 -0
  39. data/lib/arel/algebra/relations/writes.rb +36 -0
  40. data/lib/arel/algebra/value.rb +14 -0
  41. data/lib/arel/engines.rb +2 -0
  42. data/lib/arel/engines/memory.rb +4 -0
  43. data/lib/arel/engines/memory/engine.rb +16 -0
  44. data/lib/arel/engines/memory/predicates.rb +99 -0
  45. data/lib/arel/engines/memory/primitives.rb +27 -0
  46. data/lib/arel/engines/memory/relations.rb +5 -0
  47. data/lib/arel/engines/memory/relations/array.rb +35 -0
  48. data/lib/arel/engines/memory/relations/compound.rb +9 -0
  49. data/lib/arel/engines/memory/relations/operations.rb +67 -0
  50. data/lib/arel/engines/memory/relations/writes.rb +7 -0
  51. data/lib/arel/engines/sql.rb +8 -0
  52. data/lib/arel/engines/sql/attributes.rb +40 -0
  53. data/lib/arel/engines/sql/christener.rb +14 -0
  54. data/lib/arel/engines/sql/compilers/ibm_db_compiler.rb +48 -0
  55. data/lib/arel/engines/sql/compilers/mysql_compiler.rb +11 -0
  56. data/lib/arel/engines/sql/compilers/oracle_compiler.rb +95 -0
  57. data/lib/arel/engines/sql/compilers/postgresql_compiler.rb +42 -0
  58. data/lib/arel/engines/sql/compilers/sqlite_compiler.rb +9 -0
  59. data/lib/arel/engines/sql/core_extensions.rb +4 -0
  60. data/lib/arel/engines/sql/core_extensions/array.rb +24 -0
  61. data/lib/arel/engines/sql/core_extensions/nil_class.rb +15 -0
  62. data/lib/arel/engines/sql/core_extensions/object.rb +19 -0
  63. data/lib/arel/engines/sql/core_extensions/range.rb +19 -0
  64. data/lib/arel/engines/sql/engine.rb +55 -0
  65. data/lib/arel/engines/sql/formatters.rb +122 -0
  66. data/lib/arel/engines/sql/predicates.rb +103 -0
  67. data/lib/arel/engines/sql/primitives.rb +97 -0
  68. data/lib/arel/engines/sql/relations.rb +10 -0
  69. data/lib/arel/engines/sql/relations/compiler.rb +118 -0
  70. data/lib/arel/engines/sql/relations/operations/alias.rb +5 -0
  71. data/lib/arel/engines/sql/relations/operations/join.rb +33 -0
  72. data/lib/arel/engines/sql/relations/relation.rb +65 -0
  73. data/lib/arel/engines/sql/relations/table.rb +88 -0
  74. data/lib/arel/engines/sql/relations/utilities/compound.rb +10 -0
  75. data/lib/arel/engines/sql/relations/utilities/externalization.rb +14 -0
  76. data/lib/arel/engines/sql/relations/utilities/nil.rb +6 -0
  77. data/lib/arel/engines/sql/relations/utilities/recursion.rb +13 -0
  78. data/lib/arel/engines/sql/relations/writes.rb +19 -0
  79. data/lib/arel/session.rb +51 -0
  80. data/lib/arel/version.rb +3 -0
  81. data/spec/algebra/unit/predicates/binary_spec.rb +35 -0
  82. data/spec/algebra/unit/predicates/equality_spec.rb +29 -0
  83. data/spec/algebra/unit/predicates/in_spec.rb +12 -0
  84. data/spec/algebra/unit/primitives/attribute_spec.rb +181 -0
  85. data/spec/algebra/unit/primitives/expression_spec.rb +45 -0
  86. data/spec/algebra/unit/primitives/value_spec.rb +15 -0
  87. data/spec/algebra/unit/relations/alias_spec.rb +16 -0
  88. data/spec/algebra/unit/relations/delete_spec.rb +9 -0
  89. data/spec/algebra/unit/relations/group_spec.rb +10 -0
  90. data/spec/algebra/unit/relations/insert_spec.rb +9 -0
  91. data/spec/algebra/unit/relations/join_spec.rb +25 -0
  92. data/spec/algebra/unit/relations/order_spec.rb +21 -0
  93. data/spec/algebra/unit/relations/project_spec.rb +34 -0
  94. data/spec/algebra/unit/relations/relation_spec.rb +187 -0
  95. data/spec/algebra/unit/relations/skip_spec.rb +10 -0
  96. data/spec/algebra/unit/relations/table_spec.rb +38 -0
  97. data/spec/algebra/unit/relations/take_spec.rb +10 -0
  98. data/spec/algebra/unit/relations/update_spec.rb +9 -0
  99. data/spec/algebra/unit/relations/where_spec.rb +19 -0
  100. data/spec/algebra/unit/session/session_spec.rb +84 -0
  101. data/spec/attributes/boolean_spec.rb +57 -0
  102. data/spec/attributes/float_spec.rb +119 -0
  103. data/spec/attributes/header_spec.rb +42 -0
  104. data/spec/attributes/integer_spec.rb +119 -0
  105. data/spec/attributes/string_spec.rb +43 -0
  106. data/spec/attributes/time_spec.rb +24 -0
  107. data/spec/engines/memory/integration/joins/cross_engine_spec.rb +51 -0
  108. data/spec/engines/memory/unit/relations/array_spec.rb +32 -0
  109. data/spec/engines/memory/unit/relations/insert_spec.rb +28 -0
  110. data/spec/engines/memory/unit/relations/join_spec.rb +31 -0
  111. data/spec/engines/memory/unit/relations/order_spec.rb +27 -0
  112. data/spec/engines/memory/unit/relations/project_spec.rb +27 -0
  113. data/spec/engines/memory/unit/relations/skip_spec.rb +26 -0
  114. data/spec/engines/memory/unit/relations/take_spec.rb +26 -0
  115. data/spec/engines/memory/unit/relations/where_spec.rb +39 -0
  116. data/spec/engines/sql/integration/joins/with_adjacency_spec.rb +258 -0
  117. data/spec/engines/sql/integration/joins/with_aggregations_spec.rb +221 -0
  118. data/spec/engines/sql/integration/joins/with_compounds_spec.rb +137 -0
  119. data/spec/engines/sql/unit/engine_spec.rb +45 -0
  120. data/spec/engines/sql/unit/predicates/binary_spec.rb +140 -0
  121. data/spec/engines/sql/unit/predicates/equality_spec.rb +75 -0
  122. data/spec/engines/sql/unit/predicates/in_spec.rb +179 -0
  123. data/spec/engines/sql/unit/predicates/noteq_spec.rb +75 -0
  124. data/spec/engines/sql/unit/predicates/predicates_spec.rb +79 -0
  125. data/spec/engines/sql/unit/primitives/attribute_spec.rb +36 -0
  126. data/spec/engines/sql/unit/primitives/expression_spec.rb +28 -0
  127. data/spec/engines/sql/unit/primitives/literal_spec.rb +43 -0
  128. data/spec/engines/sql/unit/primitives/value_spec.rb +29 -0
  129. data/spec/engines/sql/unit/relations/alias_spec.rb +53 -0
  130. data/spec/engines/sql/unit/relations/delete_spec.rb +83 -0
  131. data/spec/engines/sql/unit/relations/from_spec.rb +64 -0
  132. data/spec/engines/sql/unit/relations/group_spec.rb +72 -0
  133. data/spec/engines/sql/unit/relations/having_spec.rb +78 -0
  134. data/spec/engines/sql/unit/relations/insert_spec.rb +143 -0
  135. data/spec/engines/sql/unit/relations/join_spec.rb +180 -0
  136. data/spec/engines/sql/unit/relations/lock_spec.rb +86 -0
  137. data/spec/engines/sql/unit/relations/order_spec.rb +161 -0
  138. data/spec/engines/sql/unit/relations/project_spec.rb +143 -0
  139. data/spec/engines/sql/unit/relations/skip_spec.rb +41 -0
  140. data/spec/engines/sql/unit/relations/table_spec.rb +129 -0
  141. data/spec/engines/sql/unit/relations/take_spec.rb +49 -0
  142. data/spec/engines/sql/unit/relations/update_spec.rb +203 -0
  143. data/spec/engines/sql/unit/relations/where_spec.rb +72 -0
  144. data/spec/relations/join_spec.rb +42 -0
  145. data/spec/relations/relation_spec.rb +31 -0
  146. data/spec/shared/relation_spec.rb +255 -0
  147. data/spec/spec_helper.rb +36 -0
  148. data/spec/support/check.rb +6 -0
  149. data/spec/support/connections/mysql_connection.rb +14 -0
  150. data/spec/support/connections/oracle_connection.rb +17 -0
  151. data/spec/support/connections/postgresql_connection.rb +13 -0
  152. data/spec/support/connections/sqlite3_connection.rb +24 -0
  153. data/spec/support/guards.rb +28 -0
  154. data/spec/support/matchers.rb +4 -0
  155. data/spec/support/matchers/be_like.rb +24 -0
  156. data/spec/support/matchers/disambiguate_attributes.rb +28 -0
  157. data/spec/support/matchers/hash_the_same_as.rb +26 -0
  158. data/spec/support/matchers/have_rows.rb +18 -0
  159. data/spec/support/model.rb +62 -0
  160. data/spec/support/schemas/mysql_schema.rb +26 -0
  161. data/spec/support/schemas/oracle_schema.rb +20 -0
  162. data/spec/support/schemas/postgresql_schema.rb +26 -0
  163. data/spec/support/schemas/sqlite3_schema.rb +26 -0
  164. metadata +258 -0
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ module Arel
4
+ describe "Attributes::Boolean" do
5
+
6
+ before :all do
7
+ @relation = Model.build do |r|
8
+ r.engine Testing::Engine.new
9
+ r.attribute :awesome, Attributes::Boolean
10
+ end
11
+ end
12
+
13
+ def type_cast(val)
14
+ @relation[:awesome].type_cast(val)
15
+ end
16
+
17
+ describe "#type_cast" do
18
+ it "returns same value if passed a boolean" do
19
+ val = true
20
+ type_cast(val).should eql(val)
21
+ end
22
+
23
+ it "returns boolean representation (false) of nil" do
24
+ type_cast(nil).should eql(false)
25
+ end
26
+
27
+ it "returns boolean representation of 'true', 'false'" do
28
+ type_cast('true').should eql(true)
29
+ type_cast('false').should eql(false)
30
+ end
31
+
32
+ it "returns boolean representation of :true, :false" do
33
+ type_cast(:true).should eql(true)
34
+ type_cast(:false).should eql(false)
35
+ end
36
+
37
+ it "returns boolean representation of 0, 1" do
38
+ type_cast(1).should == true
39
+ type_cast(0).should == false
40
+ end
41
+
42
+ it "calls #to_s on arbitrary objects" do
43
+ obj = Object.new
44
+ obj.extend Module.new { def to_s ; 'true' ; end }
45
+ type_cast(obj).should == true
46
+ end
47
+
48
+ [ Object.new, 'string', '00.0', 5 ].each do |value|
49
+ it "raises exception when attempting type_cast of non-boolean value #{value.inspect}" do
50
+ lambda do
51
+ type_cast(value)
52
+ end.should raise_error(TypecastError, /could not typecast/)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ require 'bigdecimal'
3
+
4
+ module Arel
5
+ describe "Attributes::Float" do
6
+
7
+ before :all do
8
+ @relation = Model.build do |r|
9
+ r.engine Testing::Engine.new
10
+ r.attribute :percentage, Attributes::Float
11
+ end
12
+ end
13
+
14
+ def type_cast(val)
15
+ @relation[:percentage].type_cast(val)
16
+ end
17
+
18
+ describe "#type_cast" do
19
+ it "returns same value if an float" do
20
+ type_cast(24.01).should eql(24.01)
21
+ end
22
+
23
+ it "returns nil if passed nil" do
24
+ type_cast(nil).should be_nil
25
+ end
26
+
27
+ it "returns nil if passed empty string" do
28
+ type_cast('').should be_nil
29
+ end
30
+
31
+ it "returns float representation of a zero string float" do
32
+ type_cast('0').should eql(0.0)
33
+ end
34
+
35
+ it "returns float representation of a positive string integer" do
36
+ type_cast('24').should eql(24.0)
37
+ end
38
+
39
+ it "returns float representation of a positive string integer with spaces" do
40
+ type_cast(' 24').should eql(24.0)
41
+ type_cast('24 ').should eql(24.0)
42
+ end
43
+
44
+ it "returns float representation of a negative string float" do
45
+ type_cast('-24.23').should eql(-24.23)
46
+ end
47
+
48
+ it "returns float representation of a negative string integer with spaces" do
49
+ type_cast('-24 ').should eql(-24.0)
50
+ type_cast(' -24').should eql(-24.0)
51
+ end
52
+
53
+ it "returns integer representation of a zero string float" do
54
+ type_cast('0.0').should eql(0.0)
55
+ end
56
+
57
+ it "returns integer representation of a positive string float" do
58
+ type_cast('24.35').should eql(24.35)
59
+ end
60
+
61
+ it "returns integer representation of a positive string float with spaces" do
62
+ type_cast(' 24.35').should eql(24.35)
63
+ type_cast('24.35 ').should eql(24.35)
64
+ end
65
+
66
+ it "returns integer representation of a negative string float" do
67
+ type_cast('-24.35').should eql(-24.35)
68
+ end
69
+
70
+ it "returns integer representation of a negative string float with spaces" do
71
+ type_cast(' -24.35 ').should eql(-24.35)
72
+ end
73
+
74
+ it "returns integer representation of a zero string float, with no leading digits" do
75
+ type_cast('.0').should eql(0.0)
76
+ end
77
+
78
+ it "returns integer representation of a zero string float, with no leading digits with spaces" do
79
+ type_cast(' .0').should eql(0.0)
80
+ end
81
+
82
+ it "returns integer representation of a positive string float, with no leading digits" do
83
+ type_cast('.41').should eql(0.41)
84
+ end
85
+
86
+ it "returns integer representation of a zero float" do
87
+ type_cast(0.0).should eql(0.0)
88
+ end
89
+
90
+ it "returns integer representation of a positive float" do
91
+ type_cast(24.35).should eql(24.35)
92
+ end
93
+
94
+ it "returns integer representation of a negative float" do
95
+ type_cast(-24.35).should eql(-24.35)
96
+ end
97
+
98
+ it "returns integer representation of a zero decimal" do
99
+ type_cast(BigDecimal('0.0')).should eql(0.0)
100
+ end
101
+
102
+ it "returns integer representation of a positive decimal" do
103
+ type_cast(BigDecimal('24.35')).should eql(24.35)
104
+ end
105
+
106
+ it "returns integer representation of a negative decimal" do
107
+ type_cast(BigDecimal('-24.35')).should eql(-24.35)
108
+ end
109
+
110
+ [ Object.new, true, '00.0', '0.', 'string' ].each do |value|
111
+ it "raises exception when attempting type_cast of non-numeric value #{value.inspect}" do
112
+ lambda do
113
+ type_cast(value)
114
+ end.should raise_error(TypecastError, /could not typecast/)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ module Arel
4
+ describe "Header" do
5
+ before :all do
6
+ @relation = Model.build do |r|
7
+ r.attribute :id, Attributes::Integer
8
+ r.attribute :name, Attributes::String
9
+ r.attribute :age, Attributes::Integer
10
+ end
11
+
12
+ @other = Model.build do |r|
13
+ r.attribute :foo, Attributes::String
14
+ end
15
+
16
+ @subset = Model.build do |r|
17
+ r.attribute :id, Attributes::Integer
18
+ end
19
+ end
20
+
21
+ describe "attribute lookup" do
22
+ it "finds attributes by name" do
23
+ @relation.attributes[:name].should == Attributes::String.new(@relation, :name)
24
+ end
25
+
26
+ it "returns nil if no attribute is found" do
27
+ @relation.attributes[:does_not_exist].should be_nil
28
+ @relation[:does_not_exist].should be_nil
29
+ end
30
+ end
31
+
32
+ describe "#union" do
33
+ it "keeps all attributes from disjoint headers" do
34
+ (@relation.attributes.union @other.attributes).to_ary.should have(4).items
35
+ end
36
+
37
+ it "keeps all attributes from both relations even if they seem like subsets" do
38
+ (@relation.attributes.union @subset.attributes).to_ary.should have(4).items
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ require 'bigdecimal'
3
+
4
+ module Arel
5
+ describe "Attributes::Integer" do
6
+
7
+ before :all do
8
+ @relation = Model.build do |r|
9
+ r.engine Testing::Engine.new
10
+ r.attribute :age, Attributes::Integer
11
+ end
12
+ end
13
+
14
+ def type_cast(val)
15
+ @relation[:age].type_cast(val)
16
+ end
17
+
18
+ describe "#type_cast" do
19
+ it "returns same value if an integer" do
20
+ type_cast(24).should eql(24)
21
+ end
22
+
23
+ it "returns nil if passed nil" do
24
+ type_cast(nil).should be_nil
25
+ end
26
+
27
+ it "returns nil if passed empty string" do
28
+ type_cast('').should be_nil
29
+ end
30
+
31
+ it "returns integer representation of a zero string integer" do
32
+ type_cast('0').should eql(0)
33
+ end
34
+
35
+ it "returns integer representation of a positive string integer" do
36
+ type_cast('24').should eql(24)
37
+ end
38
+
39
+ it "returns integer representation of a positive string integer with spaces" do
40
+ type_cast(' 24').should eql(24)
41
+ type_cast('24 ').should eql(24)
42
+ end
43
+
44
+ it "returns integer representation of a negative string integer" do
45
+ type_cast('-24').should eql(-24)
46
+ end
47
+
48
+ it "returns integer representation of a negative string integer with spaces" do
49
+ type_cast('-24 ').should eql(-24)
50
+ type_cast(' -24').should eql(-24)
51
+ end
52
+
53
+ it "returns integer representation of a zero string float" do
54
+ type_cast('0.0').should eql(0)
55
+ end
56
+
57
+ it "returns integer representation of a positive string float" do
58
+ type_cast('24.35').should eql(24)
59
+ end
60
+
61
+ it "returns integer representation of a positive string float with spaces" do
62
+ type_cast(' 24.35').should eql(24)
63
+ type_cast('24.35 ').should eql(24)
64
+ end
65
+
66
+ it "returns integer representation of a negative string float" do
67
+ type_cast('-24.35').should eql(-24)
68
+ end
69
+
70
+ it "returns integer representation of a negative string float with spaces" do
71
+ type_cast(' -24.35 ').should eql(-24)
72
+ end
73
+
74
+ it "returns integer representation of a zero string float, with no leading digits" do
75
+ type_cast('.0').should eql(0)
76
+ end
77
+
78
+ it "returns integer representation of a zero string float, with no leading digits with spaces" do
79
+ type_cast(' .0').should eql(0)
80
+ end
81
+
82
+ it "returns integer representation of a positive string float, with no leading digits" do
83
+ type_cast('.41').should eql(0)
84
+ end
85
+
86
+ it "returns integer representation of a zero float" do
87
+ type_cast(0.0).should eql(0)
88
+ end
89
+
90
+ it "returns integer representation of a positive float" do
91
+ type_cast(24.35).should eql(24)
92
+ end
93
+
94
+ it "returns integer representation of a negative float" do
95
+ type_cast(-24.35).should eql(-24)
96
+ end
97
+
98
+ it "returns integer representation of a zero decimal" do
99
+ type_cast(BigDecimal('0.0')).should eql(0)
100
+ end
101
+
102
+ it "returns integer representation of a positive decimal" do
103
+ type_cast(BigDecimal('24.35')).should eql(24)
104
+ end
105
+
106
+ it "returns integer representation of a negative decimal" do
107
+ type_cast(BigDecimal('-24.35')).should eql(-24)
108
+ end
109
+
110
+ [ Object.new, true, '00.0', '0.', 'string' ].each do |value|
111
+ it "raises exception when attempting type_cast of non-numeric value #{value.inspect}" do
112
+ lambda do
113
+ type_cast(value)
114
+ end.should raise_error(TypecastError, /could not typecast/)
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -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,24 @@
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" do
20
+ pending
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Arel
4
+ describe Join do
5
+ before do
6
+ @users = Array.new([
7
+ [1, 'bryan' ],
8
+ [2, 'emilio' ],
9
+ [3, 'nick']
10
+ ], [[:id, Attributes::Integer], [:name, Attributes::String]])
11
+ @photos = Table.new(:photos)
12
+ @photos.delete
13
+ @photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6)
14
+ @photos.insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42)
15
+ # Oracle adapter returns database integers as Ruby integers and not strings
16
+ # So does the FFI sqlite library
17
+ db_int_return = @photos.project(@photos[:camera_id]).first.tuple.first
18
+ @adapter_returns_integer = db_int_return.is_a?(String) ? false : true
19
+ end
20
+
21
+ describe 'when the in memory relation is on the left' do
22
+ it 'joins across engines' do
23
+ @users \
24
+ .join(@photos) \
25
+ .on(@users[:id].eq(@photos[:user_id])) \
26
+ .project(@users[:name], @photos[:camera_id]) \
27
+ .let do |relation|
28
+ relation.call.should == [
29
+ Row.new(relation, ['bryan', @adapter_returns_integer ? 6 : '6']),
30
+ Row.new(relation, ['emilio', @adapter_returns_integer ? 42 : '42'])
31
+ ]
32
+ end
33
+ end
34
+ end
35
+
36
+ describe 'when the in memory relation is on the right' do
37
+ it 'joins across engines' do
38
+ @photos \
39
+ .join(@users) \
40
+ .on(@users[:id].eq(@photos[:user_id])) \
41
+ .project(@users[:name], @photos[:camera_id]) \
42
+ .let do |relation|
43
+ relation.call.should == [
44
+ Row.new(relation, ['bryan', @adapter_returns_integer ? 6 : '6']),
45
+ Row.new(relation, ['emilio', @adapter_returns_integer ? 42 : '42'])
46
+ ]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end