-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add ActiveStorage getter and setter generator for has_one_attached and has_many_attached #416
Conversation
You'll have to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
24f71ee
to
50941eb
Compare
25a9c65
to
4eeea3d
Compare
|
||
require "active_storage/engine" | ||
|
||
class Dummy < Rails::Application |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creating a dummy app to run all Rails initializer to load all ActiveStorage classes.
203cdca
to
944997e
Compare
944997e
to
001a27c
Compare
) | ||
scope.create_method( | ||
"#{name}=", | ||
parameters: [create_param("attachable", type: "T.untyped")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems like attachable can be any of the types mentioned here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, thanks!
Motivation
closes #376
Based on ActiveStorage documentation on
has_one_attached
andhas_many_attached
, we are missing getter/setter methods for the attachments.Here is the source code for these getters and setters:
has_one_attached
andhas_many_attached
. The other methods are picked up byActiveRecord
scope and association generators.Implementation
Added an
ActiveStorage
generator that adds the getter and setter methods for the attachments to theActiveRecord
model.Added tests for ActiveStorage associations and scopes to
active_record_associations_spec
andactive_record_scope_spec
. I put the tests in a newdescribe
block, but if there is a more acceptable way to do this let me know.Tests
Added tests for the generator