Permalink
Browse files

Batch publish now tries to publish all that it can

It will log errors for bad data/unexpected edition states, but still try to
publish everything else.
  • Loading branch information...
1 parent fb751ab commit 4d82b2cdd9f99e700d0a75be86dd76779ee0e3fc @jamiecobbett jamiecobbett committed Mar 27, 2013
Showing with 25 additions and 25 deletions.
  1. +6 −5 lib/batch_publish.rb
  2. +19 −20 test/unit/lib/batch_publish_test.rb
View
@@ -10,15 +10,16 @@ def call
slug: identifier.fetch(:slug),
version_number: identifier.fetch(:edition)
).first
- unless edition
- raise "Edition couldn't be found for #{identifier}"
- end
- unless edition.ready? || edition.published?
- raise "Edition #{identifier} isn't 'published' or 'ready'. It's #{edition.state}"
+ if edition.nil?
+ Rails.logger.error "Edition couldn't be found for #{identifier}"
+ elsif edition.ready? || edition.published?
+ Rails.logger.error "Edition #{identifier} isn't 'published' or 'ready'. It's #{edition.state}"
@alext
alext Mar 27, 2013 Member

I think the logic is inverted here.

@jamiecobbett
jamiecobbett Mar 27, 2013 Contributor

Ah yes. Curse you, unless!

end
edition
end
+ editions = editions.compact
+
editions.each do |edition|
published = user.progress(edition, { request_type: "publish", comment: "" })
if published
@@ -28,42 +28,41 @@ class BatchPublishTest < ActiveSupport::TestCase
end
context "edition doesn't exist" do
- should "fail noisily" do
+ should "still try to publish the other editions" do
+ edition = FactoryGirl.create(:edition, slug: "foo", version_number: 1, state: "ready", body: "x")
edition_identifiers = [
- { slug: "not-foo", edition: 1 }
+ { slug: "not-foo", edition: 1 },
+ { slug: "foo", edition: 1 }
]
- assert_raises RuntimeError do
- BatchPublish.new(edition_identifiers, @user.email).call
- end
+ BatchPublish.new(edition_identifiers, @user.email).call
+ assert_equal "published", edition.reload.state
end
end
context "an edition is not 'Ready' yet" do
- should "fail noisily" do
- edition = FactoryGirl.create(:edition, slug: "foo", version_number: 1, state: "draft", body: "x")
- edition.expects(:publish).never
+ should "still try to publish the other editions" do
+ draft = FactoryGirl.create(:edition, slug: "foo-draft", version_number: 1, state: "draft", body: "x")
+ ready = FactoryGirl.create(:edition, slug: "foo", version_number: 1, state: "ready", body: "x")
+ draft.expects(:publish).never
edition_identifiers = [
+ { slug: "foo-draft", edition: 1 },
{ slug: "foo", edition: 1 }
]
- assert_raises RuntimeError do
- BatchPublish.new(edition_identifiers, @user.email).call
- end
- assert_equal "draft", edition.reload.state
+ BatchPublish.new(edition_identifiers, @user.email).call
+ assert_equal "draft", draft.reload.state
+ assert_equal "published", ready.reload.state
end
end
context "one of the editions cannot be found" do
- should "not try to publish any of the editions" do
+ should "still try to publish the other editions" do
edition = FactoryGirl.create(:edition, slug: "foo", version_number: 1, state: "ready", body: "x")
- Edition.any_instance.expects(:publish).never
edition_identifiers = [
- { slug: "foo", edition: 1 },
- { slug: "not-foo", edition: 1 }
+ { slug: "not-foo", edition: 1 },
+ { slug: "foo", edition: 1 }
]
- assert_raises RuntimeError do
- BatchPublish.new(edition_identifiers, @user.email).call
- end
- assert_equal "ready", edition.reload.state
+ BatchPublish.new(edition_identifiers, @user.email).call
+ assert_equal "published", edition.reload.state
end
end
end

0 comments on commit 4d82b2c

Please sign in to comment.