Adds default trix partial
This commit is contained in:
parent
50226c8fe0
commit
764803e07a
|
@ -67,6 +67,10 @@ module ActionText
|
||||||
super.merge(attachable_sgid: attachable_sgid)
|
super.merge(attachable_sgid: attachable_sgid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_trix_content_attachment_partial_path
|
||||||
|
to_partial_path
|
||||||
|
end
|
||||||
|
|
||||||
def to_rich_text_attributes(attributes = {})
|
def to_rich_text_attributes(attributes = {})
|
||||||
attributes.dup.tap do |attrs|
|
attributes.dup.tap do |attrs|
|
||||||
attrs[:sgid] = attachable_sgid
|
attrs[:sgid] = attachable_sgid
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
class Page < ApplicationRecord
|
||||||
|
include ActionText::Attachable
|
||||||
|
end
|
||||||
|
|
|
@ -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
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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|
|
create_table "action_text_rich_texts", force: :cascade do |t|
|
||||||
t.string "name", null: false
|
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
|
t.datetime "updated_at", precision: 6, null: false
|
||||||
end
|
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|
|
create_table "people", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at", precision: 6, null: false
|
t.datetime "created_at", precision: 6, null: false
|
||||||
|
|
|
@ -32,7 +32,8 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
|
||||||
assert_equal attachable.byte_size, trix_attachment.attributes["filesize"]
|
assert_equal attachable.byte_size, trix_attachment.attributes["filesize"]
|
||||||
assert_equal "Captioned", trix_attachment.attributes["caption"]
|
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
|
end
|
||||||
|
|
||||||
test "converts to TrixAttachment with content" do
|
test "converts to TrixAttachment with content" do
|
||||||
|
@ -49,6 +50,11 @@ class ActionText::AttachmentTest < ActiveSupport::TestCase
|
||||||
assert_not_nil trix_attachment.attributes["content"]
|
assert_not_nil trix_attachment.attributes["content"]
|
||||||
end
|
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
|
private
|
||||||
def attachment_from_html(html)
|
def attachment_from_html(html)
|
||||||
ActionText::Content.new(html).attachments.first
|
ActionText::Content.new(html).attachments.first
|
||||||
|
|
Loading…
Reference in New Issue