copyable 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/copyable/declarations/associations.rb +3 -1
- data/lib/copyable/version.rb +1 -1
- data/spec/deep_structure_copy_spec.rb +7 -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: 0859ce58af81fc332e91f2bbd28a5b366bf4ea39
|
4
|
+
data.tar.gz: f8f723985693eb36ef020438477df278bd5d6cd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29faf86afe9848520ee195c143d11ae2d0e4b9f58c957394e00cd4f05399d4b75639c6aef3a274e63ebf7264900d83a6f81562ab6864806aec9a949738868173
|
7
|
+
data.tar.gz: 4160086a9126941852f26add5112e3ee6ad91a9fd7318d4a1e3dde1b81c00f3c3a360ea23c14cea43381ee82a796728d9b4c648840b3b7e552071187b1e6a8c2
|
@@ -8,6 +8,7 @@ module Copyable
|
|
8
8
|
# instructions given in the copyable declaration
|
9
9
|
def execute(association_list, original_model, new_model, skip_validations, skip_associations)
|
10
10
|
@skip_validations = skip_validations
|
11
|
+
@skip_associations = skip_associations
|
11
12
|
association_list.each do |assoc_name, advice|
|
12
13
|
association = original_model.class.reflections[assoc_name.to_sym]
|
13
14
|
check_advice(association, advice, original_model)
|
@@ -78,7 +79,8 @@ module Copyable
|
|
78
79
|
copied_record = original_record.create_copy!(
|
79
80
|
override: { association.foreign_key => parent_model.id },
|
80
81
|
__called_recursively: true,
|
81
|
-
skip_validations: @skip_validations
|
82
|
+
skip_validations: @skip_validations,
|
83
|
+
skip_associations: @skip_associations)
|
82
84
|
else
|
83
85
|
message = "Could not copy #{parent_model.class.name}#id:#{parent_model.id} "
|
84
86
|
message << "because #{original_record.class.name} does not have a copyable declaration."
|
data/lib/copyable/version.rb
CHANGED
@@ -89,6 +89,13 @@ describe 'complex model hierarchies:' do
|
|
89
89
|
expect(CopyableWarranty.count).to eq(3) # Because the amenities weren't copied either
|
90
90
|
end
|
91
91
|
|
92
|
+
it 'should skip nested branches of the tree when directed' do
|
93
|
+
@vehicle2 = @vehicle1.create_copy!(skip_associations: [:copyable_warranty])
|
94
|
+
expect(CopyableVehicle.count).to eq(2)
|
95
|
+
expect(CopyableAmenity.count).to eq(6)
|
96
|
+
expect(CopyableWarranty.count).to eq(3) # No new ones created
|
97
|
+
end
|
98
|
+
|
92
99
|
it 'should create the expected records if copied multiple times' do
|
93
100
|
# this test makes sure the SingleCopyEnforcer isn't too eager
|
94
101
|
@vehicle1.create_copy!
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copyable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wyatt Greene
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|