Adds default trix partial

This commit is contained in:
Chris Oliver 2019-03-05 11:29:32 -06:00
parent 50226c8fe0
commit 764803e07a
5 changed files with 31 additions and 2 deletions

View File

@ -67,6 +67,10 @@ module ActionText
super.merge(attachable_sgid: attachable_sgid)
end
def to_trix_content_attachment_partial_path
to_partial_path
end
def to_rich_text_attributes(attributes = {})
attributes.dup.tap do |attrs|
attrs[:sgid] = attachable_sgid

View File

@ -0,0 +1,4 @@
class Page < ApplicationRecord
include ActionText::Attachable
end

View File

@ -0,0 +1,9 @@
class CreatePages < ActiveRecord::Migration[6.0]
def change
create_table :pages do |t|
t.string :title
t.timestamps
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2018_10_03_185713) do
ActiveRecord::Schema.define(version: 2019_03_05_172303) do
create_table "action_text_rich_texts", force: :cascade do |t|
t.string "name", null: false
@ -49,6 +49,12 @@ ActiveRecord::Schema.define(version: 2018_10_03_185713) do
t.datetime "updated_at", precision: 6, null: false
end
create_table "pages", force: :cascade do |t|
t.string "title"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "people", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false

View File

@ -32,7 +32,8 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
assert_equal attachable.byte_size, trix_attachment.attributes["filesize"]
assert_equal "Captioned", trix_attachment.attributes["caption"]
assert_nil trix_attachment.attributes["content"]
assert_not_nil attachable.to_trix_content_attachment_partial_path
assert_not_nil trix_attachment.attributes["content"]
end
test "converts to TrixAttachment with content" do
@ -49,6 +50,11 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
assert_not_nil trix_attachment.attributes["content"]
end
test "defaults trix partial to model partial" do
attachable = Page.create! title: "Homepage"
assert_equal "pages/page", attachable.to_trix_content_attachment_partial_path
end
private
def attachment_from_html(html)
ActionText::Content.new(html).attachments.first