datamapper 0.2.5 → 0.3.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/CHANGELOG +5 -1
- data/FAQ +96 -0
- data/QUICKLINKS +12 -0
- data/README +57 -155
- data/environment.rb +61 -43
- data/example.rb +30 -12
- data/lib/data_mapper.rb +6 -1
- data/lib/data_mapper/adapters/abstract_adapter.rb +0 -57
- data/lib/data_mapper/adapters/data_object_adapter.rb +203 -97
- data/lib/data_mapper/adapters/mysql_adapter.rb +4 -0
- data/lib/data_mapper/adapters/postgresql_adapter.rb +7 -1
- data/lib/data_mapper/adapters/sql/coersion.rb +3 -2
- data/lib/data_mapper/adapters/sql/commands/load_command.rb +29 -10
- data/lib/data_mapper/adapters/sql/mappings/associations_set.rb +4 -0
- data/lib/data_mapper/adapters/sql/mappings/column.rb +13 -9
- data/lib/data_mapper/adapters/sql/mappings/conditions.rb +172 -0
- data/lib/data_mapper/adapters/sql/mappings/table.rb +43 -17
- data/lib/data_mapper/adapters/sqlite3_adapter.rb +9 -2
- data/lib/data_mapper/associations.rb +75 -3
- data/lib/data_mapper/associations/belongs_to_association.rb +70 -36
- data/lib/data_mapper/associations/has_and_belongs_to_many_association.rb +195 -86
- data/lib/data_mapper/associations/has_many_association.rb +168 -61
- data/lib/data_mapper/associations/has_n_association.rb +23 -3
- data/lib/data_mapper/attributes.rb +73 -0
- data/lib/data_mapper/auto_migrations.rb +2 -6
- data/lib/data_mapper/base.rb +5 -9
- data/lib/data_mapper/database.rb +4 -3
- data/lib/data_mapper/embedded_value.rb +66 -30
- data/lib/data_mapper/identity_map.rb +1 -3
- data/lib/data_mapper/is/tree.rb +121 -0
- data/lib/data_mapper/migration.rb +155 -0
- data/lib/data_mapper/persistence.rb +532 -218
- data/lib/data_mapper/property.rb +306 -0
- data/lib/data_mapper/query.rb +164 -0
- data/lib/data_mapper/support/blank.rb +2 -2
- data/lib/data_mapper/support/connection_pool.rb +5 -6
- data/lib/data_mapper/support/enumerable.rb +3 -3
- data/lib/data_mapper/support/errors.rb +10 -1
- data/lib/data_mapper/support/inflector.rb +174 -238
- data/lib/data_mapper/support/object.rb +54 -0
- data/lib/data_mapper/support/serialization.rb +19 -1
- data/lib/data_mapper/support/string.rb +7 -16
- data/lib/data_mapper/support/symbol.rb +3 -15
- data/lib/data_mapper/support/typed_set.rb +68 -0
- data/lib/data_mapper/types/base.rb +44 -0
- data/lib/data_mapper/types/string.rb +34 -0
- data/lib/data_mapper/validations/number_validator.rb +40 -0
- data/lib/data_mapper/validations/string_validator.rb +20 -0
- data/lib/data_mapper/validations/validator.rb +13 -0
- data/performance.rb +26 -1
- data/profile_data_mapper.rb +1 -1
- data/rakefile.rb +42 -2
- data/spec/acts_as_tree_spec.rb +11 -3
- data/spec/adapters/data_object_adapter_spec.rb +31 -0
- data/spec/associations/belongs_to_association_spec.rb +98 -0
- data/spec/associations/has_and_belongs_to_many_association_spec.rb +377 -0
- data/spec/associations/has_many_association_spec.rb +337 -0
- data/spec/attributes_spec.rb +23 -1
- data/spec/auto_migrations_spec.rb +86 -29
- data/spec/callbacks_spec.rb +107 -0
- data/spec/column_spec.rb +5 -2
- data/spec/count_command_spec.rb +33 -1
- data/spec/database_spec.rb +18 -0
- data/spec/dependency_spec.rb +4 -2
- data/spec/embedded_value_spec.rb +8 -8
- data/spec/fixtures/people.yaml +1 -1
- data/spec/fixtures/projects.yaml +10 -1
- data/spec/fixtures/tasks.yaml +6 -0
- data/spec/fixtures/tasks_tasks.yaml +2 -0
- data/spec/fixtures/tomatoes.yaml +1 -0
- data/spec/is_a_tree_spec.rb +149 -0
- data/spec/load_command_spec.rb +71 -9
- data/spec/magic_columns_spec.rb +17 -2
- data/spec/migration_spec.rb +267 -0
- data/spec/models/animal.rb +1 -1
- data/spec/models/candidate.rb +8 -0
- data/spec/models/career.rb +1 -1
- data/spec/models/chain.rb +8 -0
- data/spec/models/comment.rb +1 -1
- data/spec/models/exhibit.rb +1 -1
- data/spec/models/fence.rb +7 -0
- data/spec/models/fruit.rb +2 -2
- data/spec/models/job.rb +8 -0
- data/spec/models/person.rb +2 -3
- data/spec/models/post.rb +1 -1
- data/spec/models/project.rb +21 -1
- data/spec/models/section.rb +1 -1
- data/spec/models/serializer.rb +1 -1
- data/spec/models/task.rb +9 -0
- data/spec/models/tomato.rb +27 -0
- data/spec/models/user.rb +8 -2
- data/spec/models/zoo.rb +2 -7
- data/spec/paranoia_spec.rb +1 -1
- data/spec/{base_spec.rb → persistence_spec.rb} +207 -18
- data/spec/postgres_spec.rb +48 -6
- data/spec/property_spec.rb +90 -9
- data/spec/query_spec.rb +71 -5
- data/spec/save_command_spec.rb +11 -0
- data/spec/spec_helper.rb +14 -11
- data/spec/support/blank_spec.rb +8 -0
- data/spec/support/inflector_spec.rb +41 -0
- data/spec/support/object_spec.rb +9 -0
- data/spec/{serialization_spec.rb → support/serialization_spec.rb} +1 -1
- data/spec/support/silence_spec.rb +15 -0
- data/spec/{support_spec.rb → support/string_spec.rb} +3 -3
- data/spec/support/struct_spec.rb +12 -0
- data/spec/support/typed_set_spec.rb +66 -0
- data/spec/table_spec.rb +3 -3
- data/spec/types/string.rb +81 -0
- data/spec/validates_uniqueness_of_spec.rb +17 -0
- data/spec/validations/number_validator.rb +59 -0
- data/spec/validations/string_validator.rb +14 -0
- metadata +59 -17
- data/do_performance.rb +0 -153
- data/lib/data_mapper/support/active_record_impersonation.rb +0 -103
- data/lib/data_mapper/support/weak_hash.rb +0 -46
- data/spec/active_record_impersonation_spec.rb +0 -129
- data/spec/associations_spec.rb +0 -232
- data/spec/conditions_spec.rb +0 -49
- data/spec/has_many_association_spec.rb +0 -173
- data/spec/models/animals_exhibit.rb +0 -8
@@ -0,0 +1,337 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe DataMapper::Associations::HasManyAssociation do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
fixtures(:zoos)
|
7
|
+
fixtures(:exhibits)
|
8
|
+
fixtures(:fruit)
|
9
|
+
fixtures(:animals)
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:all) do
|
13
|
+
fixtures(:fruit)
|
14
|
+
fixtures(:animals)
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@zoo = Zoo.new(:name => "ZOO")
|
19
|
+
@zoo.save
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
@zoo.destroy!
|
24
|
+
Chain.delete_all
|
25
|
+
Fence.delete_all
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should provide a shallow_append method that doesn't impact the complementary association" do
|
29
|
+
project = Project.new
|
30
|
+
section = Section.new
|
31
|
+
project.sections.shallow_append(section)
|
32
|
+
section.project.should be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "assignment should not force associated items to load" do
|
36
|
+
dallas = Zoo.first(:name => 'Dallas')
|
37
|
+
Exhibit.new(:name => 'Weasel World!', :zoo => dallas)
|
38
|
+
dallas.exhibits.instance_variable_get('@items').should be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should use << for assignment" do
|
42
|
+
bob_land = Zoo.new(:name => 'Bob Land!')
|
43
|
+
bob_land.exhibits << Exhibit.new(:name => 'Cow')
|
44
|
+
bob_land.exhibits.should have(1).entries
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return an empty Enumerable for new objects" do
|
48
|
+
project = Project.new
|
49
|
+
project.sections.should be_a_kind_of(Enumerable)
|
50
|
+
project.sections.should be_empty
|
51
|
+
project.sections.should be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should display correctly when inspected" do
|
55
|
+
Zoo.first(:name => 'Dallas').exhibits.inspect.should match(/\#\<Exhibit\:0x.{7}/)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should lazily-load the association when Enumerable methods are called' do
|
59
|
+
database do |db|
|
60
|
+
san_diego = Zoo.first(:name => 'San Diego')
|
61
|
+
san_diego.exhibits.size.should == 2
|
62
|
+
san_diego.exhibits.should include(Exhibit.first(:name => 'Monkey Mayhem'))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should eager-load associations for an entire set' do
|
67
|
+
database do
|
68
|
+
zoos = Zoo.all
|
69
|
+
zoos.each do |zoo|
|
70
|
+
zoo.exhibits.each do |exhibit|
|
71
|
+
exhibit.zoo.should == zoo
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should be dirty even when clean objects are associated" do
|
78
|
+
zoo = Zoo.first(:name => 'New York')
|
79
|
+
zoo.exhibits << Exhibit.first
|
80
|
+
zoo.should be_dirty
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should proxy associations on the associated type" do
|
84
|
+
Zoo.first(:name => 'Miami').exhibits.animals.size.should == 1
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have a valid zoo setup for testing" do
|
88
|
+
@zoo.should be_valid
|
89
|
+
@zoo.should_not be_a_new_record
|
90
|
+
@zoo.id.should_not be_nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should generate the SQL for a join statement" do
|
94
|
+
exhibits_association = database(:mock).schema[Zoo].associations.find { |a| a.name == :exhibits }
|
95
|
+
|
96
|
+
exhibits_association.to_sql.should == <<-EOS.compress_lines
|
97
|
+
JOIN `exhibits` ON `exhibits`.`zoo_id` = `zoos`.`id`
|
98
|
+
EOS
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should add an item to an association" do
|
102
|
+
bear = Exhibit.new( :name => "Bear")
|
103
|
+
@zoo.exhibits << bear
|
104
|
+
@zoo.exhibits.should include(bear)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should build a new item" do
|
108
|
+
bear = @zoo.exhibits.build( :name => "Bear" )
|
109
|
+
bear.should be_kind_of(Exhibit)
|
110
|
+
@zoo.exhibits.should include(bear)
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not save the item when building" do
|
114
|
+
bear = @zoo.exhibits.build( :name => "Bear" )
|
115
|
+
bear.should be_new_record
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should create a new item" do
|
119
|
+
bear = @zoo.exhibits.create( :name => "Bear" )
|
120
|
+
bear.should be_kind_of(Exhibit)
|
121
|
+
@zoo.exhibits.should include(bear)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should save the item when creating" do
|
125
|
+
bear = @zoo.exhibits.create( :name => "Bear" )
|
126
|
+
bear.should_not be_new_record
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should set the association to a saved target when added with <<" do
|
130
|
+
pirahna = Exhibit.new(:name => "Pirahna")
|
131
|
+
pirahna.zoo_id.should be_nil
|
132
|
+
|
133
|
+
@zoo.exhibits << pirahna
|
134
|
+
pirahna.zoo.should == @zoo
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should set the association to a non-saved target when added with <<" do
|
138
|
+
zoo = Zoo.new(:name => "My Zoo")
|
139
|
+
kangaroo = Exhibit.new(:name => "Kangaroo")
|
140
|
+
zoo.exhibits << kangaroo
|
141
|
+
kangaroo.zoo.should == zoo
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should set the id of the exhibit when the associated zoo is saved" do
|
145
|
+
snake = Exhibit.new(:name => "Snake")
|
146
|
+
@zoo.exhibits << snake
|
147
|
+
@zoo.save
|
148
|
+
@zoo.id.should == snake.zoo_id
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should update the foreign_key of already saved exhibits with a new zoo on zoo creation" do
|
152
|
+
zoo = Zoo.new(:name => "My Zoo")
|
153
|
+
snake = Exhibit.create(:name => "Snake")
|
154
|
+
tiger = Exhibit.create(:name => "Tiger")
|
155
|
+
zoo.exhibits << snake << tiger
|
156
|
+
zoo.save
|
157
|
+
snake.zoo_id.should == zoo.key
|
158
|
+
tiger.zoo_id.should == zoo.key
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should set the id of an already saved exibit if it's added to a different zoo" do
|
162
|
+
beaver = Exhibit.new(:name => "Beaver")
|
163
|
+
beaver.save
|
164
|
+
beaver.should_not be_a_new_record
|
165
|
+
@zoo.exhibits << beaver
|
166
|
+
@zoo.save
|
167
|
+
beaver.zoo.should == @zoo
|
168
|
+
beaver.zoo_id.should == @zoo.id
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should set the size of the assocation" do
|
172
|
+
@zoo.exhibits << Exhibit.new(:name => "anonymous")
|
173
|
+
@zoo.exhibits.size.should == 1
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should give the association when an inspect is done on it" do
|
177
|
+
whale = Exhibit.new(:name => "Whale")
|
178
|
+
@zoo.exhibits << whale
|
179
|
+
@zoo.exhibits.should_not == "nil"
|
180
|
+
@zoo.exhibits.inspect.should_not be_nil
|
181
|
+
end
|
182
|
+
|
183
|
+
it "should generate the SQL for a join statement" do
|
184
|
+
fruit_association = database(:mock).schema[Animal].associations.find { |a| a.name == :favourite_fruit }
|
185
|
+
|
186
|
+
fruit_association.to_sql.should == <<-EOS.compress_lines
|
187
|
+
JOIN `fruit` ON `fruit`.`devourer_id` = `animals`.`id`
|
188
|
+
EOS
|
189
|
+
end
|
190
|
+
|
191
|
+
it "is assigned a devourer_id" do
|
192
|
+
bob = Animal.new(:name => 'bob')
|
193
|
+
fruit = Fruit.first
|
194
|
+
bob.favourite_fruit = fruit
|
195
|
+
|
196
|
+
bob.save
|
197
|
+
|
198
|
+
bob.reload!
|
199
|
+
fruit.devourer_id.should eql(bob.id)
|
200
|
+
bob.favourite_fruit.should == fruit
|
201
|
+
|
202
|
+
fruit.reload!
|
203
|
+
fruit.devourer_of_souls.should == bob
|
204
|
+
end
|
205
|
+
|
206
|
+
it "Should handle setting complementary associations" do
|
207
|
+
# pending "http://wm.lighthouseapp.com/projects/4819/tickets/84-belongs_to-associations-not-working-for-me"
|
208
|
+
u1 = User.create(:name => "u1", :email => "test@email.com")
|
209
|
+
u1.comments.should be_empty
|
210
|
+
|
211
|
+
c1 = Comment.create(:comment => "c", :author => u1)
|
212
|
+
|
213
|
+
u1.comments.should_not be_empty
|
214
|
+
u1.comments.should include(c1)
|
215
|
+
|
216
|
+
u1.reload!
|
217
|
+
u1.comments.should_not be_empty
|
218
|
+
u1.comments.should include(c1)
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should allow updates to associations using association_keys=" do
|
222
|
+
# pending "http://wm.lighthouseapp.com/projects/4819-datamapper/tickets/109-associations-should-support-association_keys-methods"
|
223
|
+
database(:default) do
|
224
|
+
london = Zoo.create(:name => "London")
|
225
|
+
dunes = Exhibit.create(:name => "Dunes")
|
226
|
+
|
227
|
+
london.exhibits.should be_empty
|
228
|
+
london.send(:exhibits_keys=, dunes.key)
|
229
|
+
london.save!.should be_true
|
230
|
+
|
231
|
+
london.should have(1).exhibits
|
232
|
+
london.exhibits.should include(dunes)
|
233
|
+
|
234
|
+
london.reload!
|
235
|
+
london.should have(1).exhibits
|
236
|
+
|
237
|
+
london.destroy!
|
238
|
+
dunes.destroy!
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should correctly handle dependent associations (:destroy)" do
|
243
|
+
class Fence
|
244
|
+
has_many :chains, :dependent => :destroy
|
245
|
+
end
|
246
|
+
#Chain.should_receive(:destroy!).and_return(true)
|
247
|
+
|
248
|
+
fence = Fence.create(:name => "Great Wall of China")
|
249
|
+
fence.chains << Chain.create(:name => "1")
|
250
|
+
fence.chains << Chain.create(:name => "2")
|
251
|
+
fence.chains << Chain.create(:name => "3")
|
252
|
+
fence.save
|
253
|
+
chain = Chain.create(:name => "4")
|
254
|
+
fence = Fence[fence.key]
|
255
|
+
|
256
|
+
fence.destroy!
|
257
|
+
Chain.first(:name => "1").should be_nil
|
258
|
+
Chain.first(:name => "2").should be_nil
|
259
|
+
Chain.first(:name => "3").should be_nil
|
260
|
+
Chain.first(:name => "4").should_not be_nil
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should correctly handle dependent associations (:delete)" do
|
264
|
+
class Fence
|
265
|
+
has_many :chains, :dependent => :delete
|
266
|
+
end
|
267
|
+
|
268
|
+
fence = Fence.create(:name => "Great Wall of China")
|
269
|
+
fence.chains << Chain.create(:name => "1")
|
270
|
+
fence.chains << Chain.create(:name => "2")
|
271
|
+
fence.chains << Chain.create(:name => "3")
|
272
|
+
fence.save
|
273
|
+
chain = Chain.create(:name => "4")
|
274
|
+
fence = Fence[fence.key]
|
275
|
+
|
276
|
+
fence.destroy!
|
277
|
+
Chain.first(:name => "1").should be_nil
|
278
|
+
Chain.first(:name => "2").should be_nil
|
279
|
+
Chain.first(:name => "3").should be_nil
|
280
|
+
Chain.first(:name => "4").should_not be_nil
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should correctly handle dependent associations (:protect)" do
|
284
|
+
class Fence
|
285
|
+
has_many :chains, :dependent => :protect
|
286
|
+
end
|
287
|
+
|
288
|
+
fence = Fence.create(:name => "Great Wall of China")
|
289
|
+
fence.chains << Chain.create(:name => "1")
|
290
|
+
fence.chains << Chain.create(:name => "2")
|
291
|
+
fence.chains << Chain.create(:name => "3")
|
292
|
+
fence.save
|
293
|
+
chain = Chain.create(:name => "4")
|
294
|
+
fence = Fence[fence.key]
|
295
|
+
|
296
|
+
lambda { fence.destroy! }.should raise_error(DataMapper::AssociationProtectedError)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should throw AssociationProtectedError even when @items have not been loaded yet (:protect)" do
|
300
|
+
class Fence
|
301
|
+
has_many :chains, :dependent => :protect
|
302
|
+
end
|
303
|
+
|
304
|
+
fence = Fence.create(:name => "Great Wall of China")
|
305
|
+
fence.chains << Chain.create(:name => "1")
|
306
|
+
fence.chains << Chain.create(:name => "2")
|
307
|
+
fence.chains << Chain.create(:name => "3")
|
308
|
+
fence.save
|
309
|
+
chain = Chain.create(:name => "4")
|
310
|
+
fence = Fence[fence.key]
|
311
|
+
|
312
|
+
lambda { fence.destroy! }.should raise_error(DataMapper::AssociationProtectedError)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "should correctly handle dependent associations (:nullify)" do
|
316
|
+
class Fence
|
317
|
+
has_many :chains, :dependent => :nullify
|
318
|
+
end
|
319
|
+
|
320
|
+
fence = Fence.create(:name => "Great Wall of China")
|
321
|
+
fence.chains << Chain.create(:name => "1")
|
322
|
+
fence.chains << Chain.create(:name => "2")
|
323
|
+
fence.chains << Chain.create(:name => "3")
|
324
|
+
fence.save
|
325
|
+
chain = Chain.create(:name => "4")
|
326
|
+
fence = Fence[fence.key]
|
327
|
+
|
328
|
+
fence.destroy!
|
329
|
+
Chain.first(:name => "1").should_not be_nil
|
330
|
+
Chain.first(:name => "1").fence_id.should be_nil
|
331
|
+
Chain.first(:name => "2").should_not be_nil
|
332
|
+
Chain.first(:name => "2").fence_id.should be_nil
|
333
|
+
Chain.first(:name => "3").should_not be_nil
|
334
|
+
Chain.first(:name => "3").fence_id.should be_nil
|
335
|
+
end
|
336
|
+
|
337
|
+
end
|
data/spec/attributes_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
|
-
describe DataMapper::
|
3
|
+
describe "DataMapper::Attributes" do
|
4
4
|
|
5
5
|
it 'should allow mass-assignment of attributes' do
|
6
6
|
zoo = Zoo.new(:name => 'MassAssignment', :notes => 'This is a test.')
|
@@ -27,4 +27,26 @@ describe DataMapper::Persistence do
|
|
27
27
|
zoo.name.should eql("Cheyenne Mountain")
|
28
28
|
end
|
29
29
|
|
30
|
+
it "should provide an ATTRIBUTES constant" do
|
31
|
+
Tomato::ATTRIBUTES.should == Set.new([:id, :name, :bruised])
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should get attributes declared in ATTRIBUTES constant" do
|
35
|
+
Tomato.new.attributes.should == { :id => nil, :name => 'Ugly', :bruised => true }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should get proper values for mass-created attributes with array" do
|
39
|
+
person = Person.new(:name => 'Steve Jobs', :occupation => 'Apple CEO')
|
40
|
+
|
41
|
+
person.name.should eql('Steve Jobs')
|
42
|
+
person.occupation.should eql('Apple CEO')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should get proper values for mass-created attributes without array" do
|
46
|
+
job = Job.new(:name => 'Banker')
|
47
|
+
job.save! and job.reload
|
48
|
+
|
49
|
+
job.hours.should eql(0)
|
50
|
+
job.days.should eql(0)
|
51
|
+
end
|
30
52
|
end
|
@@ -1,44 +1,101 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/spec_helper"
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
3
|
+
describe DataMapper::AutoMigrations do
|
4
|
+
before(:all) do
|
5
|
+
DataMapper::Persistence.drop_all_tables!
|
6
|
+
DataMapper::Persistence.subclasses.clear
|
6
7
|
end
|
7
|
-
end
|
8
8
|
|
9
|
-
|
9
|
+
# before(:each) do
|
10
|
+
# DataMapper::Persistence.drop_all_tables!
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# after(:all) do
|
14
|
+
# DataMapper::Persistence.drop_all_tables!
|
15
|
+
# DataMapper::Persistence.auto_migrate!
|
16
|
+
# end
|
17
|
+
|
18
|
+
# describe DataMapper::Base do
|
19
|
+
# it "should auto migrate all" do
|
20
|
+
# DataMapper::Base.auto_migrate!
|
21
|
+
#
|
22
|
+
# database.adapter.schema.database_tables.size.should == Dir[File.dirname(__FILE__) + '/fixtures/*'].size
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# describe "when migrating a descendant" do
|
26
|
+
# before do
|
27
|
+
# class Descendant < DataMapper::Base
|
28
|
+
# property :one, :string
|
29
|
+
# property :two, :string
|
30
|
+
# property :three, :string
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# it "should work" do
|
35
|
+
# Descendant.auto_migrate!
|
36
|
+
#
|
37
|
+
# database.table_exists?(Descendant).should be_true
|
38
|
+
# database.column_exists_for_table?(Descendant, :one).should be_true
|
39
|
+
# database.column_exists_for_table?(Descendant, :two).should be_true
|
40
|
+
# database.column_exists_for_table?(Descendant, :three).should be_true
|
41
|
+
# database.adapter.schema.database_tables.size.should == 1
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# after do
|
45
|
+
# database.schema[Descendant].drop!
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
|
10
50
|
it "should find all new models" do
|
11
|
-
database.schema[Zoo].drop!
|
12
51
|
Zoo.auto_migrate!
|
52
|
+
|
13
53
|
database.table_exists?(Zoo).should be_true
|
14
54
|
database.column_exists_for_table?(Zoo, :id).should be_true
|
15
55
|
database.column_exists_for_table?(Zoo, :name).should be_true
|
16
56
|
database.column_exists_for_table?(Zoo, :notes).should be_true
|
17
57
|
database.column_exists_for_table?(Zoo, :updated_at).should be_true
|
58
|
+
database.adapter.schema.database_tables.size.should == 1
|
18
59
|
end
|
19
60
|
|
20
61
|
it "should find all changed models"
|
21
62
|
it "should find all unmapped tables"
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
63
|
+
|
64
|
+
describe Zoo, "with auto-migrations" do
|
65
|
+
it "should allow auto migration" do
|
66
|
+
Zoo.should respond_to("auto_migrate!")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "when migrating a new model" do
|
71
|
+
it "should allow creation of new tables for new models"
|
72
|
+
it "should allow renaming of unmapped tables for new models"
|
73
|
+
it "should create columns for the model's properties"
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "when migrating a changed model" do
|
77
|
+
it "should find all new properties"
|
78
|
+
it "should allow creation of new columns for new properties"
|
79
|
+
it "should allow an unmapped column to be renamed for a new property"
|
80
|
+
it "should find all unmapped columns"
|
81
|
+
it "should allow removal of any or all unmapped columns"
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "when migrating an unmapped table" do
|
85
|
+
it "should allow the table to be dropped"
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "after migrating" do
|
89
|
+
it "should store migration decisions to allow the migration to be replicated"
|
90
|
+
end
|
91
|
+
|
92
|
+
after(:all) do
|
93
|
+
DataMapper::Persistence.subclasses.clear
|
94
|
+
DataMapper::Persistence.subclasses.concat INITIAL_CLASSES
|
95
|
+
|
96
|
+
# Use DataMapper::Base to boost spec coverage since it delegates to Persistence anyways.
|
97
|
+
DataMapper::Base.auto_migrate!
|
98
|
+
|
99
|
+
load_database
|
100
|
+
end
|
101
|
+
end
|