amoeba 3.3.0 → 3.4.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/activerecord_head.yml +26 -0
  3. data/.github/workflows/jruby.yml +4 -1
  4. data/.github/workflows/rspec.yml +49 -0
  5. data/.github/workflows/rubocop.yml +20 -0
  6. data/.gitignore +1 -0
  7. data/.rubocop.yml +2 -2
  8. data/.rubocop_todo.yml +64 -35
  9. data/Appraisals +25 -15
  10. data/CHANGELOG.md +54 -0
  11. data/Gemfile +1 -0
  12. data/README.md +26 -1
  13. data/amoeba.gemspec +10 -12
  14. data/docs/contributing.md +19 -0
  15. data/docs/test_refactor.md +20 -0
  16. data/gemfiles/activerecord_6.1.gemfile +8 -0
  17. data/gemfiles/activerecord_7.0.gemfile +3 -0
  18. data/gemfiles/{activerecord_6.0.gemfile → activerecord_7.1.gemfile} +3 -1
  19. data/gemfiles/{activerecord_5.2.gemfile → activerecord_8.0.gemfile} +4 -2
  20. data/gemfiles/activerecord_8.1.gemfile +21 -0
  21. data/gemfiles/activerecord_head.gemfile +3 -1
  22. data/gemfiles/jruby_activerecord_7.0.gemfile +2 -2
  23. data/gemfiles/jruby_activerecord_head.gemfile +2 -0
  24. data/lib/amoeba/cloner.rb +4 -2
  25. data/lib/amoeba/config.rb +8 -3
  26. data/lib/amoeba/version.rb +1 -1
  27. data/spec/lib/amoeba_spec.rb +405 -225
  28. data/spec/spec_helper.rb +3 -1
  29. data/spec/support/data.rb +2 -0
  30. data/spec/support/models.rb +11 -2
  31. data/spec/support/schema.rb +2 -0
  32. metadata +26 -43
  33. data/.github/workflows/ruby_25.yml +0 -30
  34. data/.github/workflows/ruby_26.yml +0 -30
  35. data/.github/workflows/ruby_27.yml +0 -30
  36. data/.github/workflows/ruby_30.yml +0 -34
  37. data/.github/workflows/ruby_31.yml +0 -34
  38. data/.github/workflows/ruby_32.yml +0 -34
  39. data/.github/workflows/ruby_head.yml +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29529dad8414b04baff41f8ef9638dc79f118bf259c46ce6769ddb03919d484b
4
- data.tar.gz: 6b3d0507d6c1a6fe325394ccbd620fab75cd73c570ca16275e90bb11234f5c0f
3
+ metadata.gz: e23f137845db9ab5d966278ecc7310519e2194767cb156bd3b20063441d126e2
4
+ data.tar.gz: b0006cfc924dc4d1f443b065ab0592719af14adf0b3a0d58e3f24e680ac404d5
5
5
  SHA512:
6
- metadata.gz: 27bcd19c86d54a1cf5af027aa29ed1e81b79bf21d54459b438789be81999a915950e26311011b38d9b79c0106b8537cf01287f3f89a1974f4b10dfcd56429f7b
7
- data.tar.gz: 86586b2a76dec19a36d3bae63a16cda9301c9659cabb50b0d7b66afe946effd35f7ebe38748ac0f9c398a835f1429d29a5661c94e52187f59db89b1278502cbc
6
+ metadata.gz: 9f49bff4617121516954f3423b512ef9ed0e7e4fe8cbb444c5d6faad681009882948332cd28907c3a194cb4fb18ee9472504b489f24295918b853ecdcdeeb37b
7
+ data.tar.gz: a50ebd357ae15ca4ff5efb96b959e6fa5e3de692de6fd396dc6a64c6a0d188e4a7fa2237f61dc42b59da772320ff0ef8ed967980a9be550381eb89678227e794
@@ -0,0 +1,26 @@
1
+ name: Active Record head
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby_version: [ 3.3, 3.4, '4.0', head ]
15
+ env:
16
+ BUNDLE_GEMFILE: gemfiles/activerecord_head.gemfile
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby_version }}
23
+ bundler-cache: true
24
+ - name: Run tests
25
+ # Allow tests to run on Active Record head without failing the pipeline
26
+ run: bundle exec rspec || true
@@ -9,8 +9,11 @@ on:
9
9
  jobs:
