motion-prime 0.8.6 → 0.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +5 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +21 -20
- data/ROADMAP.md +2 -2
- data/files/Gemfile +1 -3
- data/files/app/config/base.rb +15 -1
- data/motion-prime.gemspec +3 -3
- data/motion-prime/config/base.rb +1 -0
- data/motion-prime/models/_base_mixin.rb +51 -45
- data/motion-prime/models/_dirty_mixin.rb +31 -3
- data/motion-prime/version.rb +1 -1
- data/spec/helpers/models.rb +7 -13
- data/spec/models/dirty_spec.rb +34 -0
- data/spec/models/model_spec.rb +26 -2
- data/spec/models/store_extension_spec.rb +26 -26
- data/spec/models/store_spec.rb +5 -5
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDNjNmUxZTA5MDQxMjZlMWZlYzU5YTQ5NDExZmU2NzRlNjA2ZGQ1Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDY0MzhiNjc1MzU0YWExMTA1ZDdkOGM0MjYzOWM2Yzk0NGZkN2Q3OA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzVhOTRjNjA3NDI1ODNlMzNkZWQ0NzlkYTU2ZmRkMzA5ZjljMGUwYTk5Zjlm
|
10
|
+
MzIxMmIwZjA0MDkyMjg0MDk3YzdlNDZiZmEzNDM1NTE5YjMwNTJkYmJkZDBh
|
11
|
+
OGIxYmE0ZWZjZmU1MmNmZWNiY2Q5MzAyYWVjODViZGIzNWQyMTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzBlZjk3NmRjM2I3NzA0NjU5ZTllMmEzNjYwY2VmNDhjMzY1YWYyMjc5OTA2
|
14
|
+
ZGVkZGUxMDVlNzFlNDA3NGVjMGVjZmY1NjgyOTI2N2Y4MGI0MTJjOTRiNGJm
|
15
|
+
Y2MxODBlMWUyOWZiZmVkZTU4NTFhOWYyZTBlM2E4MDljODZhMDc=
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== 0.8.7
|
2
|
+
* Refactored and improved model attributes convertion.
|
3
|
+
* Refactored and improved model#dirty.
|
4
|
+
* Added auto-generating model id by default.
|
5
|
+
|
1
6
|
=== 0.8.6
|
2
7
|
* Ability to pass :after_render to form field.
|
3
8
|
* Ability to append data to collection on sync.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,49 +1,51 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
motion-prime (0.8.
|
4
|
+
motion-prime (0.8.7)
|
5
5
|
afmotion (~> 2.0.0)
|
6
|
-
bubble-wrap (~> 1.
|
6
|
+
bubble-wrap (~> 1.5.0)
|
7
7
|
cocoapods
|
8
8
|
methadone
|
9
9
|
motion-cocoapods
|
10
10
|
motion-require
|
11
|
-
motion-support
|
11
|
+
motion-support (~> 0.2.6)
|
12
12
|
rm-digest
|
13
|
-
sugarcube (~> 1.
|
13
|
+
sugarcube (~> 1.5.2)
|
14
14
|
|
15
15
|
GEM
|
16
16
|
remote: http://rubygems.org/
|
17
17
|
specs:
|
18
|
-
activesupport (3.2.
|
18
|
+
activesupport (3.2.17)
|
19
19
|
i18n (~> 0.6, >= 0.6.4)
|
20
20
|
multi_json (~> 1.0)
|
21
21
|
afmotion (2.0.0)
|
22
22
|
motion-cocoapods (~> 1.4.0)
|
23
23
|
motion-require (~> 0.0.7)
|
24
|
-
bubble-wrap (1.
|
24
|
+
bubble-wrap (1.5.0)
|
25
25
|
claide (0.4.0)
|
26
|
-
cocoapods (0.
|
26
|
+
cocoapods (0.29.0)
|
27
27
|
activesupport (>= 3.2.15, < 4)
|
28
28
|
claide (~> 0.4.0)
|
29
|
-
cocoapods-core (= 0.
|
30
|
-
cocoapods-downloader (~> 0.
|
29
|
+
cocoapods-core (= 0.29.0)
|
30
|
+
cocoapods-downloader (~> 0.3.0)
|
31
|
+
cocoapods-try-release-fix (~> 0.1.1)
|
31
32
|
colored (~> 1.2)
|
32
33
|
escape (~> 0.0.4)
|
33
34
|
json_pure (~> 1.8)
|
35
|
+
nap (~> 0.5)
|
34
36
|
open4 (~> 1.3)
|
35
37
|
xcodeproj (~> 0.14.1)
|
36
|
-
cocoapods-core (0.
|
38
|
+
cocoapods-core (0.29.0)
|
37
39
|
activesupport (>= 3.2.15, < 4)
|
38
40
|
fuzzy_match (~> 2.0.4)
|
39
|
-
|
41
|
+
json_pure (~> 1.8)
|
40
42
|
nap (~> 0.5)
|
41
|
-
cocoapods-downloader (0.
|
43
|
+
cocoapods-downloader (0.3.0)
|
44
|
+
cocoapods-try-release-fix (0.1.2)
|
42
45
|
colored (1.2)
|
43
46
|
escape (0.0.4)
|
44
47
|
fuzzy_match (2.0.4)
|
45
48
|
i18n (0.6.9)
|
46
|
-
json (1.8.1)
|
47
49
|
json_pure (1.8.1)
|
48
50
|
methadone (1.3.2)
|
49
51
|
bundler
|
@@ -51,15 +53,15 @@ GEM
|
|
51
53
|
cocoapods (>= 0.26.2)
|
52
54
|
motion-redgreen (0.1.0)
|
53
55
|
motion-require (0.0.7)
|
54
|
-
motion-stump (0.3.
|
55
|
-
motion-support (0.2.
|
56
|
+
motion-stump (0.3.1)
|
57
|
+
motion-support (0.2.6)
|
56
58
|
motion-require (>= 0.0.6)
|
57
|
-
multi_json (1.
|
59
|
+
multi_json (1.9.0)
|
58
60
|
nap (0.6.0)
|
59
|
-
open4 (1.3.
|
60
|
-
rake (10.1.
|
61
|
+
open4 (1.3.3)
|
62
|
+
rake (10.1.1)
|
61
63
|
rm-digest (0.0.2)
|
62
|
-
sugarcube (1.
|
64
|
+
sugarcube (1.5.2)
|
63
65
|
xcodeproj (0.14.1)
|
64
66
|
activesupport (~> 3.0)
|
65
67
|
colored (~> 1.2)
|
@@ -73,5 +75,4 @@ DEPENDENCIES
|
|
73
75
|
motion-prime!
|
74
76
|
motion-redgreen
|
75
77
|
motion-stump
|
76
|
-
motion-support (~> 0.2.4)
|
77
78
|
rake
|
data/ROADMAP.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* Move api_client and model sync mixin to prime_api gem.
|
3
3
|
* Move bind keyboard events to forms.
|
4
4
|
|
5
|
-
===
|
5
|
+
=== 1.0.0
|
6
6
|
* bug: if mp label do not have text and was set as hidden, it should unhide after setting text
|
7
7
|
* bug: size_to_fit works incorrect with relative width.
|
8
8
|
* bug: bind_keyboard_close breaks bind_guesture
|
@@ -23,4 +23,4 @@
|
|
23
23
|
* add computed_options.get(), this will allow to make sure that options is computed.
|
24
24
|
* add testing framework
|
25
25
|
* add DSL for ViewStyles#setValue conditions
|
26
|
-
* add embed/regular has many types. embedded by default.
|
26
|
+
* add embed/regular has many types. embedded by default.
|
data/files/Gemfile
CHANGED
data/files/app/config/base.rb
CHANGED
@@ -1,3 +1,17 @@
|
|
1
1
|
Prime::Config.configure do |config|
|
2
|
-
|
2
|
+
# Uncomments following if you don't want auto generating id for model on save
|
3
|
+
#
|
4
|
+
# config.model.auto_generate_id = false
|
5
|
+
|
6
|
+
# After defining colors you will be able to use it via <uilabel>.text_color = :app_base.uicolor
|
7
|
+
# config.colors do |colors|
|
8
|
+
# colors.base = 0x1b75bc
|
9
|
+
# colors.dark = 0x333333
|
10
|
+
# colors.error = 0xef471f
|
11
|
+
# end
|
12
|
+
|
13
|
+
# After defining fonts you will be able to use it via <uilabel>.font = :app_base.uifont
|
14
|
+
# config.fonts do |fonts|
|
15
|
+
# fonts.base = "Ubuntu"
|
16
|
+
# end
|
3
17
|
end
|
data/motion-prime.gemspec
CHANGED
@@ -23,9 +23,9 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency "cocoapods"
|
24
24
|
spec.add_dependency "motion-cocoapods"
|
25
25
|
spec.add_dependency "motion-require"
|
26
|
-
spec.add_dependency "motion-support"
|
27
|
-
spec.add_dependency 'bubble-wrap', '~> 1.
|
28
|
-
spec.add_dependency 'sugarcube', '~> 1.
|
26
|
+
spec.add_dependency "motion-support", '~> 0.2.6'
|
27
|
+
spec.add_dependency 'bubble-wrap', '~> 1.5.0'
|
28
|
+
spec.add_dependency 'sugarcube', '~> 1.5.2'
|
29
29
|
spec.add_dependency 'afmotion', '~> 2.0.0'
|
30
30
|
spec.add_dependency "methadone"
|
31
31
|
spec.add_dependency "rm-digest"
|
data/motion-prime/config/base.rb
CHANGED
@@ -10,6 +10,7 @@ module MotionPrime
|
|
10
10
|
#
|
11
11
|
# @return [Prime::Model] model
|
12
12
|
def save
|
13
|
+
set_default_id_if_needed
|
13
14
|
raise StoreError, 'No store provided' unless self.store
|
14
15
|
error_ptr = Pointer.new(:id)
|
15
16
|
self.store.addObject(self, error: error_ptr)
|
@@ -112,6 +113,41 @@ module MotionPrime
|
|
112
113
|
self.class.new(self.info.select { |key, value| !key.to_s.ends_with?('_bag') })
|
113
114
|
end
|
114
115
|
|
116
|
+
protected
|
117
|
+
def set_default_id_if_needed
|
118
|
+
if !self.id && MotionPrime::Config.model.auto_generate_id
|
119
|
+
self.id = RmDigest::MD5.hexdigest(Time.now.to_s + self.object_id.to_s)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def attribute_convert_out(value, type)
|
124
|
+
return value if value.nil? || type.blank?
|
125
|
+
case type.to_s
|
126
|
+
when 'integer'
|
127
|
+
value.to_i
|
128
|
+
when 'float'
|
129
|
+
value.to_f
|
130
|
+
when 'time'
|
131
|
+
Time.short_iso8601(value)
|
132
|
+
else
|
133
|
+
value
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def attribute_convert_in(value, type)
|
138
|
+
return value if value.nil? || type.blank?
|
139
|
+
case type.to_s
|
140
|
+
when 'integer'
|
141
|
+
value.to_i
|
142
|
+
when 'float'
|
143
|
+
value.to_f
|
144
|
+
when 'time'
|
145
|
+
value.to_short_iso8601 unless value.is_a?(String)
|
146
|
+
else
|
147
|
+
value
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
115
151
|
module ClassMethods
|
116
152
|
# Initialize a new object
|
117
153
|
#
|
@@ -123,17 +159,8 @@ module MotionPrime
|
|
123
159
|
# @option options [Boolean] :validate_attribute_presence Raise error if model do not have attribute
|
124
160
|
# @return MotionPrime::Model unsaved model
|
125
161
|
def new(data = {}, options = {})
|
126
|
-
|
127
|
-
|
128
|
-
if options[:validate_attribute_presence]
|
129
|
-
raise StoreError, "unknown attribute: '#{key}'"
|
130
|
-
else
|
131
|
-
data.delete(key)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
object = self.nanoObjectWithDictionary(data)
|
162
|
+
object = self.nanoObjectWithDictionary({})
|
163
|
+
object.assign_attributes(data, options)
|
137
164
|
object
|
138
165
|
end
|
139
166
|
|
@@ -162,47 +189,26 @@ module MotionPrime
|
|
162
189
|
def attribute(name, options = {})
|
163
190
|
attributes << name
|
164
191
|
|
165
|
-
define_method(name) do
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
192
|
+
define_method(:"#{name}=") do |value, &block|
|
193
|
+
track_changed_attributes do
|
194
|
+
if options[:convert] || !options.has_key?(:convert)
|
195
|
+
self.info[name] = attribute_convert_in(value, options[:type])
|
196
|
+
else
|
197
|
+
self.info[name] = value
|
198
|
+
end
|
170
199
|
end
|
171
|
-
value
|
172
|
-
end
|
173
|
-
|
174
|
-
define_method((name + "=").to_sym) do |*args, &block|
|
175
|
-
value = args[0]
|
176
|
-
case options[:type].to_s
|
177
|
-
when 'integer'
|
178
|
-
value = value.to_i
|
179
|
-
when 'float'
|
180
|
-
value = value.to_f
|
181
|
-
when 'time'
|
182
|
-
value = value.to_short_iso8601 unless value.is_a?(String)
|
183
|
-
end unless value.nil?
|
184
|
-
|
185
|
-
self.info[name] = value
|
186
200
|
end
|
187
201
|
|
188
202
|
define_method(name.to_sym) do
|
189
|
-
|
190
|
-
|
191
|
-
when 'integer'
|
192
|
-
value.to_i
|
193
|
-
when 'float'
|
194
|
-
value.to_f
|
195
|
-
when 'time' && !value.is_a?(String)
|
196
|
-
value.to_short_iso8601
|
203
|
+
if options[:convert] || !options.has_key?(:convert)
|
204
|
+
attribute_convert_out(self.info[name], options[:type])
|
197
205
|
else
|
198
|
-
|
206
|
+
self.info[name]
|
199
207
|
end
|
200
|
-
end
|
208
|
+
end
|
201
209
|
|
202
|
-
|
203
|
-
|
204
|
-
!!self.info[name]
|
205
|
-
end
|
210
|
+
define_method("#{name}?") do
|
211
|
+
self.info[name].present?
|
206
212
|
end
|
207
213
|
end
|
208
214
|
|
@@ -25,13 +25,41 @@ module MotionPrime
|
|
25
25
|
result
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def changed_attributes
|
29
29
|
@_changed_attributes ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset_changed_attributes
|
33
|
+
@_changed_attributes = {}
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return true if model was changed
|
37
|
+
#
|
38
|
+
# @param key [Symbol,String] (not required) will return result only for that attribute if specified
|
39
|
+
# @return result [Boolean] result
|
40
|
+
def has_changed?(key = nil)
|
30
41
|
if key
|
31
|
-
|
42
|
+
changed_attributes.has_key?(key.to_s)
|
32
43
|
else
|
33
|
-
|
44
|
+
changed_attributes.present?
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def save
|
49
|
+
super
|
50
|
+
reset_changed_attributes
|
51
|
+
self
|
52
|
+
end
|
53
|
+
|
54
|
+
# Reverts model changes and returns saved version
|
55
|
+
#
|
56
|
+
# @return model [MotionPrime::Model] reloaded model
|
57
|
+
def reload
|
58
|
+
changed_attributes.each do |key, value|
|
59
|
+
self.info[key] = value
|
34
60
|
end
|
61
|
+
reset_changed_attributes
|
62
|
+
self
|
35
63
|
end
|
36
64
|
end
|
37
65
|
end
|
data/motion-prime/version.rb
CHANGED
data/spec/helpers/models.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
class User < MotionPrime::Model
|
2
2
|
attributes :name, :age, :created_at
|
3
3
|
end
|
4
|
-
|
5
4
|
class Plane < MotionPrime::Model
|
6
5
|
attributes :name, :age
|
7
6
|
end
|
8
7
|
|
9
|
-
class Listing < MotionPrime::Model
|
10
|
-
attribute :name
|
11
|
-
end
|
12
|
-
|
13
8
|
class Todo < MotionPrime::Model
|
14
9
|
attribute :title
|
15
10
|
bag :items
|
@@ -25,14 +20,6 @@ class Page < MotionPrime::Model
|
|
25
20
|
attribute :index
|
26
21
|
end
|
27
22
|
|
28
|
-
class Animal < MotionPrime::Model
|
29
|
-
attribute :name
|
30
|
-
end
|
31
|
-
|
32
|
-
class Autobot < MotionPrime::Model
|
33
|
-
attribute :name
|
34
|
-
end
|
35
|
-
|
36
23
|
class Organization < MotionPrime::Model
|
37
24
|
attribute :name
|
38
25
|
has_many :projects
|
@@ -42,6 +29,13 @@ class Project < MotionPrime::Model
|
|
42
29
|
attribute :title
|
43
30
|
end
|
44
31
|
|
32
|
+
class Autobot < MotionPrime::Model
|
33
|
+
attribute :name
|
34
|
+
attribute :uid, type: :integer
|
35
|
+
attribute :release_at, type: :time
|
36
|
+
attribute :strength, type: :float
|
37
|
+
end
|
38
|
+
|
45
39
|
module CustomModule; end
|
46
40
|
class CustomModule::Car < MotionPrime::Model
|
47
41
|
attribute :name
|
@@ -0,0 +1,34 @@
|
|
1
|
+
describe MotionPrime::Model do
|
2
|
+
before do
|
3
|
+
MotionPrime::Store.connect
|
4
|
+
@store = MotionPrime::Store.shared_store
|
5
|
+
end
|
6
|
+
|
7
|
+
after do
|
8
|
+
@store.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "has_changed?" do
|
12
|
+
before do
|
13
|
+
@user = stub_user("Bob", 10, Time.now)
|
14
|
+
@user.save
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be false after save" do
|
18
|
+
puts @user.changed_attributes
|
19
|
+
@user.has_changed?.should.be.false
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be true after attribute change" do
|
23
|
+
@user.name = "Smith"
|
24
|
+
@user.has_changed?.should.be.true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be false after reload" do
|
28
|
+
@user.name = "Smith"
|
29
|
+
@user.reload
|
30
|
+
@user.has_changed?.should.be.false
|
31
|
+
@user.name.should == "Bob"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/models/model_spec.rb
CHANGED
@@ -73,8 +73,8 @@ describe MotionPrime::Model do
|
|
73
73
|
|
74
74
|
it "create object in their class" do
|
75
75
|
@store.allObjectClasses.should == []
|
76
|
-
|
77
|
-
@store.allObjectClasses.should == ["
|
76
|
+
Organization.create(:name => "Bumblebee")
|
77
|
+
@store.allObjectClasses.should == ["Organization"]
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -85,6 +85,17 @@ describe MotionPrime::Model do
|
|
85
85
|
@store.count(User).should == 1
|
86
86
|
end
|
87
87
|
|
88
|
+
it "should set default id" do
|
89
|
+
user1 = User.new
|
90
|
+
user2 = User.new
|
91
|
+
user1.id = 123
|
92
|
+
user1.save
|
93
|
+
user2.save
|
94
|
+
|
95
|
+
user1.id.should == 123
|
96
|
+
user2.id.present?.should.be.true
|
97
|
+
end
|
98
|
+
|
88
99
|
# per object store since NanoStore 2.5.1
|
89
100
|
it "user per instance store to save" do
|
90
101
|
store1 = MotionPrime::Store.create
|
@@ -207,4 +218,17 @@ describe MotionPrime::Model do
|
|
207
218
|
Plane.count.should == 1
|
208
219
|
end
|
209
220
|
end
|
221
|
+
|
222
|
+
describe "#attribute" do
|
223
|
+
it "should correctly save non-string attributes" do
|
224
|
+
release = Time.now + 1.day.to_i
|
225
|
+
Autobot.create(name: "Optimus Prime", uid: 1, release_at: release, strength: 15.7)
|
226
|
+
autobot = Autobot.find(uid: 1).first
|
227
|
+
autobot.name.is_a?(String).should.be.true
|
228
|
+
autobot.uid.is_a?(Integer).should.be.true
|
229
|
+
autobot.release_at.is_a?(Time).should.be.true
|
230
|
+
autobot.strength.is_a?(Float).should.be.true
|
231
|
+
autobot.release_at.should == release
|
232
|
+
end
|
233
|
+
end
|
210
234
|
end
|
@@ -21,13 +21,13 @@ describe "Prime::Model Store Extension" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should add, delete objects and count them" do
|
24
|
-
obj1 =
|
24
|
+
obj1 = Organization.new
|
25
25
|
obj1.name = "Cat"
|
26
|
-
obj2 =
|
26
|
+
obj2 = Organization.new
|
27
27
|
obj2.name = "Dog"
|
28
|
-
obj3 =
|
28
|
+
obj3 = Organization.new
|
29
29
|
obj3.name = "Cow"
|
30
|
-
obj4 =
|
30
|
+
obj4 = Organization.new
|
31
31
|
obj4.name = "Duck"
|
32
32
|
|
33
33
|
@store << obj1
|
@@ -35,86 +35,86 @@ describe "Prime::Model Store Extension" do
|
|
35
35
|
@store += obj4
|
36
36
|
|
37
37
|
@store.save
|
38
|
-
|
38
|
+
Organization.count.should == 4
|
39
39
|
|
40
40
|
@store.delete(obj1)
|
41
|
-
|
41
|
+
Organization.count.should == 3
|
42
42
|
|
43
43
|
@store.delete_keys([obj2.key])
|
44
|
-
|
44
|
+
Organization.count.should == 2
|
45
45
|
|
46
46
|
@store.clear
|
47
|
-
|
47
|
+
Organization.count.should == 0
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should discard unsave changes" do
|
51
51
|
@store.save_interval = 1000 # must use save_interval= to set auto save interval first
|
52
52
|
@store.engine.synchronousMode = SynchronousModeFull
|
53
53
|
|
54
|
-
|
55
|
-
obj1 =
|
54
|
+
Organization.count.should == 0
|
55
|
+
obj1 = Organization.new
|
56
56
|
obj1.name = "Cat"
|
57
|
-
obj2 =
|
57
|
+
obj2 = Organization.new
|
58
58
|
obj2.name = "Dog"
|
59
59
|
|
60
60
|
@store << [obj1, obj2]
|
61
61
|
@store.changed?.should.be.true
|
62
62
|
@store.discard
|
63
63
|
@store.changed?.should.be.false
|
64
|
-
|
64
|
+
Organization.count.should == 0
|
65
65
|
@store.save_interval = 1
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should create a transaction and commit" do
|
69
69
|
@store.transaction do |the_store|
|
70
|
-
|
71
|
-
obj1 =
|
70
|
+
Organization.count.should == 0
|
71
|
+
obj1 = Organization.new
|
72
72
|
obj1.name = "Cat"
|
73
73
|
obj1.save
|
74
74
|
|
75
|
-
obj2 =
|
75
|
+
obj2 = Organization.new
|
76
76
|
obj2.name = "Dog"
|
77
77
|
obj2.save
|
78
|
-
|
78
|
+
Organization.count.should == 2
|
79
79
|
end
|
80
80
|
@store.save
|
81
|
-
|
81
|
+
Organization.count.should == 2
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should create a transaction and rollback when fail" do
|
85
85
|
begin
|
86
86
|
@store.transaction do |the_store|
|
87
|
-
|
88
|
-
obj1 =
|
87
|
+
Organization.count.should == 0
|
88
|
+
obj1 = Organization.new
|
89
89
|
obj1.name = "Cat"
|
90
90
|
obj1.save
|
91
91
|
|
92
|
-
obj2 =
|
92
|
+
obj2 = Organization.new
|
93
93
|
obj2.name = "Dog"
|
94
94
|
obj2.save
|
95
|
-
|
95
|
+
Organization.count.should == 2
|
96
96
|
raise "error"
|
97
97
|
end
|
98
98
|
rescue
|
99
99
|
end
|
100
100
|
@store.save
|
101
|
-
|
101
|
+
Organization.count.should == 0
|
102
102
|
end
|
103
103
|
|
104
104
|
it "should save in batch" do
|
105
105
|
@store.save_interval = 1000
|
106
106
|
|
107
|
-
|
108
|
-
obj1 =
|
107
|
+
Organization.count.should == 0
|
108
|
+
obj1 = Organization.new
|
109
109
|
obj1.name = "Cat"
|
110
110
|
@store << obj1
|
111
111
|
|
112
|
-
obj2 =
|
112
|
+
obj2 = Organization.new
|
113
113
|
obj2.name = "Dog"
|
114
114
|
@store << obj2
|
115
115
|
@store.save
|
116
116
|
|
117
|
-
|
117
|
+
Organization.count.should == 2
|
118
118
|
end
|
119
119
|
|
120
120
|
end
|
data/spec/models/store_spec.rb
CHANGED
@@ -32,14 +32,14 @@ describe "Prime::Model Store" do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should use shared_store if a model has no store defined" do
|
35
|
-
|
35
|
+
Organization.store = nil
|
36
36
|
MotionPrime::Store.connect
|
37
|
-
|
37
|
+
Organization.store.should.not.be.nil
|
38
38
|
MotionPrime::Store.shared_store.should.not.be.nil
|
39
|
-
|
39
|
+
Organization.store.should == MotionPrime::Store.shared_store
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
Organization.store = MotionPrime::Store.create :temp
|
42
|
+
Organization.store.should.not == MotionPrime::Store.shared_store
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should enable and disable debug mode" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-prime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Haziev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -99,44 +99,44 @@ dependencies:
|
|
99
99
|
name: motion-support
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ~>
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: 0.2.6
|
105
105
|
type: :runtime
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- -
|
109
|
+
- - ~>
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: 0.2.6
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: bubble-wrap
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ~>
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: 1.
|
118
|
+
version: 1.5.0
|
119
119
|
type: :runtime
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: 1.
|
125
|
+
version: 1.5.0
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: sugarcube
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
130
|
- - ~>
|
131
131
|
- !ruby/object:Gem::Version
|
132
|
-
version: 1.
|
132
|
+
version: 1.5.2
|
133
133
|
type: :runtime
|
134
134
|
prerelease: false
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
136
136
|
requirements:
|
137
137
|
- - ~>
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
version: 1.
|
139
|
+
version: 1.5.2
|
140
140
|
- !ruby/object:Gem::Dependency
|
141
141
|
name: afmotion
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -365,6 +365,7 @@ files:
|
|
365
365
|
- spec/models/association_collection_spec.rb
|
366
366
|
- spec/models/associations_spec.rb
|
367
367
|
- spec/models/bag_spec.rb
|
368
|
+
- spec/models/dirty_spec.rb
|
368
369
|
- spec/models/errors_spec.rb
|
369
370
|
- spec/models/finder_spec.rb
|
370
371
|
- spec/models/json.rb
|
@@ -408,6 +409,7 @@ test_files:
|
|
408
409
|
- spec/models/association_collection_spec.rb
|
409
410
|
- spec/models/associations_spec.rb
|
410
411
|
- spec/models/bag_spec.rb
|
412
|
+
- spec/models/dirty_spec.rb
|
411
413
|
- spec/models/errors_spec.rb
|
412
414
|
- spec/models/finder_spec.rb
|
413
415
|
- spec/models/json.rb
|