copyable 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c394690b8922c1b1d88ff6665fb2b4e640d8459
|
4
|
+
data.tar.gz: c7f7852188d8a62166b93063d85c77b8a1b1f31a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f5f9657c9506dd9583327da181245782944a57a54ced61627c87b3794aa851ba87e5a656aaeb391170c1b0cf31f5442a15398baa2931d2f7f2c918b88626f4d
|
7
|
+
data.tar.gz: e7dc40c25c3b728d940c648b6a528cc9ba2b740d85b12307b30e40dc3135bed51387b6c0f005036ba8279886b8d1ff6b9efec652a58b7b9b105e0c97979d8dc8
|
data/copyable.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'copyable/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "copyable"
|
8
8
|
spec.version = Copyable::VERSION
|
9
|
-
spec.authors = ["Wyatt Greene", "Dennis Chan"]
|
10
|
-
spec.email = ["dchan@
|
9
|
+
spec.authors = ["Wyatt Greene", "Dennis Chan", "Anne Geiersbach", "Parker Morse"]
|
10
|
+
spec.email = ["dchan@dmgroupK12.com", "ageiersbach@dmgroupK12.com", "pmorse@dmgroupK12.com"]
|
11
11
|
spec.summary = %q{ActiveRecord copier}
|
12
12
|
spec.description = %q{Copyable makes it easy to copy ActiveRecord models.}
|
13
13
|
spec.homepage = "https://github.com/dmcouncil/copyable"
|
@@ -49,6 +49,8 @@ module Copyable
|
|
49
49
|
# fill in each column of this brand new model according to the
|
50
50
|
# instructions given in the copyable declaration
|
51
51
|
column_overrides = options[:override] || {}
|
52
|
+
# merge with global override hash if exists
|
53
|
+
column_overrides = column_overrides.merge(options[:global_override]) if options[:global_override]
|
52
54
|
Declarations::Columns.execute(main.column_list, original_model, new_model, column_overrides)
|
53
55
|
# save that sucker!
|
54
56
|
Copyable::Saver.save!(new_model, options[:skip_validations])
|
@@ -61,7 +63,7 @@ module Copyable
|
|
61
63
|
# declaration
|
62
64
|
|
63
65
|
skip_associations = options[:skip_associations] || []
|
64
|
-
Declarations::Associations.execute(main.association_list, original_model, new_model, options[:skip_validations], skip_associations)
|
66
|
+
Declarations::Associations.execute(main.association_list, original_model, new_model, options[:global_override], options[:skip_validations], skip_associations)
|
65
67
|
# run the after_copy block if it exists
|
66
68
|
Declarations::AfterCopy.execute(main.after_copy_block, original_model, new_model)
|
67
69
|
ensure
|
@@ -6,9 +6,10 @@ 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, skip_associations)
|
9
|
+
def execute(association_list, original_model, new_model, global_override = {}, skip_validations, skip_associations)
|
10
10
|
@skip_validations = skip_validations
|
11
11
|
@skip_associations = skip_associations
|
12
|
+
@global_override = global_override
|
12
13
|
association_list.each do |assoc_name, advice|
|
13
14
|
association = original_model.class.reflections[assoc_name.to_sym]
|
14
15
|
check_advice(association, advice, original_model)
|
@@ -79,6 +80,7 @@ module Copyable
|
|
79
80
|
copied_record = original_record.create_copy!(
|
80
81
|
override: { association.foreign_key => parent_model.id },
|
81
82
|
__called_recursively: true,
|
83
|
+
global_override: @global_override,
|
82
84
|
skip_validations: @skip_validations,
|
83
85
|
skip_associations: @skip_associations)
|
84
86
|
else
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Copyable
|
2
2
|
class OptionChecker
|
3
3
|
|
4
|
-
VALID_OPTIONS = [:override, :skip_validations, :skip_associations]
|
4
|
+
VALID_OPTIONS = [:override, :global_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)
|
data/lib/copyable/version.rb
CHANGED
@@ -129,6 +129,20 @@ describe 'complex model hierarchies:' do
|
|
129
129
|
expect(CopyableVehicle.count).to eq(2)
|
130
130
|
expect(CopyableAmenity.count).to eq(2)
|
131
131
|
end
|
132
|
+
|
133
|
+
context 'with a global override, can copy vehicle with new owner' do
|
134
|
+
before(:each) do
|
135
|
+
@jane = CopyableOwner.create!(name: 'Jane')
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should copy the records correctly' do
|
139
|
+
@copy_of_joes_car = @porsche.create_copy!(global_override: { copyable_owner_id: @jane.id })
|
140
|
+
expect(CopyableVehicle.count).to eq(2)
|
141
|
+
expect(CopyableAmenity.count).to eq(2)
|
142
|
+
expect(@copy_of_joes_car.copyable_owner_id).to eq(@jane.id)
|
143
|
+
expect(@copy_of_joes_car.copyable_amenities.map(&:copyable_owner_id).uniq).to eq([@jane.id])
|
144
|
+
end
|
145
|
+
end
|
132
146
|
end
|
133
147
|
|
134
148
|
context 'with many models, some having redundant associations' do
|
metadata
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copyable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wyatt Greene
|
8
8
|
- Dennis Chan
|
9
|
+
- Anne Geiersbach
|
10
|
+
- Parker Morse
|
9
11
|
autorequire:
|
10
12
|
bindir: bin
|
11
13
|
cert_chain: []
|
12
|
-
date: 2018-
|
14
|
+
date: 2018-12-05 00:00:00.000000000 Z
|
13
15
|
dependencies:
|
14
16
|
- !ruby/object:Gem::Dependency
|
15
17
|
name: activerecord
|
@@ -97,7 +99,9 @@ dependencies:
|
|
97
99
|
version: '0'
|
98
100
|
description: Copyable makes it easy to copy ActiveRecord models.
|
99
101
|
email:
|
100
|
-
- dchan@
|
102
|
+
- dchan@dmgroupK12.com
|
103
|
+
- ageiersbach@dmgroupK12.com
|
104
|
+
- pmorse@dmgroupK12.com
|
101
105
|
executables: []
|
102
106
|
extensions: []
|
103
107
|
extra_rdoc_files: []
|
@@ -174,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
178
|
version: '0'
|
175
179
|
requirements: []
|
176
180
|
rubyforge_project:
|
177
|
-
rubygems_version: 2.6
|
181
|
+
rubygems_version: 2.4.6
|
178
182
|
signing_key:
|
179
183
|
specification_version: 4
|
180
184
|
summary: ActiveRecord copier
|