dm-core 0.9.11 → 0.10.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 (194) hide show
  1. data/.autotest +17 -14
  2. data/.gitignore +3 -1
  3. data/FAQ +6 -5
  4. data/History.txt +5 -50
  5. data/Manifest.txt +66 -76
  6. data/QUICKLINKS +1 -1
  7. data/README.txt +21 -15
  8. data/Rakefile +6 -7
  9. data/SPECS +2 -29
  10. data/TODO +1 -1
  11. data/deps.rip +2 -0
  12. data/dm-core.gemspec +11 -15
  13. data/lib/dm-core.rb +105 -110
  14. data/lib/dm-core/adapters.rb +135 -16
  15. data/lib/dm-core/adapters/abstract_adapter.rb +251 -181
  16. data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
  17. data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
  18. data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
  19. data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
  20. data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
  21. data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
  22. data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
  23. data/lib/dm-core/associations/many_to_many.rb +372 -90
  24. data/lib/dm-core/associations/many_to_one.rb +220 -73
  25. data/lib/dm-core/associations/one_to_many.rb +319 -255
  26. data/lib/dm-core/associations/one_to_one.rb +66 -53
  27. data/lib/dm-core/associations/relationship.rb +561 -156
  28. data/lib/dm-core/collection.rb +1101 -379
  29. data/lib/dm-core/core_ext/kernel.rb +12 -0
  30. data/lib/dm-core/core_ext/symbol.rb +10 -0
  31. data/lib/dm-core/identity_map.rb +4 -34
  32. data/lib/dm-core/migrations.rb +1283 -0
  33. data/lib/dm-core/model.rb +570 -369
  34. data/lib/dm-core/model/descendant_set.rb +81 -0
  35. data/lib/dm-core/model/hook.rb +45 -0
  36. data/lib/dm-core/model/is.rb +32 -0
  37. data/lib/dm-core/model/property.rb +247 -0
  38. data/lib/dm-core/model/relationship.rb +335 -0
  39. data/lib/dm-core/model/scope.rb +90 -0
  40. data/lib/dm-core/property.rb +808 -273
  41. data/lib/dm-core/property_set.rb +141 -98
  42. data/lib/dm-core/query.rb +1037 -483
  43. data/lib/dm-core/query/conditions/comparison.rb +872 -0
  44. data/lib/dm-core/query/conditions/operation.rb +221 -0
  45. data/lib/dm-core/query/direction.rb +43 -0
  46. data/lib/dm-core/query/operator.rb +84 -0
  47. data/lib/dm-core/query/path.rb +138 -0
  48. data/lib/dm-core/query/sort.rb +45 -0
  49. data/lib/dm-core/repository.rb +210 -94
  50. data/lib/dm-core/resource.rb +641 -421
  51. data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
  52. data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
  53. data/lib/dm-core/support/chainable.rb +22 -0
  54. data/lib/dm-core/support/deprecate.rb +12 -0
  55. data/lib/dm-core/support/logger.rb +13 -0
  56. data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
  57. data/lib/dm-core/transaction.rb +333 -92
  58. data/lib/dm-core/type.rb +98 -60
  59. data/lib/dm-core/types/boolean.rb +1 -1
  60. data/lib/dm-core/types/discriminator.rb +34 -20
  61. data/lib/dm-core/types/object.rb +7 -4
  62. data/lib/dm-core/types/paranoid_boolean.rb +11 -9
  63. data/lib/dm-core/types/paranoid_datetime.rb +11 -9
  64. data/lib/dm-core/types/serial.rb +3 -3
  65. data/lib/dm-core/types/text.rb +3 -4
  66. data/lib/dm-core/version.rb +1 -1
  67. data/script/performance.rb +102 -109
  68. data/script/profile.rb +169 -38
  69. data/spec/lib/adapter_helpers.rb +105 -0
  70. data/spec/lib/collection_helpers.rb +18 -0
  71. data/spec/lib/counter_adapter.rb +34 -0
  72. data/spec/lib/pending_helpers.rb +27 -0
  73. data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
  74. data/spec/public/associations/many_to_many_spec.rb +193 -0
  75. data/spec/public/associations/many_to_one_spec.rb +73 -0
  76. data/spec/public/associations/one_to_many_spec.rb +77 -0
  77. data/spec/public/associations/one_to_one_spec.rb +156 -0
  78. data/spec/public/collection_spec.rb +65 -0
  79. data/spec/public/migrations_spec.rb +359 -0
  80. data/spec/public/model/relationship_spec.rb +924 -0
  81. data/spec/public/model_spec.rb +159 -0
  82. data/spec/public/property_spec.rb +829 -0
  83. data/spec/public/resource_spec.rb +71 -0
  84. data/spec/public/sel_spec.rb +44 -0
  85. data/spec/public/setup_spec.rb +145 -0
  86. data/spec/public/shared/association_collection_shared_spec.rb +317 -0
  87. data/spec/public/shared/collection_shared_spec.rb +1670 -0
  88. data/spec/public/shared/finder_shared_spec.rb +1619 -0
  89. data/spec/public/shared/resource_shared_spec.rb +924 -0
  90. data/spec/public/shared/sel_shared_spec.rb +112 -0
  91. data/spec/public/transaction_spec.rb +129 -0
  92. data/spec/public/types/discriminator_spec.rb +130 -0
  93. data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
  94. data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
  95. data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
  96. data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
  97. data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
  98. data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
  99. data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
  100. data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
  101. data/spec/semipublic/associations/relationship_spec.rb +194 -0
  102. data/spec/semipublic/associations_spec.rb +177 -0
  103. data/spec/semipublic/collection_spec.rb +142 -0
  104. data/spec/semipublic/property_spec.rb +61 -0
  105. data/spec/semipublic/query/conditions_spec.rb +528 -0
  106. data/spec/semipublic/query/path_spec.rb +443 -0
  107. data/spec/semipublic/query_spec.rb +2626 -0
  108. data/spec/semipublic/resource_spec.rb +47 -0
  109. data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
  110. data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
  111. data/spec/spec.opts +3 -1
  112. data/spec/spec_helper.rb +80 -57
  113. data/tasks/ci.rb +19 -31
  114. data/tasks/dm.rb +43 -48
  115. data/tasks/doc.rb +8 -11
  116. data/tasks/gemspec.rb +5 -5
  117. data/tasks/hoe.rb +15 -16
  118. data/tasks/install.rb +8 -10
  119. metadata +74 -111
  120. data/lib/dm-core/associations.rb +0 -207
  121. data/lib/dm-core/associations/relationship_chain.rb +0 -81
  122. data/lib/dm-core/auto_migrations.rb +0 -105
  123. data/lib/dm-core/dependency_queue.rb +0 -32
  124. data/lib/dm-core/hook.rb +0 -11
  125. data/lib/dm-core/is.rb +0 -16
  126. data/lib/dm-core/logger.rb +0 -232
  127. data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
  128. data/lib/dm-core/migrator.rb +0 -29
  129. data/lib/dm-core/scope.rb +0 -58
  130. data/lib/dm-core/support.rb +0 -7
  131. data/lib/dm-core/support/array.rb +0 -13
  132. data/lib/dm-core/support/assertions.rb +0 -8
  133. data/lib/dm-core/support/errors.rb +0 -23
  134. data/lib/dm-core/support/kernel.rb +0 -11
  135. data/lib/dm-core/support/symbol.rb +0 -41
  136. data/lib/dm-core/type_map.rb +0 -80
  137. data/lib/dm-core/types.rb +0 -19
  138. data/script/all +0 -4
  139. data/spec/integration/association_spec.rb +0 -1382
  140. data/spec/integration/association_through_spec.rb +0 -203
  141. data/spec/integration/associations/many_to_many_spec.rb +0 -449
  142. data/spec/integration/associations/many_to_one_spec.rb +0 -163
  143. data/spec/integration/associations/one_to_many_spec.rb +0 -188
  144. data/spec/integration/auto_migrations_spec.rb +0 -413
  145. data/spec/integration/collection_spec.rb +0 -1073
  146. data/spec/integration/data_objects_adapter_spec.rb +0 -32
  147. data/spec/integration/dependency_queue_spec.rb +0 -46
  148. data/spec/integration/model_spec.rb +0 -197
  149. data/spec/integration/mysql_adapter_spec.rb +0 -85
  150. data/spec/integration/postgres_adapter_spec.rb +0 -731
  151. data/spec/integration/property_spec.rb +0 -253
  152. data/spec/integration/query_spec.rb +0 -514
  153. data/spec/integration/repository_spec.rb +0 -61
  154. data/spec/integration/resource_spec.rb +0 -513
  155. data/spec/integration/sqlite3_adapter_spec.rb +0 -352
  156. data/spec/integration/sti_spec.rb +0 -273
  157. data/spec/integration/strategic_eager_loading_spec.rb +0 -156
  158. data/spec/integration/transaction_spec.rb +0 -75
  159. data/spec/integration/type_spec.rb +0 -275
  160. data/spec/lib/logging_helper.rb +0 -18
  161. data/spec/lib/mock_adapter.rb +0 -27
  162. data/spec/lib/model_loader.rb +0 -100
  163. data/spec/lib/publicize_methods.rb +0 -28
  164. data/spec/models/content.rb +0 -16
  165. data/spec/models/vehicles.rb +0 -34
  166. data/spec/models/zoo.rb +0 -48
  167. data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
  168. data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
  169. data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
  170. data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
  171. data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
  172. data/spec/unit/associations/many_to_many_spec.rb +0 -32
  173. data/spec/unit/associations/many_to_one_spec.rb +0 -159
  174. data/spec/unit/associations/one_to_many_spec.rb +0 -393
  175. data/spec/unit/associations/one_to_one_spec.rb +0 -7
  176. data/spec/unit/associations/relationship_spec.rb +0 -71
  177. data/spec/unit/associations_spec.rb +0 -242
  178. data/spec/unit/auto_migrations_spec.rb +0 -111
  179. data/spec/unit/collection_spec.rb +0 -182
  180. data/spec/unit/data_mapper_spec.rb +0 -35
  181. data/spec/unit/identity_map_spec.rb +0 -126
  182. data/spec/unit/is_spec.rb +0 -80
  183. data/spec/unit/migrator_spec.rb +0 -33
  184. data/spec/unit/model_spec.rb +0 -321
  185. data/spec/unit/naming_conventions_spec.rb +0 -36
  186. data/spec/unit/property_set_spec.rb +0 -90
  187. data/spec/unit/property_spec.rb +0 -753
  188. data/spec/unit/query_spec.rb +0 -571
  189. data/spec/unit/repository_spec.rb +0 -93
  190. data/spec/unit/resource_spec.rb +0 -649
  191. data/spec/unit/scope_spec.rb +0 -142
  192. data/spec/unit/transaction_spec.rb +0 -493
  193. data/spec/unit/type_map_spec.rb +0 -114
  194. data/spec/unit/type_spec.rb +0 -119
@@ -0,0 +1,294 @@
1
+ share_examples_for 'An Adapter' do
2
+
3
+ def self.adapter_supports?(*methods)
4
+ methods.all? do |method|
5
+ # TODO: figure out a way to see if the instance method is only inherited
6
+ # from the Abstract Adapter, and not defined in it's class. If that is
7
+ # the case return false
8
+
9
+ # CRUD methods can be inherited from parent class
10
+ described_type.instance_methods.any? { |instance_method| method.to_s == instance_method.to_s }
11
+ end
12
+ end
13
+
14
+ before :all do
15
+ raise '+@adapter+ should be defined in before block' unless instance_variable_get('@adapter')
16
+
17
+ class ::Heffalump
18
+ include DataMapper::Resource
19
+
20
+ property :id, Serial
21
+ property :color, String
22
+ property :num_spots, Integer
23
+ property :striped, Boolean
24
+ end
25
+
26
+ # create all tables and constraints before each spec
27
+ if @repository.respond_to?(:auto_migrate!)
28
+ Heffalump.auto_migrate!
29
+ end
30
+ end
31
+
32
+ if adapter_supports?(:create)
33
+ describe '#create' do
34
+ it 'should not raise any errors' do
35
+ lambda {
36
+ Heffalump.create(:color => 'peach')
37
+ }.should_not raise_error
38
+ end
39
+
40
+ it 'should set the identity field for the resource' do
41
+ heffalump = Heffalump.new(:color => 'peach')
42
+ heffalump.id.should be_nil
43
+ heffalump.save
44
+ heffalump.id.should_not be_nil
45
+ end
46
+ end
47
+ else
48
+ it 'needs to support #create'
49
+ end
50
+
51
+ if adapter_supports?(:read)
52
+ describe '#read' do
53
+ before :all do
54
+ @heffalump = Heffalump.create(:color => 'brownish hue')
55
+ #just going to borrow this, so I can check the return values
56
+ @query = Heffalump.all.query
57
+ end
58
+
59
+ it 'should not raise any errors' do
60
+ lambda {
61
+ Heffalump.all()
62
+ }.should_not raise_error
63
+ end
64
+
65
+ it 'should return stuff' do
66
+ Heffalump.all.should be_include(@heffalump)
67
+ end
68
+ end
69
+ else
70
+ it 'needs to support #read'
71
+ end
72
+
73
+ if adapter_supports?(:update)
74
+ describe '#update' do
75
+ before do
76
+ @heffalump = Heffalump.create(:color => 'indigo')
77
+ end
78
+
79
+ it 'should not raise any errors' do
80
+ lambda {
81
+ @heffalump.color = 'violet'
82
+ @heffalump.save
83
+ }.should_not raise_error
84
+ end
85
+
86
+ it 'should not alter the identity field' do
87
+ id = @heffalump.id
88
+ @heffalump.color = 'violet'
89
+ @heffalump.save
90
+ @heffalump.id.should == id
91
+ end
92
+
93
+ it 'should update altered fields' do
94
+ @heffalump.color = 'violet'
95
+ @heffalump.save
96
+ Heffalump.get(*@heffalump.key).color.should == 'violet'
97
+ end
98
+
99
+ it 'should not alter other fields' do
100
+ color = @heffalump.color
101
+ @heffalump.num_spots = 3
102
+ @heffalump.save
103
+ Heffalump.get(*@heffalump.key).color.should == color
104
+ end
105
+ end
106
+ else
107
+ it 'needs to support #update'
108
+ end
109
+
110
+ if adapter_supports?(:delete)
111
+ describe '#delete' do
112
+ before do
113
+ @heffalump = Heffalump.create(:color => 'forest green')
114
+ end
115
+
116
+ it 'should not raise any errors' do
117
+ lambda {
118
+ @heffalump.destroy
119
+ }.should_not raise_error
120
+ end
121
+
122
+ it 'should delete the requested resource' do
123
+ id = @heffalump.id
124
+ @heffalump.destroy
125
+ Heffalump.get(id).should be_nil
126
+ end
127
+ end
128
+ else
129
+ it 'needs to support #delete'
130
+ end
131
+
132
+ if adapter_supports?(:read, :create)
133
+ describe 'query matching' do
134
+ before :all do
135
+ @red = Heffalump.create(:color => 'red')
136
+ @two = Heffalump.create(:num_spots => 2)
137
+ @five = Heffalump.create(:num_spots => 5)
138
+ end
139
+
140
+ describe 'conditions' do
141
+ describe 'eql' do
142
+ it 'should be able to search for objects included in an inclusive range of values' do
143
+ Heffalump.all(:num_spots => 1..5).should be_include(@five)
144
+ end
145
+
146
+ it 'should be able to search for objects included in an exclusive range of values' do
147
+ Heffalump.all(:num_spots => 1...6).should be_include(@five)
148
+ end
149
+
150
+ it 'should not be able to search for values not included in an inclusive range of values' do
151
+ Heffalump.all(:num_spots => 1..4).should_not be_include(@five)
152
+ end
153
+
154
+ it 'should not be able to search for values not included in an exclusive range of values' do
155
+ Heffalump.all(:num_spots => 1...5).should_not be_include(@five)
156
+ end
157
+ end
158
+
159
+ describe 'not' do
160
+ it 'should be able to search for objects with not equal value' do
161
+ Heffalump.all(:color.not => 'red').should_not be_include(@red)
162
+ end
163
+
164
+ it 'should include objects that are not like the value' do
165
+ Heffalump.all(:color.not => 'black').should be_include(@red)
166
+ end
167
+
168
+ it 'should be able to search for objects with not nil value' do
169
+ Heffalump.all(:color.not => nil).should be_include(@red)
170
+ end
171
+
172
+ it 'should not include objects with a nil value' do
173
+ Heffalump.all(:color.not => nil).should_not be_include(@two)
174
+ end
175
+
176
+ it 'should be able to search for objects not included in an array of values' do
177
+ Heffalump.all(:num_spots.not => [ 1, 3, 5, 7 ]).should be_include(@two)
178
+ end
179
+
180
+ it 'should be able to search for objects not included in an array of values' do
181
+ Heffalump.all(:num_spots.not => [ 1, 3, 5, 7 ]).should_not be_include(@five)
182
+ end
183
+
184
+ it 'should be able to search for objects not included in an inclusive range of values' do
185
+ Heffalump.all(:num_spots.not => 1..4).should be_include(@five)
186
+ end
187
+
188
+ it 'should be able to search for objects not included in an exclusive range of values' do
189
+ Heffalump.all(:num_spots.not => 1...5).should be_include(@five)
190
+ end
191
+
192
+ it 'should not be able to search for values not included in an inclusive range of values' do
193
+ Heffalump.all(:num_spots.not => 1..5).should_not be_include(@five)
194
+ end
195
+
196
+ it 'should not be able to search for values not included in an exclusive range of values' do
197
+ Heffalump.all(:num_spots.not => 1...6).should_not be_include(@five)
198
+ end
199
+ end
200
+
201
+ describe 'like' do
202
+ it 'should be able to search for objects that match value' do
203
+ Heffalump.all(:color.like => '%ed').should be_include(@red)
204
+ end
205
+
206
+ it 'should not search for objects that do not match the value' do
207
+ Heffalump.all(:color.like => '%blak%').should_not be_include(@red)
208
+ end
209
+ end
210
+
211
+ describe 'regexp' do
212
+ before do
213
+ if defined?(DataMapper::Adapters::Sqlite3Adapter) && @adapter.kind_of?(DataMapper::Adapters::Sqlite3Adapter)
214
+ pending 'delegate regexp matches to same system that the InMemory and YAML adapters use'
215
+ end
216
+ end
217
+
218
+ it 'should be able to search for objects that match value' do
219
+ Heffalump.all(:color => /ed/).should be_include(@red)
220
+ end
221
+
222
+ it 'should not be able to search for objects that do not match the value' do
223
+ Heffalump.all(:color => /blak/).should_not be_include(@red)
224
+ end
225
+
226
+ it 'should be able to do a negated search for objects that match value' do
227
+ Heffalump.all(:color.not => /blak/).should be_include(@red)
228
+ end
229
+
230
+ it 'should not be able to do a negated search for objects that do not match value' do
231
+ Heffalump.all(:color.not => /ed/).should_not be_include(@red)
232
+ end
233
+
234
+ end
235
+
236
+ describe 'gt' do
237
+ it 'should be able to search for objects with value greater than' do
238
+ Heffalump.all(:num_spots.gt => 1).should be_include(@two)
239
+ end
240
+
241
+ it 'should not find objects with a value less than' do
242
+ Heffalump.all(:num_spots.gt => 3).should_not be_include(@two)
243
+ end
244
+ end
245
+
246
+ describe 'gte' do
247
+ it 'should be able to search for objects with value greater than' do
248
+ Heffalump.all(:num_spots.gte => 1).should be_include(@two)
249
+ end
250
+
251
+ it 'should be able to search for objects with values equal to' do
252
+ Heffalump.all(:num_spots.gte => 2).should be_include(@two)
253
+ end
254
+
255
+ it 'should not find objects with a value less than' do
256
+ Heffalump.all(:num_spots.gte => 3).should_not be_include(@two)
257
+ end
258
+ end
259
+
260
+ describe 'lt' do
261
+ it 'should be able to search for objects with value less than' do
262
+ Heffalump.all(:num_spots.lt => 3).should be_include(@two)
263
+ end
264
+
265
+ it 'should not find objects with a value less than' do
266
+ Heffalump.all(:num_spots.gt => 2).should_not be_include(@two)
267
+ end
268
+ end
269
+
270
+ describe 'lte' do
271
+ it 'should be able to search for objects with value less than' do
272
+ Heffalump.all(:num_spots.lte => 3).should be_include(@two)
273
+ end
274
+
275
+ it 'should be able to search for objects with values equal to' do
276
+ Heffalump.all(:num_spots.lte => 2).should be_include(@two)
277
+ end
278
+
279
+ it 'should not find objects with a value less than' do
280
+ Heffalump.all(:num_spots.lte => 1).should_not be_include(@two)
281
+ end
282
+ end
283
+ end
284
+
285
+ describe 'limits' do
286
+ it 'should be able to limit the objects' do
287
+ Heffalump.all(:limit => 2).length.should == 2
288
+ end
289
+ end
290
+ end
291
+ else
292
+ it 'needs to support #read and #create to test query matching'
293
+ end
294
+ end
@@ -0,0 +1,106 @@
1
+ share_examples_for 'A DataObjects Adapter' do
2
+ before :all do
3
+ raise '+@adapter+ should be defined in before block' unless instance_variable_get('@adapter')
4
+
5
+ @log = StringIO.new
6
+
7
+ @original_logger = DataMapper.logger
8
+ DataMapper.logger = DataMapper::Logger.new(@log, :debug)
9
+
10
+ # set up the adapter after switching the logger so queries can be captured
11
+ @adapter = DataMapper.setup(@adapter.name, @adapter.options)
12
+ end
13
+
14
+ after :all do
15
+ DataMapper.logger = @original_logger
16
+ end
17
+
18
+ def reset_log
19
+ @log.truncate(0)
20
+ @log.rewind
21
+ end
22
+
23
+ def log_output
24
+ @log.rewind
25
+ @log.read.chomp.gsub(/^\s+~ \(\d+\.?\d*\)\s+/, '')
26
+ end
27
+
28
+ def supports_default_values?
29
+ @adapter.send(:supports_default_values?)
30
+ end
31
+
32
+ def supports_returning?
33
+ @adapter.send(:supports_returning?)
34
+ end
35
+
36
+ describe '#create' do
37
+ describe 'serial properties' do
38
+ before :all do
39
+ class ::Article
40
+ include DataMapper::Resource
41
+
42
+ property :id, Serial
43
+ end
44
+
45
+ # create all tables and constraints before each spec
46
+ if @repository.respond_to?(:auto_migrate!)
47
+ Article.auto_migrate!
48
+ end
49
+
50
+ reset_log
51
+
52
+ Article.create
53
+ end
54
+
55
+ it 'should not send NULL values' do
56
+ statement = if defined?(DataMapper::Adapters::MysqlAdapter) && @adapter.kind_of?(DataMapper::Adapters::MysqlAdapter)
57
+ /\AINSERT INTO `articles` \(\) VALUES \(\)\z/
58
+ elsif supports_default_values? && supports_returning?
59
+ /\AINSERT INTO "articles" DEFAULT VALUES RETURNING \"id\"\z/
60
+ elsif supports_default_values?
61
+ /\AINSERT INTO "articles" DEFAULT VALUES\z/
62
+ else
63
+ /\AINSERT INTO "articles" \(\) VALUES \(\)\z/
64
+ end
65
+
66
+ log_output.should =~ statement
67
+ end
68
+ end
69
+
70
+ describe 'properties without a default' do
71
+ before :all do
72
+ class ::Article
73
+ include DataMapper::Resource
74
+
75
+ property :id, Serial
76
+ property :title, String
77
+ end
78
+
79
+ # create all tables and constraints before each spec
80
+ if @repository.respond_to?(:auto_migrate!)
81
+ Article.auto_migrate!
82
+ end
83
+
84
+ reset_log
85
+
86
+ Article.create(:id => 1)
87
+ end
88
+
89
+ it 'should not send NULL values' do
90
+ if defined?(DataMapper::Adapters::MysqlAdapter) && @adapter.kind_of?(DataMapper::Adapters::MysqlAdapter)
91
+ log_output.should =~ /^INSERT INTO `articles` \(`id`\) VALUES \(.{1,2}\)$/i
92
+ else
93
+ log_output.should =~ /^INSERT INTO "articles" \("id"\) VALUES \(.{1,2}\)$/i
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ describe '#execute' do
100
+ it 'should allow queries without return results'
101
+ end
102
+
103
+ describe '#query' do
104
+ it 'should allow queries with return results'
105
+ end
106
+ end
@@ -0,0 +1,22 @@
1
+ # TODO: move this to Extlib::Chainable
2
+
3
+ module DataMapper
4
+ module Chainable
5
+
6
+ # TODO: document
7
+ # @api private
8
+ def chainable(&block)
9
+ mod = Module.new(&block)
10
+ include mod
11
+ mod
12
+ end
13
+
14
+ # TODO: document
15
+ # @api private
16
+ def extendable(&block)
17
+ mod = Module.new(&block)
18
+ extend mod
19
+ mod
20
+ end
21
+ end # module Chainable
22
+ end # module DataMapper
@@ -0,0 +1,12 @@
1
+ module DataMapper
2
+ module Deprecate
3
+ def deprecate(old_method, new_method)
4
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
5
+ def #{old_method}(*args, &block)
6
+ warn "\#{self.class}##{old_method} is deprecated, use \#{self.class}##{new_method} instead (\#{caller[0]})"
7
+ send(#{new_method.inspect}, *args, &block)
8
+ end
9
+ RUBY
10
+ end
11
+ end # module Deprecate
12
+ end # module DataMapper
@@ -0,0 +1,13 @@
1
+ module DataMapper
2
+ class << self #:nodoc:
3
+ attr_accessor :logger
4
+ end
5
+
6
+ class Logger < Extlib::Logger
7
+ def initialize(*)
8
+ super
9
+ self.auto_flush = true
10
+ DataMapper.logger = self
11
+ end
12
+ end # class Logger
13
+ end # module DataMapper