-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a minimal Content Block Edition
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
Showing
6 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
db/migrate/20240628082636_create_content_block_editions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
lib/engines/content_object_store/app/models/content_object_store/content_block_document.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 2 additions & 0 deletions
2
lib/engines/content_object_store/app/models/content_object_store/content_block_edition.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class ContentObjectStore::ContentBlockEdition < ApplicationRecord | ||
end |
7 changes: 7 additions & 0 deletions
7
lib/engines/content_object_store/test/factories/content_block_edition.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
18 changes: 18 additions & 0 deletions
18
lib/engines/content_object_store/test/unit/app/models/content_block_edition_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |