deep_cloneable 2.4.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ module DeepCloneable
2
+ module SkipValidations
3
+ def perform_validations(options = {})
4
+ options[:validate] = false
5
+ super(options)
6
+ end
7
+ end
8
+ end
data/readme.md CHANGED
@@ -6,8 +6,8 @@ This gem gives every ActiveRecord::Base object the possibility to do a deep clon
6
6
 
7
7
  ## Requirements
8
8
 
9
- * Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, 2.1.5, 2.2.2, 2.3.0, 2.4.4, 2.5.1 (tested)
10
- * Activerecord 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2 (tested)
9
+ * Ruby 1.9.3, 2.0.0, 2.1.5, 2.2.2, 2.3.0, 2.4.4, 2.5.5 (tested)
10
+ * Activerecord 3.1, 3.2, 4.0, 4.1, 4.2, 5.0, 5.1, 5.2, 6.0 (tested)
11
11
  * Rails 2.x/3.0 users, please check out the 'rails2.x-3.0' branch
12
12
 
13
13
  ## Installation
@@ -15,10 +15,19 @@ This gem gives every ActiveRecord::Base object the possibility to do a deep clon
15
15
  * Add deep_cloneable to your Gemfile:
16
16
 
17
17
  ```ruby
18
- gem 'deep_cloneable', '~> 2.4.0'
18
+ gem 'deep_cloneable', '~> 3.0.0'
19
19
  ```
20
20
 
21
- ## Upgrading from v1
21
+ ## Upgrade details
22
+
23
+ ### Upgrading from v2
24
+
25
+ There are two breaking changes that you might need to pay attention to:
26
+
27
+ * When using an optional block (see below), the block used to be evaluated before `deep_cloneable` had performed its changes (inclusions, exclusions, includes). In v3, the block is evaluated after all processing has been done, just before the copy is about to be returned.
28
+ * When a defined association is not found, `deep_cloneable` raises an exception. The exception class has changed namespace: the class definition used to be `ActiveRecord::Base::DeepCloneable::AssociationNotFoundException` and this has changed to `DeepCloneable::AssociationNotFoundException`.
29
+
30
+ ### Upgrading from v1
22
31
 
23
32
  The `dup` method with arguments has been replaced in deep_cloneable 2 by the method `deep_clone`. Please update your sources accordingly.
24
33
 
@@ -158,7 +167,7 @@ end
158
167
 
159
168
  ### Skipping missing associations
160
169
 
161
- By default, deep_cloneable will throw a `ActiveRecord::Base::DeepCloneable::AssociationNotFoundException` error when an association cannot be found. You can also skip missing associations by specifying `skip_missing_associations` if needed, for example when you have associations on some (but not all) subclasses of an STI model:
170
+ By default, deep_cloneable will throw a `DeepCloneable::AssociationNotFoundException` error when an association cannot be found. You can also skip missing associations by specifying `skip_missing_associations` if needed, for example when you have associations on some (but not all) subclasses of an STI model:
162
171
 
