mm_partial_update 0.1.2 → 0.1.3

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.
@@ -4,7 +4,6 @@ class Object
4
4
  end
5
5
  end
6
6
 
7
-
8
7
  module MongoMapper
9
8
  module Plugins
10
9
  module Associations
@@ -55,7 +55,7 @@ module MmPartialUpdate
55
55
 
56
56
  add_create_self_to_command(selector, command) and return if new?
57
57
 
58
- field_changes = changes
58
+ field_changes = persistable_changes
59
59
 
60
60
  associations.values.each do |association|
61
61
  proxy = get_proxy(association)
@@ -71,6 +71,19 @@ module MmPartialUpdate
71
71
  command.tap {|c|c.set(selector,field_changes)}
72
72
  end
73
73
 
74
+ #Since we are going to persist the values directly from
75
+ # the changes hash, we need to make sure they are
76
+ # propertly readied for storage
77
+ def persistable_changes
78
+ changes.tap do |persistable_changes|
79
+ persistable_changes.each_pair do |key_name, value|
80
+ if (key = keys[key_name])
81
+ value[-1] = key.set(value[-1])
82
+ end
83
+ end
84
+ end
85
+ end
86
+
74
87
  private
75
88
 
76
89
  def add_create_self_to_command(selector, command)
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module MmPartialUpdate
3
- Version = '0.1.2'
3
+ Version = '0.1.3'
4
4
  end
@@ -1,6 +1,8 @@
1
1
  require 'test_helper'
2
2
  require "models"
3
3
 
4
+ Time.zone = "UTC"
5
+
4
6
  class TestPartialUpdate < Test::Unit::TestCase
5
7
  context "#save_changes" do
6
8
  should "create unsaved entities" do
@@ -163,12 +165,24 @@ class TestPartialUpdate < Test::Unit::TestCase
163
165
  should 'be business as usual' do
164
166
  p = Person.new :name=>"Willard"
165
167
  p.happy_place = HappyPlace.new :description=>"A cool breeze rustles my hair as terradactyls glide gracefully overhead"
166
- p.save!
167
-
168
+ p.save_changes!
168
169
  p.reload
169
170
  p.happy_place.should_not be_nil
170
171
  end
171
172
  end
172
173
 
174
+ context "multiple save - load operations" do
175
+ should "be business as usual" do
176
+ hp = HappyPlace.create! :description=>"Hi there"
177
+ hp1 = HappyPlace.find(hp.id)
178
+ hp2 = HappyPlace.find(hp.id)
179
+ hp1.description = "ho"
180
+ hp2.description = "hi"
181
+ hp2.save!
182
+ hp1.save!
183
+ hp.reload
184
+ hp.description.should == "ho"
185
+ end
186
+ end
173
187
 
174
188
  end
data/test/models.rb CHANGED
@@ -3,18 +3,24 @@ require "callbacks_support"
3
3
  class Person
4
4
  include MongoMapper::Document
5
5
  include CallbacksSupport
6
-
7
6
  key :name, String
8
7
  many :pets
9
8
  one :happy_place
10
9
  one :favorite_pet, :class_name=>'Pet'
10
+
11
+ timestamps!
11
12
  end
12
13
 
13
14
  class HappyPlace #Test non-embedded proxies
14
15
  include MongoMapper::Document
16
+
17
+ persistence_strategy :changes_only
18
+
15
19
  key :description, String
16
20
  key :person_id, ObjectId
17
21
  belongs_to :person
22
+
23
+ timestamps!
18
24
  end
19
25
 
20
26
  class ValidatedPerson < Person
@@ -26,6 +32,7 @@ end
26
32
  class Pet
27
33
  include MongoMapper::EmbeddedDocument
28
34
  include CallbacksSupport
35
+ plugin MongoMapper::Plugins::Timestamps
29
36
  key :name, String
30
37
  key :age, Integer
31
38
  many :fleas
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
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: 2010-11-23 00:00:00 -08:00
18
+ date: 2010-12-01 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -109,6 +109,20 @@ dependencies:
109
109
  - 11
110
110
  version: "2.11"
111
111
  requirement: *id006
112
+ - !ruby/object:Gem::Dependency
113
+ type: :development
114
+ name: tzinfo
115
+ prerelease: false
116
+ version_requirements: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirement: *id007
112
126
  description:
113
127
  email:
114
128
  - hereiam@sonic.net