copyable 0.0.2 → 0.1.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f42c56201c71a8dae13510b60503300a1f8bfd27
|
4
|
+
data.tar.gz: c4efc57da93c3b9f0a3ff7134dc00bbb84fbba2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69a4aa712cf34f9cba8f598dee4b970bf482ab9b6b71558b14fd5fd0c9a9dfcf7dcb2644543db4ec21c71cc118af0bde080eda5b6f15ab78ba1baecc5d3d5f93
|
7
|
+
data.tar.gz: a64545cc78dea5befe38066e86cdda5a6486bfd5115d77fcda21810802674ce8e7f40a61e9c8637bef8efcc0aa8dcab0d6a041e617b2df40bd1fa96cf9c661bc
|
data/copyable.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "activerecord", "~>4.1"
|
21
|
+
spec.add_dependency "activerecord", "~>4.1.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "database_cleaner", "~> 1.4.0"
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
@@ -59,7 +59,9 @@ module Copyable
|
|
59
59
|
# for this brand new model, visit all of the associated models,
|
60
60
|
# making new copies according to the instructions in the copyable
|
61
61
|
# declaration
|
62
|
-
|
62
|
+
|
63
|
+
skip_associations = options[:skip_associations] || []
|
64
|
+
Declarations::Associations.execute(main.association_list, original_model, new_model, options[:skip_validations], skip_associations)
|
63
65
|
# run the after_copy block if it exists
|
64
66
|
Declarations::AfterCopy.execute(main.after_copy_block, original_model, new_model)
|
65
67
|
ensure
|
@@ -6,12 +6,12 @@ module Copyable
|
|
6
6
|
|
7
7
|
# this is the algorithm for copying associated records according to the
|
8
8
|
# instructions given in the copyable declaration
|
9
|
-
def execute(association_list, original_model, new_model, skip_validations)
|
9
|
+
def execute(association_list, original_model, new_model, skip_validations, skip_associations)
|
10
10
|
@skip_validations = skip_validations
|
11
11
|
association_list.each do |assoc_name, advice|
|
12
12
|
association = original_model.class.reflections[assoc_name.to_sym]
|
13
13
|
check_advice(association, advice, original_model)
|
14
|
-
unless advice == :do_not_copy
|
14
|
+
unless advice == :do_not_copy || skip_associations.include?(assoc_name.to_sym)
|
15
15
|
copy_association(association, original_model, new_model)
|
16
16
|
end
|
17
17
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Copyable
|
2
2
|
class OptionChecker
|
3
3
|
|
4
|
-
VALID_OPTIONS = [:override, :skip_validations]
|
4
|
+
VALID_OPTIONS = [:override, :skip_validations, :skip_associations]
|
5
5
|
VALID_PRIVATE_OPTIONS = [:__called_recursively] # for copyable's internal use only
|
6
6
|
|
7
7
|
def self.check!(options)
|
@@ -17,6 +17,10 @@ module Copyable
|
|
17
17
|
end
|
18
18
|
raise CopyableError.new(message)
|
19
19
|
end
|
20
|
+
# :skip_associations needs to be an array if it's present
|
21
|
+
if (options[:skip_associations].present? && !options[:skip_associations].is_a?(Array))
|
22
|
+
raise CopyableError.new("When :skip_associations is used, it must be an array")
|
23
|
+
end
|
20
24
|
end
|
21
25
|
|
22
26
|
end
|
data/lib/copyable/version.rb
CHANGED
@@ -82,6 +82,13 @@ describe 'complex model hierarchies:' do
|
|
82
82
|
['moon roof warranty', 'twitter warranty', 'jazz warranty'])
|
83
83
|
end
|
84
84
|
|
85
|
+
it 'should skip branches of the tree when directed' do
|
86
|
+
@vehicle2 = @vehicle1.create_copy!(skip_associations: [:copyable_amenities])
|
87
|
+
expect(CopyableVehicle.count).to eq(2)
|
88
|
+
expect(CopyableAmenity.count).to eq(3) # No new ones created
|
89
|
+
expect(CopyableWarranty.count).to eq(3) # Because the amenities weren't copied either
|
90
|
+
end
|
91
|
+
|
85
92
|
it 'should create the expected records if copied multiple times' do
|
86
93
|
# this test makes sure the SingleCopyEnforcer isn't too eager
|
87
94
|
@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.0
|
4
|
+
version: 0.1.0
|
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: 2016-
|
12
|
+
date: 2016-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 4.1.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 4.1.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: database_cleaner
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|