10
10
  test:
11
11
  runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ gemfile: [ jruby_activerecord_7.0 ]
12
15
  env:
13
- BUNDLE_GEMFILE: gemfiles/jruby_activerecord_7.0.gemfile
16
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
14
17
  JRUBY_OPTS: --debug
15
18
  steps:
16
19
  - uses: actions/checkout@v4
@@ -0,0 +1,49 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby_version: [ '3.0', 3.1, 3.2, 3.3, 3.4, '4.0', head ]
16
+ gemfile: [ activerecord_6.1, activerecord_7.0, activerecord_7.1, activerecord_8.0, activerecord_8.1 ]
17
+ exclude:
18
+ # Active Record 6.1 - 7.1 tests require sqlite3 1.6.9 which is not supported in Ruby 4.1 onwards
19
+ - ruby_version: head
20
+ gemfile: activerecord_6.1
21
+ - ruby_version: head
22
+ gemfile: activerecord_7.0
23
+ - ruby_version: head
24
+ gemfile: activerecord_7.1
25
+ - ruby_version: '3.0'
26
+ gemfile: activerecord_8.0
27
+ - ruby_version: '3.0'
28
+ gemfile: activerecord_8.1
29
+ - ruby_version: 3.1
30
+ gemfile: activerecord_8.0
31
+ - ruby_version: 3.1
32
+ gemfile: activerecord_8.1
33
+ - ruby_version: 3.2
34
+ gemfile: activerecord_8.1
35
+ env:
36
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - name: Set up Ruby
40
+ uses: ruby/setup-ruby@v1
41
+ with:
42
+ ruby-version: ${{ matrix.ruby_version }}
43
+ bundler-cache: true
44
+ - name: Run tests
45
+ run: bundle exec rspec
46
+ - name: Coveralls
47
+ uses: coverallsapp/github-action@master
48
+ with:
49
+ github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,20 @@
1
+ name: Rubocop
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: 3.0
18
+ bundler-cache: true
19
+ - name: Run Rubocop
20
+ run: bundle exec rubocop -d
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ coverage
7
7
  .idea
8
8
  gemfiles/*.lock
9
9
  .ruby-version
10
+ tmp/**/*
data/.rubocop.yml CHANGED
@@ -5,10 +5,10 @@ require:
5
5
  inherit_from: .rubocop_todo.yml
6
6
 
7
7
  AllCops:
8
- TargetRubyVersion: 2.5
8
+ TargetRubyVersion: 2.7
9
9
  NewCops: enable
10
10
  Layout/LineLength:
11
- Max: 99
11
+ Max: 120
12
12
  Naming/FileName:
13
13
  Enabled: false
14
14
  Style/ModuleFunction:
data/.rubocop_todo.yml CHANGED
@@ -1,50 +1,71 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-07-10 17:38:28 UTC using RuboCop version 1.16.1.
3
+ # on 2025-12-14 18:27:46 UTC using RuboCop version 1.71.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 10
10
- # Cop supports --auto-correct.
11
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
12
- # URISchemes: http, https
13
- Layout/LineLength:
14
- Max: 110
9
+ # Offense count: 1
10
+ # This cop supports safe autocorrection (--autocorrect).
11
+ # Configuration parameters: Severity, Include.
12
+ # Include: **/*.gemspec
13
+ Gemspec/DeprecatedAttributeAssignment:
14
+ Exclude:
15
+ - 'amoeba.gemspec'
16
+
17
+ # Offense count: 7
18
+ # Configuration parameters: EnforcedStyle, AllowedGems, Include.
19
+ # SupportedStyles: Gemfile, gems.rb, gemspec
20
+ # Include: **/*.gemspec, **/Gemfile, **/gems.rb
21
+ Gemspec/DevelopmentDependencies:
22
+ Exclude:
23
+ - 'amoeba.gemspec'
24
+
25
+ # Offense count: 1
26
+ # This cop supports safe autocorrection (--autocorrect).
27
+ # Configuration parameters: Severity, Include.
28
+ # Include: **/*.gemspec
29
+ Gemspec/RequireMFA:
30
+ Exclude:
31
+ - 'amoeba.gemspec'
32
+
33
+ # Offense count: 1
34
+ # Configuration parameters: Severity, Include.
35
+ # Include: **/*.gemspec
36
+ Gemspec/RequiredRubyVersion:
37
+ Exclude:
38
+ - 'amoeba.gemspec'
15
39
 
16
40
  # Offense count: 1
41
+ # Configuration parameters: AllowedParentClasses.
17
42
  Lint/MissingSuper:
18
43
  Exclude:
19
44
  - 'lib/amoeba/macros/base.rb'
20
45
 
21
46
  # Offense count: 17
47
+ # This cop supports safe autocorrection (--autocorrect).
48
+ # Configuration parameters: AutoCorrect.
22
49
  Lint/UselessAssignment:
23
50
  Exclude:
24
51
  - 'spec/support/data.rb'
25
52
 
26
- # Offense count: 8
27
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
28
- # IgnoredMethods: refine
29
- Metrics/BlockLength:
30
- Max: 339
31
-
32
53
  # Offense count: 2
33
54
  # Configuration parameters: CountComments, CountAsOne.
34
55
  Metrics/ClassLength:
35
- Max: 141
56
+ Max: 130
36
57
 
37
58
  # Offense count: 3
38
59
  # Configuration parameters: ForbiddenDelimiters.
39
- # ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
60
+ # ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
40
61
  Naming/HeredocDelimiterNaming:
41
62
  Exclude:
42
63
  - 'lib/amoeba/config.rb'
43
64
 
44
65
  # Offense count: 2
45
- # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
66
+ # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
46
67
  # SupportedStyles: snake_case, normalcase, non_integer
47
- # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
68
+ # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
48
69
  Naming/VariableNumber:
49
70
  Exclude:
50
71
  - 'spec/support/data.rb'
@@ -52,13 +73,13 @@ Naming/VariableNumber:
52
73
  # Offense count: 1
53
74
  RSpec/BeforeAfterAll:
54
75
  Exclude:
55
- - 'spec/spec_helper.rb'
56
- - 'spec/rails_helper.rb'
57
- - 'spec/support/**/*.rb'
76
+ - '**/spec/spec_helper.rb'
77
+ - '**/spec/rails_helper.rb'
78
+ - '**/spec/support/**/*.rb'
58
79
  - 'spec/lib/amoeba_spec.rb'
59
80
 
60
81
  # Offense count: 12
61
- # Configuration parameters: Prefixes.
82
+ # Configuration parameters: Prefixes, AllowedPatterns.
62
83
  # Prefixes: when, with, without
63
84
  RSpec/ContextWording:
64
85
  Exclude:
@@ -68,12 +89,17 @@ RSpec/ContextWording:
68
89
  # Configuration parameters: IgnoredMetadata.
69
90
  RSpec/DescribeClass:
70
91
  Exclude:
92
+ - '**/spec/features/**/*'
93
+ - '**/spec/requests/**/*'
94
+ - '**/spec/routing/**/*'
95
+ - '**/spec/system/**/*'
96
+ - '**/spec/views/**/*'
71
97
  - 'spec/lib/amoeba_spec.rb'
72
98
 
73
- # Offense count: 3
99
+ # Offense count: 2
74
100
  # Configuration parameters: CountAsOne.
75
101
  RSpec/ExampleLength:
76
- Max: 134
102
+ Max: 29
77
103
 
78
104
  # Offense count: 1
79
105
  # Configuration parameters: .
@@ -81,38 +107,41 @@ RSpec/ExampleLength:
81
107
  RSpec/MessageSpies:
82
108
  EnforcedStyle: receive
83
109
 
84
- # Offense count: 7
110
+ # Offense count: 6
85
111
  RSpec/MultipleExpectations:
86
- Max: 55
112
+ Max: 17
87
113
 
88
114
  # Offense count: 18
89
- # Configuration parameters: IgnoreSharedExamples.
115
+ # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
116
+ # SupportedStyles: always, named_only
90
117
  RSpec/NamedSubject:
91
118
  Exclude:
92
119
  - 'spec/lib/amoeba_spec.rb'
93
120
 
121
+ # Offense count: 3
122
+ # Configuration parameters: AllowedGroups.
123
+ RSpec/NestedGroups:
124
+ Max: 4
125
+
94
126
  # Offense count: 1
95
- # Cop supports --auto-correct.
127
+ # This cop supports unsafe autocorrection (--autocorrect-all).
96
128
  # Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
97
129
  # SupportedStyles: inflected, explicit
98
130
  RSpec/PredicateMatcher:
99
131
  Exclude:
100
132
  - 'spec/lib/amoeba_spec.rb'
101
133
 
102
- # Offense count: 5
103
- # Cop supports --auto-correct.
104
- # Configuration parameters: EnforcedStyle.
105
- # SupportedStyles: always, always_true, never
106
- Style/FrozenStringLiteralComment:
134
+ # Offense count: 25
135
+ # This cop supports safe autocorrection (--autocorrect).
136
+ Style/RedundantConstantBase:
107
137
  Exclude:
108
138
  - 'spec/lib/amoeba_spec.rb'
109
139
  - 'spec/spec_helper.rb'
110
- - 'spec/support/data.rb'
111
140
  - 'spec/support/models.rb'
112
- - 'spec/support/schema.rb'
113
141
 
114
142
  # Offense count: 5
115
- # Cop supports --auto-correct.
143
+ # This cop supports unsafe autocorrection (--autocorrect-all).
144
+ # Configuration parameters: Mode.
116
145
  Style/StringConcatenation:
117
146
  Exclude:
118
147
  - 'spec/lib/amoeba_spec.rb'
data/Appraisals CHANGED
@@ -1,47 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'activerecord-5.2' do
4
- gem 'activerecord', '~> 5.2.0'
3
+ appraise 'activerecord-6.1' do
4
+ gem 'activerecord', '~> 6.1.0'
5
+ gem 'concurrent-ruby', '<= 1.3.4'
6
+ gem 'mutex_m'
7
+ gem 'base64'
8
+ gem 'bigdecimal'
9
+ gem 'logger'
10
+ gem 'benchmark'
5
11
  group :development, :test do
6
- gem 'sqlite3', '~> 1.3.0'
12
+ gem 'sqlite3', '~> 1.6.0'
7
13
  end
8
14
  end
9
15
 
10
- appraise 'activerecord-6.0' do
11
- gem 'activerecord', '~> 6.0.0'
16
+ appraise 'activerecord-7.0' do
17
+ gem 'activerecord', '~> 7.0.0'
18
+ gem 'concurrent-ruby', '<= 1.3.4'
12
19
  group :development, :test do
13
20
  gem 'sqlite3', '~> 1.6.0'
14
21
  end
15
22
  end
16
23
 
17
- appraise 'activerecord-6.1' do
18
- gem 'activerecord', '~> 6.1.0'
24
+ appraise 'activerecord-7.1' do
25
+ gem 'activerecord', '~> 7.1.0'
19
26
  group :development, :test do
20
27
  gem 'sqlite3', '~> 1.6.0'
21
28
  end
22
29
  end
23
30
 
24
- appraise 'activerecord-7.0' do
25
- gem 'activerecord', '~> 7.0.0'
31
+ appraise 'activerecord-8.0' do
32
+ gem 'activerecord', '~> 8.0.0'
26
33
  group :development, :test do
27
- gem 'sqlite3', '~> 1.6.0'
34
+ gem 'sqlite3', '~> 2.1.0'
28
35
  end
29
36
  end
30
37
 
31
- appraise 'jruby-activerecord-7.0' do
32
- gem 'activerecord', '~> 7.0.0'
38
+ appraise 'activerecord-8.1' do
39
+ gem 'activerecord', '~> 8.1.0'
33
40
  group :development, :test do
34
- gem 'activerecord-jdbc-adapter', '~> 70.1'
35
- gem 'activerecord-jdbcsqlite3-adapter', '~> 70.1'
41
+ gem 'sqlite3', '~> 2.1.0'
36
42
  end
37
43
  end
38
44
 
45
+ appraise 'jruby-activerecord-7.0' do
46
+ gem 'activerecord', '~> 7.0.0'
47
+ end
48
+
39
49
  appraise 'activerecord-head' do
40
50
  git 'https://github.com/rails/rails.git', branch: 'main' do
41
51
  gem 'activerecord'
42
52
  end
43
53
  group :development, :test do
44
- gem 'sqlite3', '~> 1.6.0'
54
+ gem 'sqlite3', '~> 2.1.0'
45
55
  end
46
56
  end
