motion_model 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f8aff0f64a66b3acc96dc5b3bc3539cb9ce7414
4
- data.tar.gz: 8297cac822d64df7c823e6aeab801c54657c217c
3
+ metadata.gz: 892db8d37703846647efbe466622223f16e4457a
4
+ data.tar.gz: 4e6afc9963ed9d066f0260e94f68f2955bada371
5
5
  SHA512:
6
- metadata.gz: b01dc4562a81064f0ade25f402f3bc50c84d9cb91a9132b3497ea844ee2e6f29c141259888f495794ddf11e8bc6694dc30f456607455b7a60c2c19b25822dc48
7
- data.tar.gz: dfee05ac135e297256a9476c9f7b83c6e0bfd0ccc2646a4557338a7c1f882898100c17f4653cba221880d4d7c9d3d445c15f0308ffd8474096d634476f536432
6
+ metadata.gz: 2c3e7b74836767c12d63e75db5b5880005b04a9f87d9ccc0c23edfcc895ebd1f093823a608d0500297899af8a55683a3c63aeb1c807f69449972dbc11398dd3e
7
+ data.tar.gz: 67dd32daed7a6c8bbe9b53950d435bea746668f17494f279283ba42c5c30b59a4911167ae7be3cb4edce64c714d38ee0f6a0d03c9388f4f33a31809836908d72
@@ -3,6 +3,7 @@ GEM
3
3
  specs:
4
4
  bubble-wrap (1.4.0)
5
5
  motion-stump (0.3.0)
6
+ rake (10.4.2)
6
7
 
7
8
  PLATFORMS
8
9
  ruby
@@ -10,3 +11,4 @@ PLATFORMS
10
11
  DEPENDENCIES
11
12
  bubble-wrap
12
13
  motion-stump (~> 0.2)
14
+ rake
@@ -70,6 +70,11 @@ module MotionModel
70
70
  bulk_update do
71
71
  NSKeyedUnarchiver.unarchiveObjectWithData(data)
72
72
  end
73
+
74
+ # ensure _next_id is in sync with deserialized model
75
+ max_id = self.all.map { |o| o.id }.max
76
+ increment_next_id(max_id) unless max_id.nil? || _next_id > max_id
77
+
73
78
  return self
74
79
  end
75
80
  else
@@ -370,3 +370,13 @@ class Module
370
370
  const.split(/::/).inject(base) { |mod, name| mod.const_get(name) }
371
371
  end
372
372
  end
373
+
374
+ class Object
375
+ def try(*a, &b)
376
+ if a.empty? && block_given?
377
+ yield self
378
+ else
379
+ public_send(*a, &b) if respond_to?(a.first)
380
+ end
381
+ end
382
+ end
@@ -4,5 +4,5 @@
4
4
  # or forward port their code to take advantage
5
5
  # of adapters.
6
6
  module MotionModel
7
- VERSION = "0.6.1"
7
+ VERSION = "0.6.2"
8
8
  end
Binary file
@@ -255,4 +255,33 @@ describe "serialization of relations" do
255
255
  Parent.first.children.first.name.should == 'Fergie'
256
256
  Parent.first.dog.first.name.should == 'Fluffy'
257
257
  end
258
+
259
+ class StoredTask
260
+ include MotionModel::Model
261
+ include MotionModel::ArrayModelAdapter
262
+ columns :name
263
+ end
264
+
265
+ describe "reloading correct ids" do
266
+ before do
267
+ # # StoredTasks.dat was built with the following
268
+ # t1 = StoredTask.create(name: "One") # id: 1
269
+ # t2 = StoredTask.create(name: "Two") # id: 2
270
+ # t3 = StoredTask.create(name: "Three") # id: 3
271
+ # t2.destroy
272
+
273
+ # # StoredTasks.all => [id: 1, id:3]
274
+ # StoredTask.serialize_to_file('StoredTasks.dat')
275
+ StoredTask.deserialize_from_file('StoredTasks.dat', NSBundle.mainBundle.resourcePath)
276
+ end
277
+
278
+ it "creates a new task with the correct id after deserialization" do
279
+ StoredTask.count.should == 2
280
+ StoredTask.first.id.should == 1
281
+ StoredTask.last.id.should == 3
282
+
283
+ t4 = StoredTask.create(name: "Four")
284
+ t4.id.should == 4
285
+ end
286
+ end
258
287
  end
@@ -195,6 +195,25 @@ describe 'related objects' do
195
195
  @t1.assignees.count.should == 1
196
196
  @t1.assignees.first.assignee_name.should == @a1.assignee_name
197
197
  end
198
+
199
+ it "directly assigning the assignee a nil task twice doesn't change anything" do
200
+ @a1.task.should == nil
201
+ @a1.task = nil
202
+ @a1.dirty?.should == false
203
+ end
204
+
205
+ it "directly assigning the existing task to an assignee doesn't change anything" do
206
+ @a1.task = @t1
207
+ @a1.save
208
+ @a1.task = @t1
209
+ @a1.dirty?.should == false
210
+ end
211
+
212
+ it "directly assigning the assignee a nil task twice doesn't change anything" do
213
+ @a1.task.should == nil
214
+ @a1.task = nil
215
+ @a1.dirty?.should == false
216
+ end
198
217
  end
199
218
  end
200
219
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Ross
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-31 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bubble-wrap
@@ -69,6 +69,7 @@ files:
69
69
  - motion/validatable.rb
70
70
  - motion/version.rb
71
71
  - motion_model.gemspec
72
+ - resources/StoredTasks.dat
72
73
  - spec/adapter_spec.rb
73
74
  - spec/array_model_persistence_spec.rb
74
75
  - spec/cascading_delete_spec.rb
@@ -127,4 +128,3 @@ test_files:
127
128
  - spec/relation_spec.rb
128
129
  - spec/transaction_spec.rb
129
130
  - spec/validation_spec.rb
130
- has_rdoc: