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

Model with ActiveStorage attachment can't be anonymized #19

Open
billabel opened this issue Mar 3, 2023 · 3 comments
Open

Model with ActiveStorage attachment can't be anonymized #19

billabel opened this issue Mar 3, 2023 · 3 comments

Comments

@billabel
Copy link

billabel commented Mar 3, 2023

When I try to anonymize a model with an active storage attachment. E.g. User with a profile picture

# lib/extensions/evil_seed.rb

require "evil_seed"

EvilSeed.configure do |config|
  config.root("User", id: 13055) do |root|
    root.exclude(/.*/) # exclude all associations
  end

  config.anonymize("User") do
    name { Faker::Name.name }
  end
end

I get a method_missing for has_one_attached on this model.

/Users/billabel/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/activerecord-6.1.7.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined method `has_one_attached' for User:Class (NoMethodError)

Is there a fix or workaround? Is this a ruby 3.2 issue?

@Envek
Copy link
Member

Envek commented Mar 6, 2023

undefined method `has_one_attached' for User:Class

That's weird. Probably your application dependencies wasn't required (maybe it is done in one of initializers or whatever)?

Try to initialize your application manually by placing something like this to your lib/extensions/evil_seed.rb:

APP_PATH = File.expand_path('../../config/application', __dir__)
require_relative '../../config/boot'
require_relative '../../config/environment'

@billabel
Copy link
Author

billabel commented Mar 8, 2023

Just following back up. I tried the suggestion, but no luck.

For now, I've just moved to pg_dump and seeds, but I'd love to see if I can get this to work. It looks very promising.

@Envek
Copy link
Member

Envek commented Mar 9, 2023

Can you please try to replicate the issue using some kind of self-contained gist, like this one that Rails uses for reporting ActiveStorage bugs? (but of course adding evil-seed to it)

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

No branches or pull requests

2 participants