Skip to content

Commit

Permalink
fixup! Add republish_all_documents_by_organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
yndajas committed Jun 14, 2024
1 parent a963292 commit cca0972
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
5 changes: 2 additions & 3 deletions app/services/bulk_republisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ def republish_all_documents_with_publicly_visible_editions_with_html_attachments
republish_by_document_ids(document_ids)
end

def republish_all_documents_by_organisation(organisation_slug)
organisation = Organisation.find_by(slug: organisation_slug)
raise "Organisation with slug #{organisation_slug} not found" unless organisation
def republish_all_documents_by_organisation(organisation)
raise "Argument must be an organisation" unless organisation.is_a?(Organisation)

document_ids = Edition
.latest_edition
Expand Down
14 changes: 7 additions & 7 deletions test/unit/app/services/bulk_republisher_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class BulkRepublisherTest < ActiveSupport::TestCase
end

describe "#republish_all_documents_by_organisation" do
context "for an existing organisation" do
context "with a given organisation" do
test "republishes each of the organistion's documents" do
organisation = create(:organisation)
documents = create_list(:document, 3)
Expand All @@ -216,7 +216,7 @@ class BulkRepublisherTest < ActiveSupport::TestCase
.with("bulk_republishing", document.id, true)
end

BulkRepublisher.new.republish_all_documents_by_organisation(organisation.slug)
BulkRepublisher.new.republish_all_documents_by_organisation(organisation)
end

test "doesn't republish editions for other organisations" do
Expand All @@ -233,16 +233,16 @@ class BulkRepublisherTest < ActiveSupport::TestCase
.never
end

BulkRepublisher.new.republish_all_documents_by_organisation(organisation.slug)
BulkRepublisher.new.republish_all_documents_by_organisation(organisation)
end
end

context "for a non-existent organisation" do
context "when the organisation argument is not an organisation" do
test "raises an error" do
unknown_organisation_slug = "unknown-organisation-slug"
edition = create(:edition)

assert_raises(StandardError, match: "Organisation with slug #{unknown_organisation_slug} not found") do
BulkRepublisher.new.republish_all_documents_by_organisation(unknown_organisation_slug)
assert_raises(StandardError, match: "Argument must be an organisation") do
BulkRepublisher.new.republish_all_documents_by_organisation(edition)
end
end
end
Expand Down

0 comments on commit cca0972

Please sign in to comment.