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.
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
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
2
-
3
- describe "DataMapper::Associations::OneToOne" do
4
-
5
- it "should allow a declaration" do
6
- end
7
- end
@@ -1,71 +0,0 @@
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
@@ -1,242 +0,0 @@
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', :child_key => [ :car_id ]).
235
- and_return(@relationship)
236
-
237
- class ::Manufacturer
238
- belongs_to(:vehicle, :class_name => 'Car', :child_key => [ :car_id ]).should == mock_relationship
239
- end
240
- end
241
- end
242
- end
@@ -1,111 +0,0 @@
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
@@ -1,182 +0,0 @@
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