mm_partial_update 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -40,8 +40,7 @@ module MmPartialUpdate
|
|
40
40
|
|
41
41
|
def create_or_update_changes(options={})
|
42
42
|
#assert_root_saved
|
43
|
-
|
44
|
-
execute_command(update_command, options)
|
43
|
+
update_comment = execute_command(options)
|
45
44
|
#callbacks and changes_only are not valid
|
46
45
|
# options for regular MongoMapper saves.
|
47
46
|
# clear_changes_to_subtree will pass this options
|
@@ -114,16 +113,19 @@ module MmPartialUpdate
|
|
114
113
|
end
|
115
114
|
end
|
116
115
|
|
117
|
-
def execute_command(
|
116
|
+
def execute_command(options)
|
118
117
|
if options[:callbacks]
|
119
118
|
context = new? ? :create : :update
|
120
119
|
run_callbacks(:save) do
|
121
120
|
run_callbacks(context) do
|
122
|
-
|
121
|
+
# the update command cannot be prepared before callbacks are run
|
122
|
+
# if they are to be run because they may change the state of the
|
123
|
+
# entity, and those changes need to be persisted
|
124
|
+
prepare_update_command.tap{ |c|c.execute() }
|
123
125
|
end
|
124
126
|
end
|
125
127
|
else
|
126
|
-
|
128
|
+
prepare_update_command.tap{ |c|c.execute() }
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
@@ -21,6 +21,14 @@ class TestPartialUpdate < Test::Unit::TestCase
|
|
21
21
|
person.name.should == "Esteban"
|
22
22
|
end
|
23
23
|
|
24
|
+
should "persist changes made during before_save" do
|
25
|
+
person = Person.create! :name=>"Willard!"
|
26
|
+
person.ensure_me = nil
|
27
|
+
person.save_changes
|
28
|
+
person.reload
|
29
|
+
person.ensure_me.should == "here i am!"
|
30
|
+
end
|
31
|
+
|
24
32
|
should "update changes to a saved entity, preserving unchanged values" do
|
25
33
|
person = Person.new :name=>"Willard"
|
26
34
|
person.pets.build :name=>"Magma", :age=>2
|
data/test/models.rb
CHANGED
@@ -4,11 +4,17 @@ class Person
|
|
4
4
|
include MongoMapper::Document
|
5
5
|
include CallbacksSupport
|
6
6
|
key :name, String
|
7
|
+
key :ensure_me, String
|
7
8
|
many :pets
|
8
9
|
one :happy_place
|
9
10
|
one :favorite_pet, :class_name=>'Pet'
|
10
11
|
|
11
12
|
timestamps!
|
13
|
+
|
14
|
+
before_save :do_the_needful
|
15
|
+
def do_the_needful
|
16
|
+
self.ensure_me ||= "here i am!"
|
17
|
+
end
|
12
18
|
end
|
13
19
|
|
14
20
|
class HappyPlace #Test non-embedded proxies
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm_partial_update
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Nathan Stults
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-02-25 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -134,24 +134,24 @@ extra_rdoc_files: []
|
|
134
134
|
|
135
135
|
files:
|
136
136
|
- lib/mm_partial_update.rb
|
137
|
-
- lib/mm_partial_update/extensions.rb
|
138
137
|
- lib/mm_partial_update/update_command.rb
|
139
138
|
- lib/mm_partial_update/plugins/document.rb
|
140
|
-
- lib/mm_partial_update/plugins/partial_update.rb
|
141
139
|
- lib/mm_partial_update/plugins/embedded_document.rb
|
140
|
+
- lib/mm_partial_update/plugins/partial_update.rb
|
141
|
+
- lib/mm_partial_update/extensions.rb
|
142
142
|
- lib/mm_partial_update/embedded_collection.rb
|
143
143
|
- lib/mm_partial_update/one_embedded_proxy.rb
|
144
144
|
- lib/mm_partial_update/version.rb
|
145
|
+
- test/callbacks_support.rb
|
146
|
+
- test/test_mm_partial_update.rb
|
145
147
|
- test/functional/plugins/test_partial_update.rb
|
146
|
-
- test/functional/plugins/test_embedded_document.rb
|
147
148
|
- test/functional/plugins/test_document.rb
|
149
|
+
- test/functional/plugins/test_embedded_document.rb
|
148
150
|
- test/functional/test_update_command.rb
|
151
|
+
- test/test_partial_update.rb
|
149
152
|
- test/test_helper.rb
|
150
153
|
- test/models.rb
|
151
|
-
- test/callbacks_support.rb
|
152
154
|
- test/test_update_command.rb
|
153
|
-
- test/test_partial_update.rb
|
154
|
-
- test/test_mm_partial_update.rb
|
155
155
|
- LICENSE
|
156
156
|
- README.rdoc
|
157
157
|
has_rdoc: true
|