Skip to content

Commit

Permalink
Add organisation_id to RepublishingEvents
Browse files Browse the repository at this point in the history
This will keep track of which organisation's documents are being
republished when republishing all documents by organisation
  • Loading branch information
yndajas committed Jun 13, 2024
1 parent dda1c81 commit a963292
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/republishing_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class RepublishingEvent < ApplicationRecord
validates :content_type, presence: true, if: -> { bulk_content_type == "all_by_type" }
validates :content_type, absence: true, unless: -> { bulk_content_type == "all_by_type" }

validates :organisation_id, presence: true, if: -> { bulk_content_type == "all_documents_by_organisation" }
validates :organisation_id, absence: true, unless: -> { bulk_content_type == "all_documents_by_organisation" }

enum :bulk_content_type, %i[
all_documents
all_documents_with_pre_publication_editions
Expand All @@ -18,5 +21,6 @@ class RepublishingEvent < ApplicationRecord
all_documents_with_publicly_visible_editions_with_html_attachments
all_published_organisation_about_us_pages
all_by_type
all_documents_by_organisation
]
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOrganisationIdToRepublishingEvent < ActiveRecord::Migration[7.1]
def change
add_column :republishing_events, :organisation_id, :string
end
end
3 changes: 2 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_05_104148) do
ActiveRecord::Schema[7.1].define(version: 2024_06_13_183639) 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 @@ -866,6 +866,7 @@
t.boolean "bulk", null: false
t.integer "bulk_content_type"
t.string "content_type"
t.string "organisation_id"
t.index ["user_id"], name: "index_republishing_events_on_user_id"
end

Expand Down
26 changes: 25 additions & 1 deletion test/unit/app/models/republishing_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class RepublishingEventTest < ActiveSupport::TestCase
extend Minitest::Spec::DSL

describe "content_type" do
describe "#content_type" do
context "for an `all_by_type` bulk republishing event" do
test "should be valid with a content type" do
event = build(:republishing_event, :bulk, bulk_content_type: "all_by_type", content_type: "a content type")
Expand All @@ -26,4 +26,28 @@ class RepublishingEventTest < ActiveSupport::TestCase
end
end
end

describe "#organisation_id" do
context "for an `all_documents_by_organisation` bulk republishing event" do
test "should be valid with an organisation ID" do
event = build(:republishing_event, :bulk, bulk_content_type: "all_documents_by_organisation", organisation_id: "1234")
assert event.valid?
end

test "should be invalid without a content type" do
event = build(:republishing_event, :bulk, bulk_content_type: "all_documents_by_organisation", organisation_id: nil)
assert_not event.valid?
end
end

context "for any other republishing event" do
test "must not be present" do
bulk_event = build(:republishing_event, :bulk, bulk_content_type: "all_documents", organisation_id: "1234")
assert_not bulk_event.valid?

non_bulk_event = build(:republishing_event, organisation_id: "1234")
assert_not non_bulk_event.valid?
end
end
end
end

0 comments on commit a963292

Please sign in to comment.