mirror of
https://github.com/glitch-soc/mastodon.git
synced 2026-03-29 03:00:33 +02:00
Add column for html descriptions of collections (#38124)
This commit is contained in:
@@ -5,7 +5,8 @@
|
||||
# Table name: collections
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# description :text not null
|
||||
# description :text
|
||||
# description_html :text
|
||||
# discoverable :boolean not null
|
||||
# item_count :integer default(0), not null
|
||||
# language :string
|
||||
@@ -30,7 +31,10 @@ class Collection < ApplicationRecord
|
||||
has_many :collection_reports, dependent: :delete_all
|
||||
|
||||
validates :name, presence: true
|
||||
validates :description, presence: true
|
||||
validates :description, presence: true,
|
||||
if: :local?
|
||||
validates :description_html, presence: true,
|
||||
if: :remote?
|
||||
validates :local, inclusion: [true, false]
|
||||
validates :sensitive, inclusion: [true, false]
|
||||
validates :discoverable, inclusion: [true, false]
|
||||
|
||||
@@ -13,6 +13,10 @@ class REST::CollectionSerializer < ActiveModel::Serializer
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def description
|
||||
object.local? ? object.description : object.description_html
|
||||
end
|
||||
|
||||
def items
|
||||
object.items_for(current_user&.account)
|
||||
end
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddDescriptionHtmlToCollections < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
add_column :collections, :description_html, :text
|
||||
|
||||
reversible do |direction|
|
||||
direction.up { change_column :collections, :description, :text, null: true }
|
||||
|
||||
direction.down { change_column :collections, :description, :text, null: false }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.1].define(version: 2026_03_03_144409) do
|
||||
ActiveRecord::Schema[8.1].define(version: 2026_03_10_095021) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_catalog.plpgsql"
|
||||
|
||||
@@ -387,7 +387,8 @@ ActiveRecord::Schema[8.1].define(version: 2026_03_03_144409) do
|
||||
create_table "collections", id: :bigint, default: -> { "timestamp_id('collections'::text)" }, force: :cascade do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.text "description", null: false
|
||||
t.text "description"
|
||||
t.text "description_html"
|
||||
t.boolean "discoverable", null: false
|
||||
t.integer "item_count", default: 0, null: false
|
||||
t.string "language"
|
||||
|
||||
@@ -12,6 +12,8 @@ end
|
||||
Fabricator(:remote_collection, from: :collection) do
|
||||
account { Fabricate.build(:remote_account) }
|
||||
local false
|
||||
description nil
|
||||
description_html '<p>People to follow</p>'
|
||||
uri { sequence(:uri) { |i| "https://example.com/collections/#{i}" } }
|
||||
original_number_of_items 0
|
||||
end
|
||||
|
||||
@@ -23,6 +23,10 @@ RSpec.describe Collection do
|
||||
context 'when collection is remote' do
|
||||
subject { Fabricate.build :collection, local: false }
|
||||
|
||||
it { is_expected.to_not validate_presence_of(:description) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:description_html) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:uri) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:original_number_of_items) }
|
||||
|
||||
@@ -43,4 +43,13 @@ RSpec.describe REST::CollectionSerializer do
|
||||
'items' => []
|
||||
)
|
||||
end
|
||||
|
||||
context 'when the collection is remote' do
|
||||
let(:collection) { Fabricate(:remote_collection, description_html: '<p>remote</p>') }
|
||||
|
||||
it 'includes the html description' do
|
||||
expect(subject)
|
||||
.to include('description' => '<p>remote</p>')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user