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 +4 -4
- data/lib/mongoid/embedded_copy/version.rb +1 -1
- data/lib/mongoid/embedded_copy.rb +10 -0
- data/test/embedded_copy_test.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 677ed30fbf9b77f59f79527469a991f45d805fda
|
4
|
+
data.tar.gz: 1fa05f7864adf689087a8150600a720b6adc53c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25b6b3b88426b96211cdfb7650ee0782a8552cc3d583b5c812740f39717485795f4197c837ff3180a525e538d6be7c4d15449645def71f8ebf6c8109e8a02494
|
7
|
+
data.tar.gz: adf834156e6402ea697786733aad935e1f27e1c4c7e56d0111c46ba4f80a90712d60ec607f284f1eec6aa41295e604af792b8e85141369065940900d967a1df6
|
@@ -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|
|
data/test/embedded_copy_test.rb
CHANGED
@@ -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.
|
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:
|