mongoid-embedded_copy 1.0.1 → 1.0.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: 7072bf2f0505119bffa05338cffdee1f557a808e
4
- data.tar.gz: 3fb24208017739ca2c6cb3820ca6af758951ea62
3
+ metadata.gz: 677ed30fbf9b77f59f79527469a991f45d805fda
4
+ data.tar.gz: 1fa05f7864adf689087a8150600a720b6adc53c9
5
5
  SHA512:
6
- metadata.gz: ae7a9ae7a35e68a584ccb61a78b1326292eea0c460d4e52216a8ab5c81298abcdac95de0a0a2083fd9fd50f6752184b9a8404ad4093360093e7fd24d736c15f2
7
- data.tar.gz: a5e541795750ba55fa8b9b05df5adfdbb3477d93e0d81f78ed9d40628977dfed96b77bc00b06ee4e76aa26330589c69bcc33327bdbe6c8ee4f5b177375c3fac9
6
+ metadata.gz: 25b6b3b88426b96211cdfb7650ee0782a8552cc3d583b5c812740f39717485795f4197c837ff3180a525e538d6be7c4d15449645def71f8ebf6c8109e8a02494
7
+ data.tar.gz: adf834156e6402ea697786733aad935e1f27e1c4c7e56d0111c46ba4f80a90712d60ec607f284f1eec6aa41295e604af792b8e85141369065940900d967a1df6
@@ -1,6 +1,6 @@
1
1
  module Mongoid
2
2
  module EmbeddedCopy
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
6
6
 
@@ -64,6 +64,16 @@ module Mongoid
64
64
  super(attrs)
65
65
  end
66
66
 
67
+ def update_from_original
68
+ update_from(load_original)
69
+ end
70
+
71
+ def update_from(document)
72
+ attrs = document.attributes.to_h.dup
73
+ skipped_attributes.each {|n| attrs.delete(n) }
74
+ update_attributes(attrs)
75
+ end
76
+
67
77
  embedded_in embed_name, embed_opts
68
78
 
69
79
  klass.fields.each do |name, f|
@@ -73,5 +73,21 @@ class EmbeddedCopyTest < BaseTest
73
73
  user.a_post.some_method
74
74
  end
75
75
  end
76
+
77
+ test 'should update copy from given object' do
78
+ post = Post.create({title: 'Hello', content: 'Hello World'})
79
+ user = User.create({firstname: 'Geoffroy', lastname: 'Planquart', a_post: post})
80
+
81
+ post.title = 'World'
82
+ user.a_post = post
83
+ assert_equal 'Hello', user.a_post.title
84
+ user.a_post.update_from(post)
85
+ assert_equal 'World', user.a_post.title
86
+
87
+ post.title = 'Hello World'
88
+ post.save
89
+ user.a_post.update_from_original
90
+ assert_equal 'Hello World', user.a_post.title
91
+ end
76
92
  end
77
93
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-embedded_copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffroy Planquart
@@ -84,6 +84,6 @@ test_files:
84
84
  - test/models/user.rb
85
85
  - test/models/post.rb
86
86
  - test/mongoid.yml
87
- - test/embedded_copy_test.rb
88
87
  - test/test_helper.rb
88
+ - test/embedded_copy_test.rb
89
89
  has_rdoc: