Add action_text_attachment helper to FixtureSet - #40289
Conversation
There was a problem hiding this comment.
This will likely need some guidance.
I tried to call FixtureSet.context_class... without the ActiveRecord scope, but had autoloading issues. Is there a better way?
There was a problem hiding this comment.
Related to https://github.com/rails/rails/pull/40289/files#r495132398, I had considered making this its own ActiveRecord::FixtureSet clone, and forcing callers to fully qualify their calls as if they were calling something like identify:
body: "<p><%= ActionText::FixtureSet.action_text_attachment %></p>"That would avoid the auto-loading issues, but could be verbose. If this method is prefered, we could drop the action_text prefix and instead declare ActionText::FixtureSet.attachment, which isn't half-bad.
There was a problem hiding this comment.
After more consideration, I've pushed up 7dfd977 to propose those changes instead.
40d84c7 to
7dfd977
Compare
There was a problem hiding this comment.
Maybe this is a step too far and 7dfd977 is better, but I've pushed up the signed_global_id part to ActiveRecord::FixtureSet.
The tests for ActionText still pass, though I wasn't sure on where or how to add an ActiveRecord-side test for the new method.
1ef8c24 to
65ddb55
Compare
There was a problem hiding this comment.
@georgeclaghorn do you think that this is a reasonable addition to the ActiveRecord side of fixtures, or would we be better keeping it self-contained to the ActionText side?
There was a problem hiding this comment.
@georgeclaghorn should this be declared as a fixture-local helper method, or is it reasonable to mirror the ActiveRecord::FixtureSet interface?
65ddb55 to
85af078
Compare
|
I have mixed feelings about the |
There was a problem hiding this comment.
@georgeclaghorn do you feel like additions to both the ActiveRecord side and the introduction of the ActionText side are worthwhile?
Would this be better as an ActionText only change? An ActiveRecord only change that enables people to declare their own <action-text-attachment> elements manually?
There was a problem hiding this comment.
I would like to see this extracted to GlobalID, but that can be done as a separate step. I don’t want to kick this to the next release just because of that.
From within an `action_text/rich_texts.yml` file, generate an
`<action-text-attachment sgid="..."></action-text-attachment>` element
with a valid `sgid` attribute that references another FixtureSet record.
```ruby
hello_world_review_content:
record: hello_world (Review)
name: content
body: <p><%= action_text_attachment("messages", :hello_world) %> is great!</p>
```
85af078 to
86d75a3
Compare
9f844d1 to
9fd59b2
Compare
| signed_global_id = ActiveRecord::FixtureSet.signed_global_id fixture_set_name, label, | ||
| column_type: column_type, for: ActionText::Attachable::LOCATOR_NAME | ||
|
|
||
| %(<action-text-attachment sgid="#{signed_global_id}"></action-text-attachment) |
There was a problem hiding this comment.
Is this missing a trailing >?
There was a problem hiding this comment.
🙀 I wonder if that means the passing test isn't covering this behavior well enough?
I've tested this out in projects outside the Rails test suite, and it worked. Maybe the generated HTML is fixed by browser rendering?
There was a problem hiding this comment.
@georgeclaghorn I've closed the tag in e4e5f19.
|
@seanpdoyle I tried to attach a fixture with UUID as primary key: body: <div><%= ActionText::FixtureSet.attachment("authors", :john) %></div>However the attachment is not found and renders as "☒". If I run the generated attachment's sgid through Also while I'm here I note that forward slashes '/' appear necessary when referencing namespaced fixtures, e.g. ActiveStorage::Blob: body: <div><%= ActionText::FixtureSet.attachment("active_storage/blobs", :poster) %></div>This contrasts with the way fixtures are loaded in test code where the slash is not necessary: |
|
@seanpdoyle OK, I discovered the body: <div><%= ActionText::FixtureSet.attachment("authors", :john, column_type: :uuid) %></div> |
Summary
From within an
action_text/rich_texts.ymlfile, generate an<action-text-attachment sgid="..."></action-text-attachment>elementwith a valid
sgidattribute that references another FixtureSet record.