Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex preprocessing of field fails on null value #107

Open
jrmhaig opened this issue Jul 19, 2021 · 0 comments
Open

Regex preprocessing of field fails on null value #107

jrmhaig opened this issue Jul 19, 2021 · 0 comments

Comments

@jrmhaig
Copy link
Collaborator

jrmhaig commented Jul 19, 2021

If a field is set as follows:

amoeba do
  enable
  regex test_field: { replace: /one/, with: 'two' }
end

then amoeba_dup fails if the value in the field is nil.

To reproduce

Create a migration:

class CreateTestModels < ActiveRecord::Migration[6.1]
  def change
    create_table :test_models do |t|
      t.string :test_string

      t.timestamps
    end
  end
end

and the corresponding model:

class TestModel < ApplicationRecord
  amoeba do
    enable
    regex test_field: { replace: /one/, with: 'two' }
  end
end

Then:

irb> test = TestModel.create
irb> test.test_string
=> nil
irb> dup = test.amoeba_dup

Expected behaviour: dup.test_string is set to nil, the same as test.test_string.
Actual behaviour: NoMethodError (undefined method gsub! for nil:NilClass) exception is raised at lib/amoeba/cloner.rb line 159.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant