1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add ActionText::FixtureSet.attachment

Permit generating rich-text attachment markup in YAML fixtures:

    hello_world_review_content:
      record: hello_world (Review)
      name: content
      body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>
This commit is contained in:
Sean Doyle 2020-10-30 15:53:35 -04:00 committed by GitHub
parent 55cfdaf1c0
commit 76b33aa3d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 0 deletions

View file

@ -1,3 +1,16 @@
* Declare `ActionText::FixtureSet.attachment` to generate an
`<action-text-attachment sgid="..."></action-text-attachment>` element with
a valid `sgid` attribute.
```ruby
hello_world_review_content:
record: hello_world (Review)
name: content
body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>
```
*Sean Doyle*
* Locate `fill_in_rich_text_area` by `<label>` text
In addition to searching for `<trix-editor>` elements with the appropriate

View file

@ -14,6 +14,7 @@ module ActionText
autoload :Attribute
autoload :Content
autoload :Fragment
autoload :FixtureSet
autoload :HtmlConversion
autoload :PlainTextConversion
autoload :Rendering

View file

@ -0,0 +1,12 @@
# frozen_string_literal: true
module ActionText
class FixtureSet
def self.attachment(fixture_set_name, label, column_type: :integer)
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>)
end
end
end

View file

@ -0,0 +1,4 @@
hello_world_review_content:
record: hello_world (Review)
name: content
body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>

2
actiontext/test/fixtures/messages.yml vendored Normal file
View file

@ -0,0 +1,2 @@
hello_world:
subject: "A greeting"

3
actiontext/test/fixtures/reviews.yml vendored Normal file
View file

@ -0,0 +1,3 @@
hello_world:
message: $LABEL
author_name: "Ruby"

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
require "test_helper"
class ActionText::FixtureSetTest < ActiveSupport::TestCase
def test_action_text_attachment
message = messages(:hello_world)
review = reviews(:hello_world)
attachments = review.content.body.attachments
assert_includes attachments.map(&:attachable), message
end
end

View file

@ -585,6 +585,14 @@ module ActiveRecord
end
end
def signed_global_id(fixture_set_name, label, column_type: :integer, **options)
identifier = identify(label, column_type)
model_name = default_fixture_model_name(fixture_set_name)
uri = URI::GID.build([GlobalID.app, model_name, identifier, {}])
SignedGlobalID.new(uri, **options)
end
# Superclass for the evaluation contexts used by ERB fixtures.
def context_class
@context_class ||= Class.new

View file

@ -402,6 +402,10 @@ Please refer to the [Changelog][action-text] for detailed changes.
editor and fill it with given HTML content.
([Pull Request](https://github.com/rails/rails/pull/35885))
* Add `ActionText::FixtureSet.attachment` to generate
`<action-text-attachment>` elements in database fixtures.
([Pull Request](https://github.com/rails/rails/pull/40289))
Action Mailbox
----------