datamapper-dm-core 0.9.11 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/spec/unit/model_spec.rb
DELETED
@@ -1,321 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe 'DataMapper::Model' do
|
4
|
-
before do
|
5
|
-
Object.send(:remove_const, :ModelSpec) if defined?(ModelSpec)
|
6
|
-
module ModelSpec
|
7
|
-
class Resource
|
8
|
-
include DataMapper::Resource
|
9
|
-
|
10
|
-
storage_names[:legacy] = 'legacy_resource'
|
11
|
-
|
12
|
-
property :id, Serial
|
13
|
-
property :name, String
|
14
|
-
property :type, Discriminator
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should provide .new' do
|
20
|
-
meta_class = class << ModelSpec::Resource; self end
|
21
|
-
meta_class.should respond_to(:new)
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '.new' do
|
25
|
-
it 'should require a default storage name and accept a block' do
|
26
|
-
pluto = DataMapper::Model.new('planets') do
|
27
|
-
property :name, String, :key => true
|
28
|
-
end
|
29
|
-
|
30
|
-
pluto.storage_name(:default).should == 'planets'
|
31
|
-
pluto.storage_name(:legacy).should == 'planets'
|
32
|
-
pluto.properties[:name].should_not be_nil
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should provide #transaction' do
|
37
|
-
ModelSpec::Resource.should respond_to(:transaction)
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '#transaction' do
|
41
|
-
it 'should return a new Transaction with Model as argument' do
|
42
|
-
transaction = mock("transaction")
|
43
|
-
DataMapper::Transaction.should_receive(:new).with(ModelSpec::Resource).and_return(transaction)
|
44
|
-
ModelSpec::Resource.transaction.should == transaction
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should provide #before' do
|
49
|
-
ModelSpec::Resource.should respond_to(:before)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should provide #after' do
|
53
|
-
ModelSpec::Resource.should respond_to(:after)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should provide #repository' do
|
57
|
-
ModelSpec::Resource.should respond_to(:repository)
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#repository' do
|
61
|
-
it 'should delegate to DataMapper.repository' do
|
62
|
-
repository = mock('repository')
|
63
|
-
DataMapper.should_receive(:repository).with(:legacy).and_return(repository)
|
64
|
-
ModelSpec::Resource.repository(:legacy).should == repository
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'should use default repository when not passed any arguments' do
|
68
|
-
ModelSpec::Resource.repository.name.should == ModelSpec::Resource.repository(:default).name
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should provide #storage_name' do
|
73
|
-
ModelSpec::Resource.should respond_to(:storage_name)
|
74
|
-
end
|
75
|
-
|
76
|
-
describe '#storage_name' do
|
77
|
-
it 'should map a repository to the storage location' do
|
78
|
-
ModelSpec::Resource.storage_name(:legacy).should == 'legacy_resource'
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should use default repository when not passed any arguments' do
|
82
|
-
ModelSpec::Resource.storage_name.object_id.should == ModelSpec::Resource.storage_name(:default).object_id
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'should provide #storage_names' do
|
87
|
-
ModelSpec::Resource.should respond_to(:storage_names)
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#storage_names' do
|
91
|
-
it 'should return a Hash mapping each repository to a storage location' do
|
92
|
-
ModelSpec::Resource.storage_names.should be_kind_of(Hash)
|
93
|
-
ModelSpec::Resource.storage_names.should == { :legacy => 'legacy_resource' }
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should provide #property' do
|
98
|
-
ModelSpec::Resource.should respond_to(:property)
|
99
|
-
end
|
100
|
-
|
101
|
-
describe '#property' do
|
102
|
-
it 'should raise a SyntaxError when the name contains invalid characters' do
|
103
|
-
lambda {
|
104
|
-
ModelSpec::Resource.property(:"with space", TrueClass)
|
105
|
-
}.should raise_error(SyntaxError)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should provide #properties' do
|
110
|
-
ModelSpec::Resource.should respond_to(:properties)
|
111
|
-
end
|
112
|
-
|
113
|
-
describe '#properties' do
|
114
|
-
it 'should return an PropertySet' do
|
115
|
-
ModelSpec::Resource.properties(:legacy).should be_kind_of(DataMapper::PropertySet)
|
116
|
-
ModelSpec::Resource.properties(:legacy).should have(3).entries
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should use default repository when not passed any arguments' do
|
120
|
-
ModelSpec::Resource.properties.object_id.should == ModelSpec::Resource.properties(:default).object_id
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'should provide #key' do
|
125
|
-
ModelSpec::Resource.should respond_to(:key)
|
126
|
-
end
|
127
|
-
|
128
|
-
describe '#key' do
|
129
|
-
it 'should return an Array of Property objects' do
|
130
|
-
ModelSpec::Resource.key(:legacy).should be_kind_of(Array)
|
131
|
-
ModelSpec::Resource.key(:legacy).should have(1).entries
|
132
|
-
ModelSpec::Resource.key(:legacy).first.should be_kind_of(DataMapper::Property)
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'should use default repository when not passed any arguments' do
|
136
|
-
ModelSpec::Resource.key.should == ModelSpec::Resource.key(:default)
|
137
|
-
end
|
138
|
-
|
139
|
-
it 'should not cache the key value' do
|
140
|
-
class GasGiant < ModelSpec::Resource
|
141
|
-
end
|
142
|
-
|
143
|
-
GasGiant.key.object_id.should_not == ModelSpec::Resource.key(:default)
|
144
|
-
|
145
|
-
# change the key and make sure the Array changes
|
146
|
-
GasGiant.key == GasGiant.properties.slice(:id)
|
147
|
-
GasGiant.property(:new_prop, String, :key => true)
|
148
|
-
GasGiant.key.object_id.should_not == ModelSpec::Resource.key(:default)
|
149
|
-
GasGiant.key == GasGiant.properties.slice(:id, :new_prop)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should provide #get' do
|
154
|
-
ModelSpec::Resource.should respond_to(:get)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should provide #first' do
|
158
|
-
ModelSpec::Resource.should respond_to(:first)
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'should provide #all' do
|
162
|
-
ModelSpec::Resource.should respond_to(:all)
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'should provide #storage_exists?' do
|
166
|
-
ModelSpec::Resource.should respond_to(:storage_exists?)
|
167
|
-
end
|
168
|
-
|
169
|
-
describe '#storage_exists?' do
|
170
|
-
it 'should return whether or not the storage exists' do
|
171
|
-
ModelSpec::Resource.storage_exists?.should == false
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should provide #default_order' do
|
176
|
-
ModelSpec::Resource.should respond_to(:default_order)
|
177
|
-
end
|
178
|
-
|
179
|
-
describe '#default_order' do
|
180
|
-
it 'should be equal to #key by default' do
|
181
|
-
ModelSpec::Resource.default_order.should == [ DataMapper::Query::Direction.new(ModelSpec::Resource.properties[:id], :asc) ]
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
describe '#append_inclusions' do
|
186
|
-
before(:all) do
|
187
|
-
@standard_resource_inclusions = DataMapper::Resource.instance_variable_get('@extra_inclusions')
|
188
|
-
@standard_model_extensions = DataMapper::Model.instance_variable_get('@extra_extensions')
|
189
|
-
end
|
190
|
-
|
191
|
-
before(:each) do
|
192
|
-
DataMapper::Resource.instance_variable_set('@extra_inclusions', [])
|
193
|
-
DataMapper::Model.instance_variable_set('@extra_extensions', [])
|
194
|
-
|
195
|
-
@module = Module.new do
|
196
|
-
def greet
|
197
|
-
hi_mom!
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
@another_module = Module.new do
|
202
|
-
def hello
|
203
|
-
hi_dad!
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
@class = Class.new
|
208
|
-
|
209
|
-
@class_code = %{
|
210
|
-
include DataMapper::Resource
|
211
|
-
property :id, Serial
|
212
|
-
}
|
213
|
-
end
|
214
|
-
|
215
|
-
after(:each) do
|
216
|
-
DataMapper::Resource.instance_variable_set('@extra_inclusions', @standard_resource_inclusions)
|
217
|
-
DataMapper::Model.instance_variable_set('@extra_extensions', @standard_model_extensions)
|
218
|
-
end
|
219
|
-
|
220
|
-
it "should append the module to be included in resources" do
|
221
|
-
DataMapper::Resource.append_inclusions @module
|
222
|
-
@class.class_eval(@class_code)
|
223
|
-
|
224
|
-
instance = @class.new
|
225
|
-
instance.should_receive(:hi_mom!)
|
226
|
-
instance.greet
|
227
|
-
end
|
228
|
-
|
229
|
-
it "should append the module to all resources" do
|
230
|
-
DataMapper::Resource.append_inclusions @module
|
231
|
-
|
232
|
-
objects = (1..5).map do
|
233
|
-
the_class = Class.new
|
234
|
-
the_class.class_eval(@class_code)
|
235
|
-
|
236
|
-
instance = the_class.new
|
237
|
-
instance.should_receive(:hi_mom!)
|
238
|
-
instance
|
239
|
-
end
|
240
|
-
|
241
|
-
objects.each { |obj| obj.greet }
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should append multiple modules to be included in resources" do
|
245
|
-
DataMapper::Resource.append_inclusions @module, @another_module
|
246
|
-
@class.class_eval(@class_code)
|
247
|
-
|
248
|
-
instance = @class.new
|
249
|
-
instance.should_receive(:hi_mom!)
|
250
|
-
instance.should_receive(:hi_dad!)
|
251
|
-
instance.greet
|
252
|
-
instance.hello
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should include the appended modules in order" do
|
256
|
-
module_one = Module.new do
|
257
|
-
def self.included(base); base.hi_mom!; end;
|
258
|
-
end
|
259
|
-
|
260
|
-
module_two = Module.new do
|
261
|
-
def self.included(base); base.hi_dad!; end;
|
262
|
-
end
|
263
|
-
|
264
|
-
DataMapper::Resource.append_inclusions module_two, module_one
|
265
|
-
|
266
|
-
@class.should_receive(:hi_dad!).once.ordered
|
267
|
-
@class.should_receive(:hi_mom!).once.ordered
|
268
|
-
|
269
|
-
@class.class_eval(@class_code)
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should append the module to extend resources with" do
|
273
|
-
DataMapper::Model.append_extensions @module
|
274
|
-
@class.class_eval(@class_code)
|
275
|
-
|
276
|
-
@class.should_receive(:hi_mom!)
|
277
|
-
@class.greet
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should extend all resources with the module" do
|
281
|
-
DataMapper::Model.append_extensions @module
|
282
|
-
|
283
|
-
classes = (1..5).map do
|
284
|
-
the_class = Class.new
|
285
|
-
the_class.class_eval(@class_code)
|
286
|
-
the_class.should_receive(:hi_mom!)
|
287
|
-
the_class
|
288
|
-
end
|
289
|
-
|
290
|
-
classes.each { |cla| cla.greet }
|
291
|
-
end
|
292
|
-
|
293
|
-
it "should append multiple modules to extend resources with" do
|
294
|
-
DataMapper::Model.append_extensions @module, @another_module
|
295
|
-
@class.class_eval(@class_code)
|
296
|
-
|
297
|
-
@class.should_receive(:hi_mom!)
|
298
|
-
@class.should_receive(:hi_dad!)
|
299
|
-
@class.greet
|
300
|
-
@class.hello
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should extend the resource in the order that the modules were appended" do
|
304
|
-
@module.class_eval do
|
305
|
-
def self.extended(base); base.hi_mom!; end;
|
306
|
-
end
|
307
|
-
|
308
|
-
@another_module.class_eval do
|
309
|
-
def self.extended(base); base.hi_dad!; end;
|
310
|
-
end
|
311
|
-
|
312
|
-
DataMapper::Model.append_extensions @another_module, @module
|
313
|
-
|
314
|
-
@class.should_receive(:hi_dad!).once.ordered
|
315
|
-
@class.should_receive(:hi_mom!).once.ordered
|
316
|
-
|
317
|
-
@class.class_eval(@class_code)
|
318
|
-
end
|
319
|
-
|
320
|
-
end
|
321
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
describe "DataMapper::NamingConventions" do
|
4
|
-
describe "Resource" do
|
5
|
-
it "should coerce a string into the Underscored convention" do
|
6
|
-
DataMapper::NamingConventions::Resource::Underscored.call('User').should == 'user'
|
7
|
-
DataMapper::NamingConventions::Resource::Underscored.call('UserAccountSetting').should == 'user_account_setting'
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should coerce a string into the UnderscoredAndPluralized convention" do
|
11
|
-
DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('User').should == 'users'
|
12
|
-
DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('UserAccountSetting').should == 'user_account_settings'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should coerce a string into the UnderscoredAndPluralized convention joining namespace with underscore" do
|
16
|
-
DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('Model::User').should == 'model_users'
|
17
|
-
DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call('Model::UserAccountSetting').should == 'model_user_account_settings'
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should coerce a string into the UnderscoredAndPluralizedWithoutModule convention" do
|
21
|
-
DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutModule.call('Model::User').should == 'users'
|
22
|
-
DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutModule.call('Model::UserAccountSetting').should == 'user_account_settings'
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should coerce a string into the Yaml convention" do
|
26
|
-
DataMapper::NamingConventions::Resource::Yaml.call('UserSetting').should == 'user_settings.yaml'
|
27
|
-
DataMapper::NamingConventions::Resource::Yaml.call('User').should == 'users.yaml'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "Field" do
|
32
|
-
it "should accept a property as input" do
|
33
|
-
DataMapper::NamingConventions::Field::Underscored.call(Article.blog_id).should == 'blog_id'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
-
|
3
|
-
class Icon
|
4
|
-
include DataMapper::Resource
|
5
|
-
|
6
|
-
property :id, Serial
|
7
|
-
property :name, String
|
8
|
-
property :width, Integer, :lazy => true
|
9
|
-
property :height, Integer, :lazy => true
|
10
|
-
end
|
11
|
-
|
12
|
-
class Boat
|
13
|
-
include DataMapper::Resource
|
14
|
-
property :name, String #not lazy
|
15
|
-
property :text, DataMapper::Types::Text #Lazy by default
|
16
|
-
property :notes, String, :lazy => true
|
17
|
-
property :a1, String, :lazy => [:ctx_a,:ctx_c]
|
18
|
-
property :a2, String, :lazy => [:ctx_a,:ctx_b]
|
19
|
-
property :a3, String, :lazy => [:ctx_a]
|
20
|
-
property :b1, String, :lazy => [:ctx_b]
|
21
|
-
property :b2, String, :lazy => [:ctx_b]
|
22
|
-
property :b3, String, :lazy => [:ctx_b]
|
23
|
-
end
|
24
|
-
|
25
|
-
describe DataMapper::PropertySet do
|
26
|
-
before :each do
|
27
|
-
@properties = Icon.properties(:default).dup
|
28
|
-
end
|
29
|
-
|
30
|
-
it "#slice should find properties" do
|
31
|
-
@properties.slice(:name, 'width').should have(2).entries
|
32
|
-
end
|
33
|
-
|
34
|
-
it "#select should find properties" do
|
35
|
-
@properties.select { |property| property.primitive == Integer }.should have(3).entries
|
36
|
-
end
|
37
|
-
|
38
|
-
it "#clear should clear out set" do
|
39
|
-
@properties.clear
|
40
|
-
@properties.key.should == []
|
41
|
-
@properties.defaults.should == []
|
42
|
-
@properties.length.should == 0
|
43
|
-
end
|
44
|
-
|
45
|
-
it "#[] should find properties by name (Symbol or String)" do
|
46
|
-
default_properties = [ :id, 'name', :width, 'height' ]
|
47
|
-
@properties.each_with_index do |property,i|
|
48
|
-
property.should == @properties[default_properties[i]]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should provide defaults" do
|
53
|
-
@properties.defaults.should have(2).entries
|
54
|
-
@properties.should have(4).entries
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should add a property for lazy loading to the :default context if a context is not supplied' do
|
58
|
-
Boat.properties(:default).lazy_context(:default).length.should == 2 # text & notes
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should return a list of contexts that a given field is in' do
|
62
|
-
props = Boat.properties(:default)
|
63
|
-
set = props.property_contexts(:a1)
|
64
|
-
set.include?(:ctx_a).should == true
|
65
|
-
set.include?(:ctx_c).should == true
|
66
|
-
set.include?(:ctx_b).should == false
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should return a list of expanded fields that should be loaded with a given field' do
|
70
|
-
props = Boat.properties(:default)
|
71
|
-
set = props.lazy_load_context(:a2)
|
72
|
-
expect = [:a1,:a2,:a3,:b1,:b2,:b3]
|
73
|
-
expect.should == set.sort! {|a,b| a.to_s <=> b.to_s}
|
74
|
-
end
|
75
|
-
|
76
|
-
describe 'when dup\'ed' do
|
77
|
-
it 'should duplicate the @entries ivar' do
|
78
|
-
@properties.dup.entries.should_not equal(@properties.entries)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'should reinitialize @properties_for' do
|
82
|
-
# force @properties_for to hold a property
|
83
|
-
Icon.properties(:default)[:name].should_not be_nil
|
84
|
-
@properties = Icon.properties(:default)
|
85
|
-
|
86
|
-
@properties.instance_variable_get("@property_for").should_not be_empty
|
87
|
-
@properties.dup.instance_variable_get("@property_for").should be_empty
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|