motion_model 0.6.1 → 0.6.2
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.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -0
- data/motion/adapters/array_model_persistence.rb +5 -0
- data/motion/ext.rb +10 -0
- data/motion/version.rb +1 -1
- data/resources/StoredTasks.dat +0 -0
- data/spec/array_model_persistence_spec.rb +29 -0
- data/spec/relation_spec.rb +19 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 892db8d37703846647efbe466622223f16e4457a
|
4
|
+
data.tar.gz: 4e6afc9963ed9d066f0260e94f68f2955bada371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c3e7b74836767c12d63e75db5b5880005b04a9f87d9ccc0c23edfcc895ebd1f093823a608d0500297899af8a55683a3c63aeb1c807f69449972dbc11398dd3e
|
7
|
+
data.tar.gz: 67dd32daed7a6c8bbe9b53950d435bea746668f17494f279283ba42c5c30b59a4911167ae7be3cb4edce64c714d38ee0f6a0d03c9388f4f33a31809836908d72
|
data/Gemfile.lock
CHANGED
@@ -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
|
data/motion/ext.rb
CHANGED
@@ -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
|
data/motion/version.rb
CHANGED
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
|
data/spec/relation_spec.rb
CHANGED
@@ -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.
|
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-
|
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:
|