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:
parent
55cfdaf1c0
commit
76b33aa3d1
9 changed files with 61 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -14,6 +14,7 @@ module ActionText
|
|||
autoload :Attribute
|
||||
autoload :Content
|
||||
autoload :Fragment
|
||||
autoload :FixtureSet
|
||||
autoload :HtmlConversion
|
||||
autoload :PlainTextConversion
|
||||
autoload :Rendering
|
||||
|
|
12
actiontext/lib/action_text/fixture_set.rb
Normal file
12
actiontext/lib/action_text/fixture_set.rb
Normal 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
|
4
actiontext/test/fixtures/action_text/rich_texts.yml
vendored
Normal file
4
actiontext/test/fixtures/action_text/rich_texts.yml
vendored
Normal 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
2
actiontext/test/fixtures/messages.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
hello_world:
|
||||
subject: "A greeting"
|
3
actiontext/test/fixtures/reviews.yml
vendored
Normal file
3
actiontext/test/fixtures/reviews.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
hello_world:
|
||||
message: $LABEL
|
||||
author_name: "Ruby"
|
14
actiontext/test/unit/fixture_set_test.rb
Normal file
14
actiontext/test/unit/fixture_set_test.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
----------
|
||||
|
||||
|
|
Loading…
Reference in a new issue