From 969830451c27345650b984610336b33112475fed Mon Sep 17 00:00:00 2001 From: Sean Doyle Date: Sun, 10 Oct 2021 13:32:52 -0400 Subject: [PATCH] DOCS: Improve ActionText FixtureSet Ruby docs * Resolves test directory inconsistencies * Separates Ruby code fences from YAML code fences * Various prose edits --- actiontext/lib/action_text/fixture_set.rb | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/actiontext/lib/action_text/fixture_set.rb b/actiontext/lib/action_text/fixture_set.rb index b3641f457e..4f9465f028 100644 --- a/actiontext/lib/action_text/fixture_set.rb +++ b/actiontext/lib/action_text/fixture_set.rb @@ -10,23 +10,26 @@ module ActionText # === YAML # # Like other Active Record-backed models, ActionText::RichText records inherit - # from ActiveRecord::Base instances and therefore can be populated by + # from ActiveRecord::Base instances and can therefore be populated by # fixtures. # - # Consider a hypothetical Article model class, its related fixture - # data, as well as fixture data for related ActionText::RichText records: + # Consider an Article class: # - # # app/models/article.rb # class Article < ApplicationRecord # has_rich_text :content # end # - # # tests/fixtures/articles.yml + # To declare fixture data for the related content, first declare fixture + # data for Article instances in test/fixtures/articles.yml: + # # first: # title: An Article # - # # tests/fixtures/action_text/rich_texts.yml - # first_content: + # Then declare the ActionText::RichText fixture data in + # test/fixtures/action_text/rich_texts.yml, making sure to declare + # each entry's record: key as a polymorphic relationship: + # + # first: # record: first (Article) # name: content # body:
Hello, world.
@@ -39,18 +42,21 @@ module ActionText # # === Examples # - # For example, consider a second Article record that mentions the - # first as part of its content HTML: + # For example, consider a second Article fixture declared in + # test/fixtures/articles.yml: # - # # tests/fixtures/articles.yml # second: # title: Another Article # - # # tests/fixtures/action_text/rich_texts.yml - # second_content: + # You can attach a mention of articles(:first) to second's + # content by embedding a call to ActionText::FixtureSet.attachment + # in the body: value in test/fixtures/action_text/rich_texts.yml: + # + # second: # record: second (Article) # name: content # body:
Hello, <%= ActionText::FixtureSet.attachment("articles", :first) %>
+ # 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