Fix removing published_at for a scheduled draft (#18682)
* Fix removing published_at for a scheduled draft * Fix Article spec
This commit is contained in:
parent
6aacf2996a
commit
2eda11d6bc
4 changed files with 14 additions and 6 deletions
|
|
@ -790,10 +790,11 @@ class Article < ApplicationRecord
|
|||
def correct_published_at?
|
||||
return unless changes["published_at"]
|
||||
|
||||
# for drafts (that were never published before) or scheduled articles => allow future or current dates
|
||||
# for drafts (that were never published before) or scheduled articles
|
||||
# => allow future or current dates, or no published_at
|
||||
if !published_at_was || published_at_was > Time.current
|
||||
# for articles published_from_feed (exported from rss) we allow past published_at
|
||||
if (!published_at || published_at < 15.minutes.ago) && !published_from_feed
|
||||
if (published_at && published_at < 15.minutes.ago) && !published_from_feed
|
||||
errors.add(:published_at, I18n.t("models.article.future_or_current_published_at"))
|
||||
end
|
||||
else
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ en:
|
|||
must_not_have_spaces: must not have spaces
|
||||
published: Published
|
||||
unique_url: has already been taken. Email %{email} for further details.
|
||||
future_or_current_published_at: only future or current published_at allowed when publishing an article
|
||||
future_or_current_published_at: only future or current published_at allowed
|
||||
|
||||
immutable_published_at: updating published_at for articles that have already been published is not allowed
|
||||
mention_too_many:
|
||||
one: You cannot mention more than %{count} users in a post!
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ fr:
|
|||
must_not_have_spaces: must not have spaces
|
||||
published: Published
|
||||
unique_url: has already been taken. Email %{email} for further details.
|
||||
future_or_current_published_at: only future or current published_at allowed when publishing an article
|
||||
future_or_current_published_at: only future or current published_at allowed
|
||||
immutable_published_at: updating published_at for articles that have already been published is not allowed
|
||||
mention_too_many:
|
||||
one: You cannot mention more than %{count} users in a post!
|
||||
|
|
|
|||
|
|
@ -514,14 +514,14 @@ RSpec.describe Article, type: :model do
|
|||
article2 = build(:article, published_at: 10.days.ago, published: true)
|
||||
expect(article2.valid?).to be false
|
||||
expect(article2.errors[:published_at])
|
||||
.to include("only future or current published_at allowed when publishing an article")
|
||||
.to include("only future or current published_at allowed")
|
||||
end
|
||||
|
||||
it "doesn't allow recent published_at when publishing on create" do
|
||||
article2 = build(:article, published_at: 1.hour.ago, published: true)
|
||||
expect(article2.valid?).to be false
|
||||
expect(article2.errors[:published_at])
|
||||
.to include("only future or current published_at allowed when publishing an article")
|
||||
.to include("only future or current published_at allowed")
|
||||
end
|
||||
|
||||
it "allows recent published_at when publishing on create" do
|
||||
|
|
@ -529,6 +529,12 @@ RSpec.describe Article, type: :model do
|
|||
expect(article2.valid?).to be true
|
||||
end
|
||||
|
||||
it "allows removing published_at when updating a scheduled draft" do
|
||||
scheduled_draft = create(:article, published: false, published_at: 1.day.from_now)
|
||||
scheduled_draft.published_at = nil
|
||||
expect(scheduled_draft).to be_valid
|
||||
end
|
||||
|
||||
context "when unpublishing" do
|
||||
let!(:published_at_was) { article.published_at }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue