Skip to content

Commit 76b33aa

Browse files
authored
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>
1 parent 55cfdaf commit 76b33aa

File tree

9 files changed

+61
-0
lines changed

9 files changed

+61
-0
lines changed

actiontext/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
* Declare `ActionText::FixtureSet.attachment` to generate an
2+
`<action-text-attachment sgid="..."></action-text-attachment>` element with
3+
a valid `sgid` attribute.
4+
5+
```ruby
6+
hello_world_review_content:
7+
record: hello_world (Review)
8+
name: content
9+
body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>
10+
```
11+
12+
*Sean Doyle*
13+
114
* Locate `fill_in_rich_text_area` by `<label>` text
215

316
In addition to searching for `<trix-editor>` elements with the appropriate

actiontext/lib/action_text.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module ActionText
1414
autoload :Attribute
1515
autoload :Content
1616
autoload :Fragment
17+
autoload :FixtureSet
1718
autoload :HtmlConversion
1819
autoload :PlainTextConversion
1920
autoload :Rendering
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
module ActionText
4+
class FixtureSet
5+
def self.attachment(fixture_set_name, label, column_type: :integer)
6+
signed_global_id = ActiveRecord::FixtureSet.signed_global_id fixture_set_name, label,
7+
column_type: column_type, for: ActionText::Attachable::LOCATOR_NAME
8+
9+
%(<action-text-attachment sgid="#{signed_global_id}"></action-text-attachment>)
10+
end
11+
end
12+
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
hello_world_review_content:
2+
record: hello_world (Review)
3+
name: content
4+
body: <p><%= ActionText::FixtureSet.attachment("messages", :hello_world) %> is great!</p>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hello_world:
2+
subject: "A greeting"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hello_world:
2+
message: $LABEL
3+
author_name: "Ruby"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
class ActionText::FixtureSetTest < ActiveSupport::TestCase
6+
def test_action_text_attachment
7+
message = messages(:hello_world)
8+
review = reviews(:hello_world)
9+
10+
attachments = review.content.body.attachments
11+
12+
assert_includes attachments.map(&:attachable), message
13+
end
14+
end

activerecord/lib/active_record/fixtures.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,14 @@ def identify(label, column_type = :integer)
585585
end
586586
end
587587

588+
def signed_global_id(fixture_set_name, label, column_type: :integer, **options)
589+
identifier = identify(label, column_type)
590+
model_name = default_fixture_model_name(fixture_set_name)
591+
uri = URI::GID.build([GlobalID.app, model_name, identifier, {}])
592+
593+
SignedGlobalID.new(uri, **options)
594+
end
595+
588596
# Superclass for the evaluation contexts used by ERB fixtures.
589597
def context_class
590598
@context_class ||= Class.new

guides/source/6_1_release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,10 @@ Please refer to the [Changelog][action-text] for detailed changes.
402402
editor and fill it with given HTML content.
403403
([Pull Request](https://github.com/rails/rails/pull/35885))
404404

405+
* Add `ActionText::FixtureSet.attachment` to generate
406+
`<action-text-attachment>` elements in database fixtures.
407+
([Pull Request](https://github.com/rails/rails/pull/40289))
408+
405409
Action Mailbox
406410
----------
407411

0 commit comments

Comments
 (0)