163
172
  ```ruby
164
173
  pirate.deep_clone include: [:parrot, :rum], skip_missing_associations: true
@@ -242,7 +242,7 @@ class TestDeepCloneable < MiniTest::Unit::TestCase
242
242
  @chicken = Animal::Chicken.create :name => 'Chick', :humans => [@human], :planet => @earth
243
243
  @dove = Animal::Dove.create :name => 'Dovey', :planet => @earth
244
244
 
245
- assert_raises ActiveRecord::Base::DeepCloneable::AssociationNotFoundException do
245
+ assert_raises ::DeepCloneable::AssociationNotFoundException do
246
246
  @earth.deep_clone(:include => { :birds => :ownerships })
247
247
  end
248
248
 
@@ -350,18 +350,19 @@ class TestDeepCloneable < MiniTest::Unit::TestCase
350
350
  assert_equal deep_clone_parent.errors.messages, :children => ['is invalid']
351
351
  end
352
352
 
353
- def test_child_validations_run_on_save_after_clone_without_validation
353
+ def test_child_validations_dont_run_on_save_after_clone_without_validation
354
354
  child = ChildWithValidation.new
355
355
  child.save :validate => false
356
356
  parent = ParentWithValidation.create :name => 'John', :children => [child]
357
357
 
358
358
  deep_clone_parent = parent.deep_clone :include => :children, :validate => false
359
+ deep_clone_child = deep_clone_parent.children.first
359
360
 
360
361
  assert deep_clone_parent.save
361
362
  assert !deep_clone_parent.new_record?
362
- assert !deep_clone_parent.valid?
363
- assert !deep_clone_parent.children.first.valid?
364
- assert_equal deep_clone_parent.errors.messages, :children => ['is invalid']
363
+ assert !deep_clone_child.new_record?
364
+ assert !deep_clone_child.valid?
365
+ assert_equal deep_clone_child.errors.messages, :name => ["can't be blank"]
365
366
  end
366
367
 
367
368
  def test_self_join_has_many
@@ -436,6 +437,11 @@ class TestDeepCloneable < MiniTest::Unit::TestCase
436
437
  assert_equal 2, deep_clone.subjects.size
437
438
  end
438
439
 
440
+ def test_should_set_association_to_nil_if_conditionals_fail
441
+ deep_clone = @jack.deep_clone(:include => { :ship => { :unless => lambda { |ship| ship.name == 'Black Pearl' } } })
442
+ assert_nil deep_clone.ship
443
+ end
444
+
439
445
  def test_should_reject_copies_if_conditionals_are_passed_with_associations
440
446
  deep_clone = @ship.deep_clone(:include => [:pirates => [:treasures, :mateys, { :unless => lambda { |pirate| pirate.name == 'Jack Sparrow' } }]])
441
447
 
@@ -24,9 +24,8 @@ def load_schema
24
24
  db_adapter = ENV['DB']
25
25
  db_adapter ||= 'sqlite3'
26
26
 
27
- if db_adapter.nil?
28
- raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.'
29
- end
27
+ raise 'No DB Adapter selected. Pass the DB= option to pick one, or install Sqlite or Sqlite3.' if db_adapter.nil?
28
+
30
29
  ActiveRecord::Base.establish_connection(config[db_adapter])
31
30
  load(File.dirname(__FILE__) + '/schema.rb')
32
31
  end
metadata CHANGED
@@ -1,35 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_cloneable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reinier de Lange
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-10 00:00:00.000000000 Z
11
+ date: 2019-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
18
- - !ruby/object:Gem::Version
19
- version: '6'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: 3.1.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - "<"
28
- - !ruby/object:Gem::Version
29
- version: '6'
30
27
  - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: 3.1.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
33
  description: 'Extends the functionality of ActiveRecord::Base#dup to perform a deep
34
34
  clone that includes user specified associations. '
35
35
  email: rjdelange@icloud.com
@@ -65,8 +65,13 @@ files:
65
65
  - gemfiles/5.1.gemfile.lock
66
66
  - gemfiles/5.2.gemfile
67
67
  - gemfiles/5.2.gemfile.lock
68
+ - gemfiles/6.0.gemfile
69
+ - gemfiles/6.0.gemfile.lock
68
70
  - init.rb
69
71
  - lib/deep_cloneable.rb
72
+ - lib/deep_cloneable/association_not_found_exception.rb
73
+ - lib/deep_cloneable/deep_clone.rb
74
+ - lib/deep_cloneable/skip_validations.rb
70
75
  - readme.md
71
76
  - test/database.yml
72
77
  - test/models.rb
@@ -92,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
97
  - !ruby/object:Gem::Version
93
98
  version: '0'
94
99
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.7.6
100
+ rubygems_version: 3.0.2
97
101
  signing_key:
98
102
  specification_version: 4
99
103
  summary: This gem gives every ActiveRecord::Base object the possibility to do a deep