mongoid_deep_cloneable 0.0.2pre → 0.0.3pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mongoid_deep_cloneable.rb +5 -4
- data/lib/mongoid_deep_cloneable/version.rb +1 -1
- data/spec/mongoid_deep_cloneable/cloning_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -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: 75bec5985d4ee1060e4e72ca5e671c14ee5d6d61
|
4
|
+
data.tar.gz: cab5abea5f02414f14f6b0efbe0bbcaa7bcb0f8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1056054cb44d149bec922ed29a659187743ed9387c0605012796acd43934baf948e8ca17c44482a9b4a9b4e56e5e29ed00f3b7f370f1b2c383d4e37b9e9b89a
|
7
|
+
data.tar.gz: fd1c3047ab43b1a5867f76404d831d570ac4e5f91975737fcf026470351309b0e5f0b20439a77818d38e051ffa824d13711cb715dd589a83f7ad9121aa436c28
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/
|
1
|
+
[![Build Status](https://travis-ci.org/3poundhealth/mongoid_deep_cloneable.png?branch=master)](https://travis-ci.org/3poundhealth/mongoid_deep_cloneable)
|
2
2
|
|
3
3
|
# mongoid_deep_cloneable
|
4
4
|
|
@@ -7,8 +7,8 @@ end
|
|
7
7
|
module MongoidDeepCloneable
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
|
-
def deep_clone
|
11
|
-
copy = options.try(:[], :parent) || self.
|
10
|
+
def deep_clone(options={})
|
11
|
+
copy = options.try(:[], :parent) || self.dup
|
12
12
|
if options && options[:include]
|
13
13
|
children_copy options[:include], copy
|
14
14
|
elsif copy.class.respond_to? :clone_associations
|
@@ -19,7 +19,7 @@ module MongoidDeepCloneable
|
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
|
-
def children_copy
|
22
|
+
def children_copy(options, parent)
|
23
23
|
if options.is_a? Hash
|
24
24
|
associations = options.keys.collect &:to_sym
|
25
25
|
elsif options.is_a? Array
|
@@ -34,11 +34,12 @@ private
|
|
34
34
|
children = { include: options[association], build: true } rescue nil
|
35
35
|
if (val = self.send(association)).is_a? Array
|
36
36
|
parent.send("#{association}=", val.map{|x| x.deep_clone(children) })
|
37
|
+
parent.send("#{association}").each(&:save)
|
37
38
|
else
|
38
39
|
parent.send("#{association}=", val)
|
39
40
|
end
|
40
41
|
elsif association.is_a? Hash
|
41
|
-
children_copy
|
42
|
+
children_copy(association, parent)
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -4,6 +4,7 @@ describe MongoidDeepCloneable do
|
|
4
4
|
|
5
5
|
it "should attach its method to existing models" do
|
6
6
|
expect(subject).to respond_to(:deep_clone)
|
7
|
+
# binding.pry
|
7
8
|
end
|
8
9
|
|
9
10
|
it "should make a clone of an object" do
|
@@ -14,6 +15,9 @@ describe MongoidDeepCloneable do
|
|
14
15
|
it "should be able to clone an object with its children" do
|
15
16
|
copy = subject.deep_clone(include: :students)
|
16
17
|
expect(copy.students.map(&:name)).to eq(subject.students.map(&:name))
|
18
|
+
last_student = copy.students.last
|
19
|
+
expect(last_student.changed?).to be_false
|
20
|
+
expect(Student.where(name: last_student.name).count).to eq(2)
|
17
21
|
end
|
18
22
|
|
19
23
|
it "should be able to clone two levels deep" do
|
data/spec/spec_helper.rb
CHANGED
@@ -20,6 +20,10 @@ RSpec.configure do |config|
|
|
20
20
|
config.include FactoryGirl::Syntax::Methods
|
21
21
|
config.include MongoidDeepCloneable
|
22
22
|
|
23
|
+
config.before do
|
24
|
+
Mongoid.default_session.collections.select {|c| c.name !~ /system/ }.each(&:drop)
|
25
|
+
end
|
26
|
+
|
23
27
|
# Run specs in random order to surface order dependencies. If you find an
|
24
28
|
# order dependency and want to debug it, you can fix the order by providing
|
25
29
|
# the seed, which is printed after each run.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_deep_cloneable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyle Macey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|