47
57
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,57 @@
1
+ ### 3.4.0
2
+
3
+ * Update test matrix for current version for Ruby and Rails. Drop support for Rails versions 5.2 and 6.0, and Ruby 2.5, 2.6 and 2.7. [https://github.com/amoeba-rb/amoeba/pull/120 and https://github.com/amoeba-rb/amoeba/pull/124]
4
+ * Notes on contributing. Github Actions for automate tests. [https://github.com/amoeba-rb/amoeba/pull/124]
5
+ * Fix tests for Active Record after 7.1. [https://github.com/amoeba-rb/amoeba/pull/127]
6
+ * Refactor tests. [https://github.com/amoeba-rb/amoeba/pull/130]
7
+ * Allow `nullify` to accept an `:if` condition. `Config#null_fields` is now a Hash of field names to options rather than an Array of field names, for consistency with `includes` and `excludes`; code reading it directly should use `null_fields.keys`. [https://github.com/amoeba-rb/amoeba/pull/134] Thanks @bvicenzo.
8
+
9
+ #### Breaking change
10
+
11
+ Internally the configuration of `null_fields` is now stored as a `Hash` instead of an `Array`. This could cause failures if you access the `config` directly. For example;
12
+
13
+ ```ruby
14
+ # test.rb
15
+ require_relative 'config/environment'
16
+
17
+ class Post < ActiveRecord::Base
18
+ amoeba do
19
+ enable
20
+ nullify :topic_id
21
+ nullify :likes
22
+ end
23
+ end
24
+
25
+ config = Post.amoeba
26
+
27
+ pp config.null_fields
28
+ pp config.null_fields.first
29
+ pp config.null_fields.map(&:to_s)
30
+ pp config.null_fields << :extra
31
+ ```
32
+
33
+ With previous versions of `amoeba` the output of this will be;
34
+
35
+ ```
36
+ [:topic_id, :likes]
37
+ :topic_id
38
+ ["topic_id", "likes"]
39
+ [:topic_id, :likes, :extra]
40
+ ```
41
+
42
+ With the new version of `amoeba` some of these command execute successfully with changed output and the final line fails with an exception;
43
+
44
+ ```
45
+ {topic_id: {}, likes: {}}
46
+ [:topic_id, {}]
47
+ ["[:topic_id, {}]", "[:likes, {}]"]
48
+ test.rb:18:in '<main>': undefined method '<<' for an instance of Hash (NoMethodError)
49
+
50
+ pp config.null_fields << :extra
51
+ ^^
52
+ Did you mean? <
53
+ ```
54
+
1
55
  ### 3.3.0
2
56
 
3
57
  * Move test pipelines from Travis to Github Actions.
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ group :development, :test do
7
7
  gem 'rake'
8
8
  gem 'simplecov', '~> 0.21.2'
9
9
  gem 'simplecov-lcov', '~> 0.8.0'
10
+ gem 'sqlite3', '~> 1.6'
10
11
  end
11
12
 
12
13
  group :local_development do
data/README.md CHANGED
@@ -6,6 +6,10 @@ Easy cloning of active_record objects including associations and several operati
6
6
  [![Gem Version](https://badge.fury.io/rb/amoeba.svg)](http://badge.fury.io/rb/amoeba)
7
7
  [![Build Status](https://travis-ci.org/amoeba-rb/amoeba.svg?branch=master)](https://travis-ci.org/amoeba-rb/amoeba)
8
8
 
9
+ ## Interested in contributing?
10
+
11
+ See [here.](docs/contributing.md)
12
+
9
13
  ## What?
10
14
 
11
15
  The goal was to be able to easily and quickly reproduce ActiveRecord objects including their children, for example copying a blog post maintaining its associated tags or categories.
@@ -336,6 +340,25 @@ This example will copy all of a post's comments. It will also nullify the publis
336
340
 
337
341
  Unlike inclusive and exclusive styles, specifying null fields will not automatically enable amoeba to copy all child records. As with any active record object, the default field value will be used instead of `nil` if a default value exists on the migration.
338
342
 
343
+ A field may also be nullified only under a given condition, by passing the name of a method on the source record to the `:if` option, just like the [conditions](#conditions) available for `include_association` and `exclude_association`:
344
+
345
+ ```ruby
346
+ class Post < ActiveRecord::Base
347
+ belongs_to :topic
348
+
349
+ amoeba do
350
+ nullify :date_published
351
+ nullify :topic_id, if: :popular?
352
+ end
353
+
354
+ def popular?
355
+ likes > 15
356
+ end
357
+ end
358
+ ```
359
+
360
+ Here `date_published` is always nullified, while `topic_id` is only nullified when `popular?` returns a truthy value on the post being copied. The `:if` option accepts a method name only.
361
+
339
362
  #### Set
340
363
 
341
364
  If you wish to just set a field to an arbitrary value on all duplicated objects you may use the `set` directive. For example, if you wanted to copy an object that has some kind of approval process associated with it, you likely may wish to set the new object's state to be open or "in progress" again.
@@ -984,7 +1007,7 @@ After cloning we will get instance of `Child` instead of `ChildPrototype`
984
1007
 
985
1008
  ## Remapping associations
986
1009
 
987
- If you will need to do complex cloning with remapping associations name you can user `remapper`:
1010
+ If you will need to do complex cloning with remapping associations name you can use `remapper`:
988
1011
 
989
1012
  ```ruby
990
1013
  class ObjectPrototype < ActiveRecord::Base
@@ -1125,6 +1148,8 @@ end
1125
1148
 
1126
1149
  Adds a field to the list of non-association based fields which should be set to nil during copy. All fields in this list will be set to `nil` - note that any nullified field will be given its default value if a default value exists on this model's migration. This method may be called multiple times, once per desired field, or you may pass an array of field names. Passing a single symbol will add to the list of null fields. Passing an array will empty the list and replace it with the array you pass.
1127
1150
 
1151
+ Accepts an `:if` option, taking the name of a method that is called on the record being copied. The field is only nullified when that method returns a truthy value, e.g. `nullify :topic_id, if: :popular?`. When an array of field names is given, the condition applies to every field in the array. Declaring the same field again without `:if` clears a condition previously set on it.
1152
+
1128
1153
  #### prepend
1129
1154
 
1130
1155
  Prefix a field with some text. This only works for string fields. Accepts a hash of fields to prepend. The keys are the field names and the values are the prefix strings. An example scenario would be to add a string such as "Copy of " to your title field. Don't forget to include extra space to the right if you want it. Passing a hash will add each key value pair to the list of prepend directives. If you wish to empty the list of directives, you may pass the hash inside of an array like this `[{:title => "Copy of "}]`.
data/amoeba.gemspec CHANGED
@@ -7,12 +7,12 @@ require 'amoeba/version'
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'amoeba'
9
9
  s.version = Amoeba::VERSION
10
- s.authors = ['Vaughn Draughon', 'Oleksandr Simonov']
11
- s.email = 'alex@simonov.me'
10
+ s.authors = ['Vaughn Draughon', 'Oleksandr Simonov', 'Joseph Haig']
11
+ s.email = 'josephhaig@gmail.com'
12
12
  s.homepage = 'http://github.com/amoeba-rb/amoeba'
13
13
  s.license = 'BSD-2-Clause'
14
14
  s.summary = 'Easy copying of rails models and their child associations.'
15
- s.required_ruby_version = '>= 2.5'
15
+ s.required_ruby_version = '>= 3.0'
16
16
 
17
17
  s.description = <<~DESCRIPTION
18
18
  An extension to ActiveRecord to allow the duplication method to also copy associated children, with recursive support for nested of grandchildren. The behavior is controllable with a simple DSL both on your rails models and on the fly, i.e. per instance. Numerous configuration styles and preprocessing directives are included for power and flexibility. Supports preprocessing of field values to prepend strings such as "Copy of ", to nullify or process field values with regular expressions. Supports most association types including has_one :through and has_many :through.
@@ -26,17 +26,15 @@ Gem::Specification.new do |s|
26
26
  s.require_paths = ['lib']
27
27
 
28
28
  # specify any dependencies here; for example:
29
- s.add_development_dependency 'rspec', '>= 3.0.0'
30
- s.add_development_dependency 'rubocop', '~> 1.16'
31
- s.add_development_dependency 'rubocop-rake', '~> 0.6'
32
- s.add_development_dependency 'rubocop-rspec', '~> 2.4'
29
+ s.add_development_dependency 'rspec', '~> 3.13.0'
30
+ s.add_development_dependency 'rubocop', '~> 1.71.0'
31
+ s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
32
+ s.add_development_dependency 'rubocop-rspec', '~> 2.27.1'
33
33
 
34
34
  if RUBY_PLATFORM == 'java'
35
- s.add_development_dependency 'activerecord-jdbc-adapter', '~> 70.0'
36
- s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', '~> 70.0'
37
- else
38
- s.add_development_dependency 'sqlite3', '>= 1.3'
35
+ s.add_development_dependency 'activerecord-jdbc-adapter', '= 70.1'
36
+ s.add_development_dependency 'activerecord-jdbcsqlite3-adapter', '= 70.1'
39
37
  end
40
38
 
41
- s.add_dependency 'activerecord', '>= 5.2.0'
39
+ s.add_dependency 'activerecord', '>= 6.1.0'
42
40
  end
@@ -0,0 +1,19 @@
1
+ # Contributing to Amoeba
2
+
3
+ Contributations to this project are welcome. The current needs are;
4
+
5
+ * More structured documentation
6
+ * [Refactoring tests](test_refactor.md)
7
+ * Identifying and prioritising features that could be implemented from the long list of issues
8
+ * Reviewing of pull requests
9
+
10
+ ## Some notes regarding pull requests
11
+
12
+ When making code changes please include unit tests for any new code and ensure that all tests pass for supported versions of Ruby and Active Record. These tests are run automatically.
13
+
14
+ Note that the tests are also run automatically for the current development branches of Ruby and Active Record. It is not necessary for all tests to pass in these cases and they are set up to always report as a success to avoid causing the whole pipeline to appear as failed[^1]. However;
15
+
16
+ * Please try at least for new tests in the PR to pass unless there is an identifiable issue in the development version of either Ruby or Active Record.
17
+ * For any new failures you see please consider raising an issue to have it fixed.
18
+
19
+ [^1]: See [this issue](https://github.com/actions/runner/issues/2347) and [this discussion](https://github.com/orgs/community/discussions/15452) for a long-running discussion on the missing "allow failure" feature in Github Actions.
@@ -0,0 +1,20 @@
1
+ # Test refactor
2
+
3
+ ## Motivation
4
+
5
+ This gem has been unmaintained for some time but is still used. This could
6
+ cause problems if it becomes incompatible with new versions of Active Record.
7
+ Additionally, there are lots of issues that have been raised and there could be
8
+ other features of Active Record that should be supported. However, the tests
9
+ not easy to understand as they generally comprise a large setup of data
10
+ followed by multiple expectations with no indication of their purpose. A better
11
+ structure for the tests would allow for making changes with more confidence.
12
+
13
+ ## Plan
14
+
15
+ All of the tests are currently in `spec/lib/amoeba_spec.rb`. New tests will be
16
+ created to mimic the modules so, for example;
17
+
18
+ * `spec/lib/amoeba/cloner_spec.rb` to test the `Amoeba::Cloner` class.
19
+ * `spec/lib/amoeba/macros/has_many_spec.rb` to test the
20
+ `Amoeba::Macros::HasMany` module.
@@ -1,8 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
5
  source 'https://rubygems.org'
4
6
 
5
7
  gem 'activerecord', '~> 6.1.0'
8
+ gem 'base64'
9
+ gem 'benchmark'
10
+ gem 'bigdecimal'
11
+ gem 'concurrent-ruby', '<= 1.3.4'
12
+ gem 'logger'
13
+ gem 'mutex_m'
6
14
 
7
15
  group :development, :test do
8
16
  gem 'rake'
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
5
  source 'https://rubygems.org'
4
6
 
5
7
  gem 'activerecord', '~> 7.0.0'
8
+ gem 'concurrent-ruby', '<= 1.3.4'
6
9
 
7
10
  group :development, :test do
8
11
  gem 'rake'
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
5
  source 'https://rubygems.org'
4
6
 
5
- gem 'activerecord', '~> 6.0.0'
7
+ gem 'activerecord', '~> 7.1.0'
6
8
 
7
9
  group :development, :test do
8
10
  gem 'rake'
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by Appraisal
2
4
 
3
5
  source 'https://rubygems.org'
4
6
 
5
- gem 'activerecord', '~> 5.2.0'
7
+ gem 'activerecord', '~> 8.0.0'
6
8
 
7
9
  group :development, :test do
8
10
  gem 'rake'
9
11
  gem 'simplecov', '~> 0.21.2'
10
12
  gem 'simplecov-lcov', '~> 0.8.0'
11
- gem 'sqlite3', '~> 1.3.0'
13
+ gem 'sqlite3', '~> 2.1.0'
12
14
  end
13
15
 
14
16
  group :local_development do