Skip to content

Commit

Permalink
Create a minimal Content Block Edition
Browse files Browse the repository at this point in the history
We take the minimal fields needed to imitate an Edition.

In this case we have added
a `details` json column which we assume will contain the properties of our block,
for example `{ "email_address": "[email protected]" }`. We are using `details`
here as that's the key used in the Publishing API to publish a piece of content[1]

We are taking the approach of duplication before reuse to help us move quickly and learn where the parts we would like to reuse are.

[1] https://govuk-pact-broker-6991351eca05.herokuapp.com/pacts/provider/Publishing%20API/consumer/GDS%20API%20Adapters/latest#a_request_from_the_Whitehall_application_to_create_a_content_item_at_/test-item_given_/test-item_has_been_reserved_by_the_Publisher_application

Co-authored-by: Tom Hipkin <[email protected]>
  • Loading branch information
Harriethw and tahb committed Jun 28, 2024
1 parent 5baa8f3 commit 7d434a2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 1 deletion.
10 changes: 10 additions & 0 deletions db/migrate/20240628082636_create_content_block_editions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateContentBlockEditions < ActiveRecord::Migration[7.1]
def change
create_table :content_block_editions do |t|
t.json :details, null: false
t.references :content_block_document, index: true, foreign_key: true, null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
end
end
end
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_06_27_142613) do
ActiveRecord::Schema[7.1].define(version: 2024_06_28_082636) do
create_table "assets", charset: "utf8mb3", force: :cascade do |t|
t.string "asset_manager_id", null: false
t.string "variant", null: false
Expand Down Expand Up @@ -199,6 +199,14 @@
t.datetime "updated_at", precision: nil
end

create_table "content_block_editions", charset: "utf8mb3", force: :cascade do |t|
t.json "details", null: false
t.bigint "content_block_document_id", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["content_block_document_id"], name: "index_content_block_editions_on_content_block_document_id"
end

create_table "data_migration_records", id: :integer, charset: "utf8mb3", force: :cascade do |t|
t.string "version"
t.index ["version"], name: "index_data_migration_records_on_version", unique: true
Expand Down Expand Up @@ -1301,6 +1309,7 @@
t.datetime "updated_at", precision: nil
end

add_foreign_key "content_block_editions", "content_block_documents"
add_foreign_key "documents", "editions", column: "latest_edition_id", on_update: :cascade, on_delete: :nullify
add_foreign_key "documents", "editions", column: "live_edition_id", on_update: :cascade, on_delete: :nullify
add_foreign_key "link_checker_api_report_links", "link_checker_api_reports"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class ContentObjectStore::ContentBlockDocument < ApplicationRecord
has_many :content_block_editions,
-> { order(created_at: :asc, id: :asc) },
inverse_of: :content_block_document
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ContentObjectStore::ContentBlockEdition < ApplicationRecord
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :content_block_edition, class: "ContentObjectStore::ContentBlockEdition" do
details { "{}" }
created_at { Time.zone.now.utc }
updated_at { Time.zone.now.utc }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require "test_helper"

class ContentObjectStore::ContentBlockEditionTest < ActiveSupport::TestCase
test "content_block_edition exists with required data" do
content_block_document = create(:content_block_document)
content_block_edition = create(
:content_block_edition,
content_block_document_id: content_block_document.id,
created_at: Time.zone.local(2000, 12, 31, 23, 59, 59).utc,
updated_at: Time.zone.local(2000, 12, 31, 23, 59, 59).utc,
details: '{ "some_field": "some_content" }',
)

assert_equal Time.zone.local(2000, 12, 31, 23, 59, 59).utc, content_block_edition.created_at
assert_equal Time.zone.local(2000, 12, 31, 23, 59, 59).utc, content_block_edition.updated_at
assert_equal '{ "some_field": "some_content" }', content_block_edition.details
end
end

0 comments on commit 7d434a2

Please sign in to comment.