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?
|
def correct_published_at?
|
||||||
return unless changes["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
|
if !published_at_was || published_at_was > Time.current
|
||||||
# for articles published_from_feed (exported from rss) we allow past published_at
|
# 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"))
|
errors.add(:published_at, I18n.t("models.article.future_or_current_published_at"))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ en:
|
||||||
must_not_have_spaces: must not have spaces
|
must_not_have_spaces: must not have spaces
|
||||||
published: Published
|
published: Published
|
||||||
unique_url: has already been taken. Email %{email} for further details.
|
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
|
immutable_published_at: updating published_at for articles that have already been published is not allowed
|
||||||
mention_too_many:
|
mention_too_many:
|
||||||
one: You cannot mention more than %{count} users in a post!
|
one: You cannot mention more than %{count} users in a post!
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ fr:
|
||||||
must_not_have_spaces: must not have spaces
|
must_not_have_spaces: must not have spaces
|
||||||
published: Published
|
published: Published
|
||||||
unique_url: has already been taken. Email %{email} for further details.
|
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
|
immutable_published_at: updating published_at for articles that have already been published is not allowed
|
||||||
mention_too_many:
|
mention_too_many:
|
||||||
one: You cannot mention more than %{count} users in a post!
|
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)
|
article2 = build(:article, published_at: 10.days.ago, published: true)
|
||||||
expect(article2.valid?).to be false
|
expect(article2.valid?).to be false
|
||||||
expect(article2.errors[:published_at])
|
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
|
end
|
||||||
|
|
||||||
it "doesn't allow recent published_at when publishing on create" do
|
it "doesn't allow recent published_at when publishing on create" do
|
||||||
article2 = build(:article, published_at: 1.hour.ago, published: true)
|
article2 = build(:article, published_at: 1.hour.ago, published: true)
|
||||||
expect(article2.valid?).to be false
|
expect(article2.valid?).to be false
|
||||||
expect(article2.errors[:published_at])
|
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
|
end
|
||||||
|
|
||||||
it "allows recent published_at when publishing on create" do
|
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
|
expect(article2.valid?).to be true
|
||||||
end
|
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
|
context "when unpublishing" do
|
||||||
let!(:published_at_was) { article.published_at }
|
let!(:published_at_was) { article.published_at }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue