datamapper-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.
- data/.autotest +17 -14
- data/.gitignore +3 -1
- data/FAQ +6 -5
- data/History.txt +5 -39
- data/Manifest.txt +67 -76
- data/QUICKLINKS +1 -1
- data/README.txt +21 -15
- data/Rakefile +16 -15
- data/SPECS +2 -29
- data/TODO +1 -1
- data/dm-core.gemspec +11 -15
- data/lib/dm-core/adapters/abstract_adapter.rb +182 -185
- data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
- data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
- data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
- data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
- data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
- data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
- data/lib/dm-core/adapters.rb +135 -16
- data/lib/dm-core/associations/many_to_many.rb +372 -90
- data/lib/dm-core/associations/many_to_one.rb +220 -73
- data/lib/dm-core/associations/one_to_many.rb +319 -255
- data/lib/dm-core/associations/one_to_one.rb +66 -53
- data/lib/dm-core/associations/relationship.rb +560 -158
- data/lib/dm-core/collection.rb +1104 -381
- data/lib/dm-core/core_ext/kernel.rb +12 -0
- data/lib/dm-core/core_ext/symbol.rb +10 -0
- data/lib/dm-core/identity_map.rb +4 -34
- data/lib/dm-core/migrations.rb +1283 -0
- data/lib/dm-core/model/descendant_set.rb +81 -0
- data/lib/dm-core/model/hook.rb +45 -0
- data/lib/dm-core/model/is.rb +32 -0
- data/lib/dm-core/model/property.rb +248 -0
- data/lib/dm-core/model/relationship.rb +335 -0
- data/lib/dm-core/model/scope.rb +90 -0
- data/lib/dm-core/model.rb +570 -369
- data/lib/dm-core/property.rb +753 -280
- data/lib/dm-core/property_set.rb +141 -98
- data/lib/dm-core/query/conditions/comparison.rb +814 -0
- data/lib/dm-core/query/conditions/operation.rb +247 -0
- data/lib/dm-core/query/direction.rb +43 -0
- data/lib/dm-core/query/operator.rb +42 -0
- data/lib/dm-core/query/path.rb +102 -0
- data/lib/dm-core/query/sort.rb +45 -0
- data/lib/dm-core/query.rb +974 -492
- data/lib/dm-core/repository.rb +147 -107
- data/lib/dm-core/resource.rb +644 -429
- data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
- data/lib/dm-core/support/chainable.rb +20 -0
- data/lib/dm-core/support/deprecate.rb +12 -0
- data/lib/dm-core/support/equalizer.rb +23 -0
- data/lib/dm-core/support/logger.rb +13 -0
- data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
- data/lib/dm-core/transaction.rb +333 -92
- data/lib/dm-core/type.rb +98 -60
- data/lib/dm-core/types/boolean.rb +1 -1
- data/lib/dm-core/types/discriminator.rb +34 -20
- data/lib/dm-core/types/object.rb +7 -4
- data/lib/dm-core/types/paranoid_boolean.rb +11 -9
- data/lib/dm-core/types/paranoid_datetime.rb +11 -9
- data/lib/dm-core/types/serial.rb +3 -3
- data/lib/dm-core/types/text.rb +3 -4
- data/lib/dm-core/version.rb +1 -1
- data/lib/dm-core.rb +106 -110
- data/script/performance.rb +102 -109
- data/script/profile.rb +169 -38
- data/spec/lib/adapter_helpers.rb +105 -0
- data/spec/lib/collection_helpers.rb +18 -0
- data/spec/lib/counter_adapter.rb +34 -0
- data/spec/lib/pending_helpers.rb +27 -0
- data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
- data/spec/public/associations/many_to_many_spec.rb +193 -0
- data/spec/public/associations/many_to_one_spec.rb +73 -0
- data/spec/public/associations/one_to_many_spec.rb +77 -0
- data/spec/public/associations/one_to_one_spec.rb +156 -0
- data/spec/public/collection_spec.rb +65 -0
- data/spec/public/model/relationship_spec.rb +924 -0
- data/spec/public/model_spec.rb +159 -0
- data/spec/public/property_spec.rb +829 -0
- data/spec/public/resource_spec.rb +71 -0
- data/spec/public/sel_spec.rb +44 -0
- data/spec/public/setup_spec.rb +145 -0
- data/spec/public/shared/association_collection_shared_spec.rb +317 -0
- data/spec/public/shared/collection_shared_spec.rb +1723 -0
- data/spec/public/shared/finder_shared_spec.rb +1619 -0
- data/spec/public/shared/resource_shared_spec.rb +924 -0
- data/spec/public/shared/sel_shared_spec.rb +112 -0
- data/spec/public/transaction_spec.rb +129 -0
- data/spec/public/types/discriminator_spec.rb +130 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
- data/spec/semipublic/associations/relationship_spec.rb +194 -0
- data/spec/semipublic/associations_spec.rb +177 -0
- data/spec/semipublic/collection_spec.rb +142 -0
- data/spec/semipublic/property_spec.rb +61 -0
- data/spec/semipublic/query/conditions_spec.rb +528 -0
- data/spec/semipublic/query/path_spec.rb +443 -0
- data/spec/semipublic/query_spec.rb +2626 -0
- data/spec/semipublic/resource_spec.rb +47 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
- data/spec/spec.opts +3 -1
- data/spec/spec_helper.rb +80 -57
- data/tasks/ci.rb +19 -31
- data/tasks/dm.rb +43 -48
- data/tasks/doc.rb +8 -11
- data/tasks/gemspec.rb +5 -5
- data/tasks/hoe.rb +15 -16
- data/tasks/install.rb +8 -10
- metadata +72 -93
- data/lib/dm-core/associations/relationship_chain.rb +0 -81
- data/lib/dm-core/associations.rb +0 -207
- data/lib/dm-core/auto_migrations.rb +0 -105
- data/lib/dm-core/dependency_queue.rb +0 -32
- data/lib/dm-core/hook.rb +0 -11
- data/lib/dm-core/is.rb +0 -16
- data/lib/dm-core/logger.rb +0 -232
- data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
- data/lib/dm-core/migrator.rb +0 -29
- data/lib/dm-core/scope.rb +0 -58
- data/lib/dm-core/support/array.rb +0 -13
- data/lib/dm-core/support/assertions.rb +0 -8
- data/lib/dm-core/support/errors.rb +0 -23
- data/lib/dm-core/support/kernel.rb +0 -11
- data/lib/dm-core/support/symbol.rb +0 -41
- data/lib/dm-core/support.rb +0 -7
- data/lib/dm-core/type_map.rb +0 -80
- data/lib/dm-core/types.rb +0 -19
- data/script/all +0 -4
- data/spec/integration/association_spec.rb +0 -1382
- data/spec/integration/association_through_spec.rb +0 -203
- data/spec/integration/associations/many_to_many_spec.rb +0 -449
- data/spec/integration/associations/many_to_one_spec.rb +0 -163
- data/spec/integration/associations/one_to_many_spec.rb +0 -188
- data/spec/integration/auto_migrations_spec.rb +0 -413
- data/spec/integration/collection_spec.rb +0 -1073
- data/spec/integration/data_objects_adapter_spec.rb +0 -32
- data/spec/integration/dependency_queue_spec.rb +0 -46
- data/spec/integration/model_spec.rb +0 -197
- data/spec/integration/mysql_adapter_spec.rb +0 -85
- data/spec/integration/postgres_adapter_spec.rb +0 -731
- data/spec/integration/property_spec.rb +0 -253
- data/spec/integration/query_spec.rb +0 -514
- data/spec/integration/repository_spec.rb +0 -61
- data/spec/integration/resource_spec.rb +0 -513
- data/spec/integration/sqlite3_adapter_spec.rb +0 -352
- data/spec/integration/sti_spec.rb +0 -273
- data/spec/integration/strategic_eager_loading_spec.rb +0 -156
- data/spec/integration/transaction_spec.rb +0 -75
- data/spec/integration/type_spec.rb +0 -275
- data/spec/lib/logging_helper.rb +0 -18
- data/spec/lib/mock_adapter.rb +0 -27
- data/spec/lib/model_loader.rb +0 -100
- data/spec/lib/publicize_methods.rb +0 -28
- data/spec/models/content.rb +0 -16
- data/spec/models/vehicles.rb +0 -34
- data/spec/models/zoo.rb +0 -48
- data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
- data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
- data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
- data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
- data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
- data/spec/unit/associations/many_to_many_spec.rb +0 -32
- data/spec/unit/associations/many_to_one_spec.rb +0 -159
- data/spec/unit/associations/one_to_many_spec.rb +0 -393
- data/spec/unit/associations/one_to_one_spec.rb +0 -7
- data/spec/unit/associations/relationship_spec.rb +0 -71
- data/spec/unit/associations_spec.rb +0 -242
- data/spec/unit/auto_migrations_spec.rb +0 -111
- data/spec/unit/collection_spec.rb +0 -182
- data/spec/unit/data_mapper_spec.rb +0 -35
- data/spec/unit/identity_map_spec.rb +0 -126
- data/spec/unit/is_spec.rb +0 -80
- data/spec/unit/migrator_spec.rb +0 -33
- data/spec/unit/model_spec.rb +0 -321
- data/spec/unit/naming_conventions_spec.rb +0 -36
- data/spec/unit/property_set_spec.rb +0 -90
- data/spec/unit/property_spec.rb +0 -753
- data/spec/unit/query_spec.rb +0 -571
- data/spec/unit/repository_spec.rb +0 -93
- data/spec/unit/resource_spec.rb +0 -649
- data/spec/unit/scope_spec.rb +0 -142
- data/spec/unit/transaction_spec.rb +0 -493
- data/spec/unit/type_map_spec.rb +0 -114
- 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,20 @@
|
|
|
1
|
+
module DataMapper
|
|
2
|
+
module Chainable
|
|
3
|
+
|
|
4
|
+
# TODO: document
|
|
5
|
+
# @api private
|
|
6
|
+
def chainable(&block)
|
|
7
|
+
mod = Module.new(&block)
|
|
8
|
+
include mod
|
|
9
|
+
mod
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# TODO: document
|
|
13
|
+
# @api private
|
|
14
|
+
def extendable(&block)
|
|
15
|
+
mod = Module.new(&block)
|
|
16
|
+
extend mod
|
|
17
|
+
mod
|
|
18
|
+
end
|
|
19
|
+
end # module Chainable
|
|
20
|
+
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,23 @@
|
|
|
1
|
+
module DataMapper
|
|
2
|
+
module Equalizer
|
|
3
|
+
def equalize(*methods)
|
|
4
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
5
|
+
def eql?(other)
|
|
6
|
+
return true if equal?(other)
|
|
7
|
+
instance_of?(other.class) &&
|
|
8
|
+
#{methods.map { |method| "#{method}.eql?(other.#{method})" }.join(' && ')}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def ==(other)
|
|
12
|
+
return true if equal?(other)
|
|
13
|
+
#{methods.map { |method| "other.respond_to?(#{method.inspect})" }.join(' && ')} &&
|
|
14
|
+
#{methods.map { |method| "#{method} == other.#{method}" }.join(' && ')}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def hash
|
|
18
|
+
[ #{methods.join(', ')} ].hash
|
|
19
|
+
end
|
|
20
|
+
RUBY
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -20,15 +20,15 @@ module DataMapper
|
|
|
20
20
|
# DataMapper.setup(name, uri) returns the Adapter for convenience, so you can
|
|
21
21
|
# use code like this:
|
|
22
22
|
#
|
|
23
|
-
# adapter = DataMapper.setup(:default,
|
|
24
|
-
# adapter.resource_naming_convention =
|
|
23
|
+
# adapter = DataMapper.setup(:default, 'mock://localhost/mock')
|
|
24
|
+
# adapter.resource_naming_convention = NamingConventions::Resource::Underscored
|
|
25
25
|
module NamingConventions
|
|
26
26
|
|
|
27
27
|
module Resource
|
|
28
28
|
|
|
29
29
|
module UnderscoredAndPluralized
|
|
30
30
|
def self.call(name)
|
|
31
|
-
Extlib::Inflection.pluralize(Extlib::Inflection.underscore(name)).gsub('/','_')
|
|
31
|
+
Extlib::Inflection.pluralize(Extlib::Inflection.underscore(name)).gsub('/', '_')
|
|
32
32
|
end
|
|
33
33
|
end # module UnderscoredAndPluralized
|
|
34
34
|
|
|
@@ -46,7 +46,7 @@ module DataMapper
|
|
|
46
46
|
|
|
47
47
|
module Yaml
|
|
48
48
|
def self.call(name)
|
|
49
|
-
Extlib::Inflection.pluralize(Extlib::Inflection.underscore(name))
|
|
49
|
+
"#{Extlib::Inflection.pluralize(Extlib::Inflection.underscore(name))}.yaml"
|
|
50
50
|
end
|
|
51
51
|
end # module Yaml
|
|
52
52
|
|
|
@@ -56,7 +56,7 @@ module DataMapper
|
|
|
56
56
|
|
|
57
57
|
module UnderscoredAndPluralized
|
|
58
58
|
def self.call(property)
|
|
59
|
-
Extlib::Inflection.pluralize(Extlib::Inflection.underscore(property.name.to_s)).gsub('/','_')
|
|
59
|
+
Extlib::Inflection.pluralize(Extlib::Inflection.underscore(property.name.to_s)).gsub('/', '_')
|
|
60
60
|
end
|
|
61
61
|
end # module UnderscoredAndPluralized
|
|
62
62
|
|
|
@@ -74,7 +74,7 @@ module DataMapper
|
|
|
74
74
|
|
|
75
75
|
module Yaml
|
|
76
76
|
def self.call(property)
|
|
77
|
-
Extlib::Inflection.pluralize(Extlib::Inflection.underscore(property.name.to_s))
|
|
77
|
+
"#{Extlib::Inflection.pluralize(Extlib::Inflection.underscore(property.name.to_s))}.yaml"
|
|
78
78
|
end
|
|
79
79
|
end # module Yaml
|
|
80
80
|
|