feat: H1 to H2 setting with the admin save conversion (tracer)
- content_h1_to_h2 and generic_anchors on the settings row (migration
202610280001), Headings and links tab, config key
golem15.journal.content_h1_to_h2 used when no settings row exists
- classes.ConvertH1 on the x/net/html tokenizer; the Blog Editor types
convert while the setting is on and answer editor.h1_converted
- GET /posts/{slug} reports content_h1_to_h2 (additive key)
This commit is contained in:
72
updates/settings_headings_migration_test.go
Normal file
72
updates/settings_headings_migration_test.go
Normal file
@@ -0,0 +1,72 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"git.golem15.com/golem15/summercms/modules/lagoon"
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
)
|
||||
|
||||
// TestSettingsHeadingsMigration checks the Headings and links columns:
|
||||
// content_h1_to_h2 defaults to true on the existing settings row,
|
||||
// generic_anchors is NULL, and the rollback drops both and keeps the row.
|
||||
func TestSettingsHeadingsMigration(t *testing.T) {
|
||||
sqlDB := dedicatedDB(t, fmt.Sprintf("journal_settings_headings_%d", time.Now().UnixNano()))
|
||||
gdb, err := lagoon.Use(t.Context(), sqlDB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
backend := gormigrate.New(gdb, &gormigrate.Options{
|
||||
TableName: "summer_migrations_summercms_cabana",
|
||||
UseTransaction: true,
|
||||
}, lagoon.BackendAdminMigrations)
|
||||
if err := backend.Migrate(); err != nil {
|
||||
t.Fatalf("backend_users migrations: %v", err)
|
||||
}
|
||||
m := journalMigrator(gdb)
|
||||
if err := m.Migrate(); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
assertUdt(t, gdb, "golem15_journal_settings", "content_h1_to_h2", "bool")
|
||||
assertUdt(t, gdb, "golem15_journal_settings", "generic_anchors", "text")
|
||||
var on bool
|
||||
var anchors sql.NullString
|
||||
if err := gdb.Raw(`SELECT content_h1_to_h2, generic_anchors FROM golem15_journal_settings WHERE id = 1`).Row().Scan(&on, &anchors); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !on || anchors.Valid {
|
||||
t.Fatalf("settings row: content_h1_to_h2 = %v, generic_anchors = %v, want true and NULL", on, anchors)
|
||||
}
|
||||
|
||||
const step = "202610280001_add_golem15_journal_settings_headings"
|
||||
previous := ""
|
||||
for i, mig := range All() {
|
||||
if mig.ID == step && i > 0 {
|
||||
previous = All()[i-1].ID
|
||||
}
|
||||
}
|
||||
if previous == "" {
|
||||
t.Fatalf("migration %s is not registered after another step", step)
|
||||
}
|
||||
if err := m.RollbackTo(previous); err != nil {
|
||||
t.Fatalf("rollback to %s: %v", previous, err)
|
||||
}
|
||||
for _, column := range []string{"content_h1_to_h2", "generic_anchors"} {
|
||||
if gdb.Migrator().HasColumn("golem15_journal_settings", column) {
|
||||
t.Fatalf("%s survived rollback", column)
|
||||
}
|
||||
}
|
||||
var rows int64
|
||||
if err := gdb.Raw(`SELECT COUNT(*) FROM golem15_journal_settings WHERE id = 1`).Scan(&rows).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rows != 1 {
|
||||
t.Fatalf("settings rows after rollback = %d, want 1", rows)
|
||||
}
|
||||
if err := m.Migrate(); err != nil {
|
||||
t.Fatalf("re-migrate: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user