sam-dm-core 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +26 -0
- data/CONTRIBUTING +51 -0
- data/FAQ +92 -0
- data/History.txt +145 -0
- data/MIT-LICENSE +22 -0
- data/Manifest.txt +125 -0
- data/QUICKLINKS +12 -0
- data/README.txt +143 -0
- data/Rakefile +30 -0
- data/SPECS +63 -0
- data/TODO +1 -0
- data/lib/dm-core.rb +224 -0
- data/lib/dm-core/adapters.rb +4 -0
- data/lib/dm-core/adapters/abstract_adapter.rb +202 -0
- data/lib/dm-core/adapters/data_objects_adapter.rb +707 -0
- data/lib/dm-core/adapters/mysql_adapter.rb +136 -0
- data/lib/dm-core/adapters/postgres_adapter.rb +188 -0
- data/lib/dm-core/adapters/sqlite3_adapter.rb +105 -0
- data/lib/dm-core/associations.rb +199 -0
- data/lib/dm-core/associations/many_to_many.rb +147 -0
- data/lib/dm-core/associations/many_to_one.rb +107 -0
- data/lib/dm-core/associations/one_to_many.rb +309 -0
- data/lib/dm-core/associations/one_to_one.rb +61 -0
- data/lib/dm-core/associations/relationship.rb +218 -0
- data/lib/dm-core/associations/relationship_chain.rb +81 -0
- data/lib/dm-core/auto_migrations.rb +113 -0
- data/lib/dm-core/collection.rb +638 -0
- data/lib/dm-core/dependency_queue.rb +31 -0
- data/lib/dm-core/hook.rb +11 -0
- data/lib/dm-core/identity_map.rb +45 -0
- data/lib/dm-core/is.rb +16 -0
- data/lib/dm-core/logger.rb +232 -0
- data/lib/dm-core/migrations/destructive_migrations.rb +17 -0
- data/lib/dm-core/migrator.rb +29 -0
- data/lib/dm-core/model.rb +471 -0
- data/lib/dm-core/naming_conventions.rb +84 -0
- data/lib/dm-core/property.rb +673 -0
- data/lib/dm-core/property_set.rb +162 -0
- data/lib/dm-core/query.rb +625 -0
- data/lib/dm-core/repository.rb +159 -0
- data/lib/dm-core/resource.rb +637 -0
- data/lib/dm-core/scope.rb +58 -0
- data/lib/dm-core/support.rb +7 -0
- data/lib/dm-core/support/array.rb +13 -0
- data/lib/dm-core/support/assertions.rb +8 -0
- data/lib/dm-core/support/errors.rb +23 -0
- data/lib/dm-core/support/kernel.rb +7 -0
- data/lib/dm-core/support/symbol.rb +41 -0
- data/lib/dm-core/transaction.rb +267 -0
- data/lib/dm-core/type.rb +160 -0
- data/lib/dm-core/type_map.rb +80 -0
- data/lib/dm-core/types.rb +19 -0
- data/lib/dm-core/types/boolean.rb +7 -0
- data/lib/dm-core/types/discriminator.rb +34 -0
- data/lib/dm-core/types/object.rb +24 -0
- data/lib/dm-core/types/paranoid_boolean.rb +34 -0
- data/lib/dm-core/types/paranoid_datetime.rb +33 -0
- data/lib/dm-core/types/serial.rb +9 -0
- data/lib/dm-core/types/text.rb +10 -0
- data/lib/dm-core/version.rb +3 -0
- data/script/all +5 -0
- data/script/performance.rb +203 -0
- data/script/profile.rb +87 -0
- data/spec/integration/association_spec.rb +1371 -0
- data/spec/integration/association_through_spec.rb +203 -0
- data/spec/integration/associations/many_to_many_spec.rb +449 -0
- data/spec/integration/associations/many_to_one_spec.rb +163 -0
- data/spec/integration/associations/one_to_many_spec.rb +151 -0
- data/spec/integration/auto_migrations_spec.rb +398 -0
- data/spec/integration/collection_spec.rb +1069 -0
- data/spec/integration/data_objects_adapter_spec.rb +32 -0
- data/spec/integration/dependency_queue_spec.rb +58 -0
- data/spec/integration/model_spec.rb +127 -0
- data/spec/integration/mysql_adapter_spec.rb +85 -0
- data/spec/integration/postgres_adapter_spec.rb +731 -0
- data/spec/integration/property_spec.rb +233 -0
- data/spec/integration/query_spec.rb +506 -0
- data/spec/integration/repository_spec.rb +57 -0
- data/spec/integration/resource_spec.rb +475 -0
- data/spec/integration/sqlite3_adapter_spec.rb +352 -0
- data/spec/integration/sti_spec.rb +208 -0
- data/spec/integration/strategic_eager_loading_spec.rb +138 -0
- data/spec/integration/transaction_spec.rb +75 -0
- data/spec/integration/type_spec.rb +271 -0
- data/spec/lib/logging_helper.rb +18 -0
- data/spec/lib/mock_adapter.rb +27 -0
- data/spec/lib/model_loader.rb +91 -0
- data/spec/lib/publicize_methods.rb +28 -0
- data/spec/models/vehicles.rb +34 -0
- data/spec/models/zoo.rb +47 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/unit/adapters/abstract_adapter_spec.rb +133 -0
- data/spec/unit/adapters/adapter_shared_spec.rb +15 -0
- data/spec/unit/adapters/data_objects_adapter_spec.rb +628 -0
- data/spec/unit/adapters/postgres_adapter_spec.rb +133 -0
- data/spec/unit/associations/many_to_many_spec.rb +17 -0
- data/spec/unit/associations/many_to_one_spec.rb +152 -0
- data/spec/unit/associations/one_to_many_spec.rb +393 -0
- data/spec/unit/associations/one_to_one_spec.rb +7 -0
- data/spec/unit/associations/relationship_spec.rb +71 -0
- data/spec/unit/associations_spec.rb +242 -0
- data/spec/unit/auto_migrations_spec.rb +111 -0
- data/spec/unit/collection_spec.rb +182 -0
- data/spec/unit/data_mapper_spec.rb +35 -0
- data/spec/unit/identity_map_spec.rb +126 -0
- data/spec/unit/is_spec.rb +80 -0
- data/spec/unit/migrator_spec.rb +33 -0
- data/spec/unit/model_spec.rb +339 -0
- data/spec/unit/naming_conventions_spec.rb +36 -0
- data/spec/unit/property_set_spec.rb +83 -0
- data/spec/unit/property_spec.rb +753 -0
- data/spec/unit/query_spec.rb +530 -0
- data/spec/unit/repository_spec.rb +93 -0
- data/spec/unit/resource_spec.rb +626 -0
- data/spec/unit/scope_spec.rb +142 -0
- data/spec/unit/transaction_spec.rb +493 -0
- data/spec/unit/type_map_spec.rb +114 -0
- data/spec/unit/type_spec.rb +119 -0
- data/tasks/ci.rb +68 -0
- data/tasks/dm.rb +63 -0
- data/tasks/doc.rb +20 -0
- data/tasks/gemspec.rb +23 -0
- data/tasks/hoe.rb +46 -0
- data/tasks/install.rb +20 -0
- metadata +216 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Associations::Relationship do
|
4
|
+
|
5
|
+
load_models_for_metaphor :vehicles
|
6
|
+
|
7
|
+
it "should describe an association" do
|
8
|
+
belongs_to = DataMapper::Associations::Relationship.new(
|
9
|
+
:manufacturer,
|
10
|
+
:mock,
|
11
|
+
'Vehicle',
|
12
|
+
'Manufacturer',
|
13
|
+
{ :child_key => [ :manufacturer_id ] }
|
14
|
+
)
|
15
|
+
|
16
|
+
belongs_to.should respond_to(:name)
|
17
|
+
belongs_to.should respond_to(:with_repository)
|
18
|
+
belongs_to.should respond_to(:child_key)
|
19
|
+
belongs_to.should respond_to(:parent_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should map properties explicitly when an association method passes them in its options" do
|
23
|
+
belongs_to = DataMapper::Associations::Relationship.new(
|
24
|
+
:manufacturer,
|
25
|
+
:mock,
|
26
|
+
'Vehicle',
|
27
|
+
'Manufacturer',
|
28
|
+
{ :child_key => [ :manufacturer_id ], :parent_key => [ :id ] }
|
29
|
+
)
|
30
|
+
|
31
|
+
belongs_to.name.should == :manufacturer
|
32
|
+
belongs_to.with_repository do |r|
|
33
|
+
r.name.should == :mock
|
34
|
+
end
|
35
|
+
|
36
|
+
belongs_to.child_key.should be_a_kind_of(DataMapper::PropertySet)
|
37
|
+
belongs_to.parent_key.should be_a_kind_of(DataMapper::PropertySet)
|
38
|
+
|
39
|
+
belongs_to.child_key.to_a.should == Vehicle.properties(:mock).slice(:manufacturer_id)
|
40
|
+
belongs_to.parent_key.to_a.should == Manufacturer.properties(:mock).key
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should infer properties when options aren't passed" do
|
44
|
+
has_many = DataMapper::Associations::Relationship.new(
|
45
|
+
:models,
|
46
|
+
:mock,
|
47
|
+
'Vehicle',
|
48
|
+
'Manufacturer',
|
49
|
+
{ :child_key => [:model_id] }
|
50
|
+
)
|
51
|
+
|
52
|
+
has_many.name.should == :models
|
53
|
+
has_many.with_repository do |r|
|
54
|
+
r.name.should == :mock
|
55
|
+
end
|
56
|
+
|
57
|
+
has_many.child_key.should be_a_kind_of(DataMapper::PropertySet)
|
58
|
+
has_many.parent_key.should be_a_kind_of(DataMapper::PropertySet)
|
59
|
+
# Vehicle.has n, :models, :class_name => 'Manufacturer', :child_key => "models_id"
|
60
|
+
has_many.child_key.to_a.should == Vehicle.properties(:mock).slice(:model_id)
|
61
|
+
has_many.parent_key.to_a.should == Manufacturer.properties(:mock).key
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should generate child properties with a safe subset of the parent options" do
|
65
|
+
pending
|
66
|
+
# For example, :size would be an option you'd want a generated child Property to copy,
|
67
|
+
# but :serial or :key obviously not. So need to take a good look at Property::OPTIONS to
|
68
|
+
# see what applies and what doesn't.
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe "DataMapper::Associations" do
|
4
|
+
|
5
|
+
load_models_for_metaphor :vehicles
|
6
|
+
|
7
|
+
before do
|
8
|
+
@relationship = mock(DataMapper::Associations::Relationship)
|
9
|
+
@n = 1.0/0
|
10
|
+
|
11
|
+
Manufacturer.mock_relationship = Vehicle.mock_relationship = @relationship
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#many_to_one_relationships" do
|
15
|
+
before :all do
|
16
|
+
module MTORelationships
|
17
|
+
class A
|
18
|
+
include DataMapper::Resource
|
19
|
+
def self.default_repository_name
|
20
|
+
:a_db
|
21
|
+
end
|
22
|
+
repository(:b_db) do
|
23
|
+
belongs_to :b
|
24
|
+
end
|
25
|
+
repository(:c_db) do
|
26
|
+
belongs_to :c
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class B
|
30
|
+
include DataMapper::Resource
|
31
|
+
def self.default_repository_name
|
32
|
+
:b_db
|
33
|
+
end
|
34
|
+
end
|
35
|
+
class C
|
36
|
+
include DataMapper::Resource
|
37
|
+
def self.default_repository_name
|
38
|
+
:c_db
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
it "should list all relationships that are one-to-many" do
|
44
|
+
MTORelationships::A.many_to_one_relationships.sort_by { |r| r.name.to_s }.should == [MTORelationships::A.relationships(:b_db)[:b], MTORelationships::A.relationships(:c_db)[:c]]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ".relationships" do
|
49
|
+
class B
|
50
|
+
include DataMapper::Resource
|
51
|
+
end
|
52
|
+
|
53
|
+
class C
|
54
|
+
include DataMapper::Resource
|
55
|
+
|
56
|
+
repository(:mock) do
|
57
|
+
has 1, :b
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class D
|
62
|
+
include DataMapper::Resource
|
63
|
+
has 1, :b
|
64
|
+
end
|
65
|
+
|
66
|
+
class E < D
|
67
|
+
end
|
68
|
+
|
69
|
+
class F < D
|
70
|
+
has 1, :a
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should assume the default repository when no arguments are passed" do
|
74
|
+
lambda do
|
75
|
+
C.relationships
|
76
|
+
end.should_not raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return the right set of relationships given the repository name" do
|
80
|
+
C.relationships.should be_empty
|
81
|
+
C.relationships(:mock).should_not be_empty
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should return the right set of relationships given the inheritance" do
|
85
|
+
E.relationships.should have(1).entries
|
86
|
+
D.relationships.should have(1).entries
|
87
|
+
F.relationships.should have(2).entries
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe ".has" do
|
92
|
+
|
93
|
+
it "should allow a declaration" do
|
94
|
+
lambda do
|
95
|
+
class Manufacturer
|
96
|
+
has 1, :halo_car
|
97
|
+
end
|
98
|
+
end.should_not raise_error
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should not allow a constraint that is not an Integer, Range or Infinity" do
|
102
|
+
lambda do
|
103
|
+
class Manufacturer
|
104
|
+
has '1', :halo_car
|
105
|
+
end
|
106
|
+
end.should raise_error(ArgumentError)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should not allow a constraint where the min is larger than the max" do
|
110
|
+
lambda do
|
111
|
+
class Manufacturer
|
112
|
+
has 1..0, :halo_car
|
113
|
+
end
|
114
|
+
end.should raise_error(ArgumentError)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should not allow overwriting of the auto assigned min/max values with keys" do
|
118
|
+
DataMapper::Associations::OneToMany.should_receive(:setup).
|
119
|
+
with(:vehicles, Manufacturer, { :min => 1, :max => 2 }).
|
120
|
+
and_return(@relationship)
|
121
|
+
|
122
|
+
class Manufacturer
|
123
|
+
has(1..2, :vehicles, :min => 5, :max => 10).should == mock_relationship
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "one-to-one syntax" do
|
128
|
+
it "should create a basic one-to-one association with fixed constraint" do
|
129
|
+
DataMapper::Associations::OneToOne.should_receive(:setup).
|
130
|
+
with(:halo_car, Manufacturer, { :min => 1, :max => 1 }).
|
131
|
+
and_return(@relationship)
|
132
|
+
|
133
|
+
class Manufacturer
|
134
|
+
has(1, :halo_car).should == mock_relationship
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should create a basic one-to-one association with min/max constraints" do
|
139
|
+
DataMapper::Associations::OneToOne.should_receive(:setup).
|
140
|
+
with(:halo_car, Manufacturer, { :min => 0, :max => 1 }).
|
141
|
+
and_return(@relationship)
|
142
|
+
|
143
|
+
class Manufacturer
|
144
|
+
has(0..1, :halo_car).should == mock_relationship
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should create a one-to-one association with options" do
|
149
|
+
DataMapper::Associations::OneToOne.should_receive(:setup).
|
150
|
+
with(:halo_car, Manufacturer, { :min => 1, :max => 1, :class_name => 'Car' }).
|
151
|
+
and_return(@relationship)
|
152
|
+
|
153
|
+
class Manufacturer
|
154
|
+
has(1, :halo_car, :class_name => 'Car').should == mock_relationship
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe "one-to-many syntax" do
|
160
|
+
it "should create a basic one-to-many association with no constraints" do
|
161
|
+
DataMapper::Associations::OneToMany.should_receive(:setup).
|
162
|
+
with(:vehicles, Manufacturer, { :min => 0, :max => @n }).
|
163
|
+
and_return(@relationship)
|
164
|
+
|
165
|
+
class Manufacturer
|
166
|
+
has(n, :vehicles).should == mock_relationship
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should create a one-to-many association with fixed constraint" do
|
171
|
+
DataMapper::Associations::OneToMany.should_receive(:setup).
|
172
|
+
with(:vehicles, Manufacturer, { :min => 4, :max => 4 }).
|
173
|
+
and_return(@relationship)
|
174
|
+
|
175
|
+
class Manufacturer
|
176
|
+
has(4, :vehicles).should == mock_relationship
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should create a one-to-many association with min/max constraints" do
|
181
|
+
DataMapper::Associations::OneToMany.should_receive(:setup).
|
182
|
+
with(:vehicles, Manufacturer, { :min => 2, :max => 4 }).
|
183
|
+
and_return(@relationship)
|
184
|
+
|
185
|
+
class Manufacturer
|
186
|
+
has(2..4, :vehicles).should == mock_relationship
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should create a one-to-many association with options" do
|
191
|
+
DataMapper::Associations::OneToMany.should_receive(:setup).
|
192
|
+
with(:vehicles, Manufacturer, { :min => 1, :max => @n, :class_name => 'Car' }).
|
193
|
+
and_return(@relationship)
|
194
|
+
|
195
|
+
class Manufacturer
|
196
|
+
has(1..n, :vehicles, :class_name => 'Car').should == mock_relationship
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# do not remove or change this spec.
|
201
|
+
it "should raise an exception when n..n is used for the cardinality" do
|
202
|
+
lambda do
|
203
|
+
class Manufacturer
|
204
|
+
has n..n, :subsidiaries, :class_name => 'Manufacturer'
|
205
|
+
end
|
206
|
+
end.should raise_error(ArgumentError)
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should create one-to-many association and pass the :through option if specified" do
|
210
|
+
DataMapper::Associations::OneToMany.should_receive(:setup).
|
211
|
+
with(:suppliers, Vehicle, { :min => 0, :max => @n, :through => :manufacturers }).
|
212
|
+
and_return(@relationship)
|
213
|
+
|
214
|
+
class Vehicle
|
215
|
+
has(n, :suppliers, :through => :manufacturers).should == mock_relationship
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe ".belongs_to" do
|
222
|
+
it "should create a basic many-to-one association" do
|
223
|
+
DataMapper::Associations::ManyToOne.should_receive(:setup).
|
224
|
+
with(:vehicle, Manufacturer, {}).
|
225
|
+
and_return(@relationship)
|
226
|
+
|
227
|
+
class Manufacturer
|
228
|
+
belongs_to(:vehicle).should == mock_relationship
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should create a many-to-one association with options" do
|
233
|
+
DataMapper::Associations::ManyToOne.should_receive(:setup).
|
234
|
+
with(:vehicle, Manufacturer, { :class_name => 'Car' }).
|
235
|
+
and_return(@relationship)
|
236
|
+
|
237
|
+
class Manufacturer
|
238
|
+
belongs_to(:vehicle, :class_name => 'Car').should == mock_relationship
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
|
+
|
4
|
+
require DataMapper.root / 'lib' / 'dm-core' / 'repository'
|
5
|
+
require DataMapper.root / 'lib' / 'dm-core' / 'resource'
|
6
|
+
require DataMapper.root / 'lib' / 'dm-core' / 'auto_migrations'
|
7
|
+
|
8
|
+
describe DataMapper::AutoMigrations do
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
@cow = Class.new do
|
12
|
+
include DataMapper::Resource
|
13
|
+
|
14
|
+
property :name, String, :key => true
|
15
|
+
property :age, Integer
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
DataMapper::Resource.descendants.clear
|
21
|
+
end
|
22
|
+
|
23
|
+
after(:each) do
|
24
|
+
DataMapper::Resource.descendants.clear
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should add the resource class to AutoMigrator's models on a mixin" do
|
28
|
+
@class = Class.new do
|
29
|
+
include DataMapper::Resource
|
30
|
+
end
|
31
|
+
|
32
|
+
DataMapper::Resource.descendants.should include(@class)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should add the #auto_migrate! method on a mixin" do
|
36
|
+
@cat = Class.new do
|
37
|
+
include DataMapper::Resource
|
38
|
+
|
39
|
+
property :name, String, :key => true
|
40
|
+
property :age, Integer
|
41
|
+
end
|
42
|
+
|
43
|
+
@cat.should respond_to(:auto_migrate!)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should add the #auto_upgrade! method on a mixin" do
|
47
|
+
@cat = Class.new do
|
48
|
+
include DataMapper::Resource
|
49
|
+
|
50
|
+
property :name, String, :key => true
|
51
|
+
property :age, Integer
|
52
|
+
end
|
53
|
+
|
54
|
+
@cat.should respond_to(:auto_upgrade!)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should not conflict with other Migrators on a mixin" do
|
58
|
+
migrator_class = Class.new(DataMapper::Migrator)
|
59
|
+
|
60
|
+
included_proc = lambda { |model| migrator_class.models << model }
|
61
|
+
|
62
|
+
migrator_mixin = Module.new do
|
63
|
+
self.class.send(:define_method, :included, &included_proc)
|
64
|
+
end
|
65
|
+
|
66
|
+
model_class = Class.new do
|
67
|
+
include DataMapper::Resource
|
68
|
+
include migrator_mixin
|
69
|
+
|
70
|
+
property :name, String
|
71
|
+
property :age, String
|
72
|
+
end
|
73
|
+
|
74
|
+
DataMapper::Resource.descendants.should include(model_class)
|
75
|
+
migrator_class.models.should include(model_class)
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#auto_migrate" do
|
79
|
+
before do
|
80
|
+
@repository_name = mock('repository name')
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should call each model's auto_migrate! method" do
|
84
|
+
models = [:cat, :dog, :fish, :cow].map {|m| mock(m)}
|
85
|
+
|
86
|
+
models.each do |model|
|
87
|
+
DataMapper::Resource.descendants << model
|
88
|
+
model.should_receive(:auto_migrate_down!).with(@repository_name)
|
89
|
+
model.should_receive(:auto_migrate_up!).with(@repository_name)
|
90
|
+
end
|
91
|
+
|
92
|
+
DataMapper::AutoMigrator.auto_migrate(@repository_name)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
describe "#auto_upgrade" do
|
96
|
+
before do
|
97
|
+
@repository_name = mock('repository name')
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should call each model's auto_upgrade! method" do
|
101
|
+
models = [:cat, :dog, :fish, :cow].map {|m| mock(m)}
|
102
|
+
|
103
|
+
models.each do |model|
|
104
|
+
DataMapper::Resource.descendants << model
|
105
|
+
model.should_receive(:auto_upgrade!).with(@repository_name)
|
106
|
+
end
|
107
|
+
|
108
|
+
DataMapper::AutoMigrator.auto_upgrade(@repository_name)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
|
+
|
3
|
+
# ensure the Collection is extremely similar to an Array
|
4
|
+
# since it will be returned by Respository#all to return
|
5
|
+
# multiple resources to the caller
|
6
|
+
describe DataMapper::Collection do
|
7
|
+
before do
|
8
|
+
@property = mock('property')
|
9
|
+
@model = mock('model', :inheritance_property => [ @property ], :key => [ @property ])
|
10
|
+
@query = mock('query', :kind_of? => true, :fields => [ @property ], :model => @model)
|
11
|
+
|
12
|
+
@collection = DataMapper::Collection.new(@query) {}
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should provide #<<' do
|
16
|
+
@collection.should respond_to(:<<)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should provide #all' do
|
20
|
+
@collection.should respond_to(:all)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should provide #at' do
|
24
|
+
@collection.should respond_to(:at)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should provide #build' do
|
28
|
+
@collection.should respond_to(:build)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should provide #clear' do
|
32
|
+
@collection.should respond_to(:clear)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should provide #collect!' do
|
36
|
+
@collection.should respond_to(:collect!)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should provide #concat' do
|
40
|
+
@collection.should respond_to(:concat)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should provide #create' do
|
44
|
+
@collection.should respond_to(:create)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should provide #delete' do
|
48
|
+
@collection.should respond_to(:delete)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should provide #delete_at' do
|
52
|
+
@collection.should respond_to(:delete_at)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should provide #destroy!' do
|
56
|
+
@collection.should respond_to(:destroy!)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should provide #each' do
|
60
|
+
@collection.should respond_to(:each)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should provide #each_index' do
|
64
|
+
@collection.should respond_to(:each_index)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should provide #eql?' do
|
68
|
+
@collection.should respond_to(:eql?)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should provide #fetch' do
|
72
|
+
@collection.should respond_to(:fetch)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should provide #first' do
|
76
|
+
@collection.should respond_to(:first)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should provide #freeze' do
|
80
|
+
@collection.should respond_to(:freeze)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should provide #get' do
|
84
|
+
@collection.should respond_to(:get)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should provide #get!' do
|
88
|
+
@collection.should respond_to(:get!)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should provide #insert' do
|
92
|
+
@collection.should respond_to(:insert)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should provide #last' do
|
96
|
+
@collection.should respond_to(:last)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should provide #load' do
|
100
|
+
@collection.should respond_to(:load)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should provide #loaded?' do
|
104
|
+
@collection.should respond_to(:loaded?)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should provide #pop' do
|
108
|
+
@collection.should respond_to(:pop)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should provide #push' do
|
112
|
+
@collection.should respond_to(:push)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should provide #properties' do
|
116
|
+
@collection.should respond_to(:properties)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should provide #reject' do
|
120
|
+
@collection.should respond_to(:reject)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should provide #reject!' do
|
124
|
+
@collection.should respond_to(:reject!)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should provide #relationships' do
|
128
|
+
@collection.should respond_to(:relationships)
|
129
|
+
end
|
130
|
+
|
131
|
+
it 'should provide #reload' do
|
132
|
+
@collection.should respond_to(:reload)
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should provide #reverse' do
|
136
|
+
@collection.should respond_to(:reverse)
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'should provide #reverse!' do
|
140
|
+
@collection.should respond_to(:reverse!)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should provide #reverse_each' do
|
144
|
+
@collection.should respond_to(:reverse_each)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should provide #select' do
|
148
|
+
@collection.should respond_to(:select)
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should provide #shift' do
|
152
|
+
@collection.should respond_to(:shift)
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should provide #slice' do
|
156
|
+
@collection.should respond_to(:slice)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should provide #slice!' do
|
160
|
+
@collection.should respond_to(:slice!)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should provide #sort' do
|
164
|
+
@collection.should respond_to(:sort)
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should provide #sort!' do
|
168
|
+
@collection.should respond_to(:sort!)
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should provide #unshift' do
|
172
|
+
@collection.should respond_to(:unshift)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should provide #update!' do
|
176
|
+
@collection.should respond_to(:update!)
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should provide #values_at' do
|
180
|
+
@collection.should respond_to(:values_at)
|
181
|
+
end
|
182
|
+
end
|