Improved article date specs (#16395)

* Improved article date specs

* Say rejects
This commit is contained in:
Anna Buianova 2022-02-03 10:07:42 +03:00 committed by GitHub
parent b1c0a8d631
commit c2ce2c32d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -191,13 +191,17 @@ RSpec.describe Article, type: :model do
end
describe "dates" do
it "reject future dates" do
expect(build(:article, with_date: true, date: Date.tomorrow).valid?).to be(false)
it "rejects future dates" do
invalid_article = build(:article, with_date: true, date: Date.tomorrow.strftime("%d/%m/%Y"), published_at: nil)
expect(invalid_article.valid?).to be(false)
expect(invalid_article.errors[:date_time])
.to include("must be entered in DD/MM/YYYY format with current or past date")
end
it "reject future dates even when it's published at" do
it "rejects future dates even when it's published at" do
article.published_at = Date.tomorrow
expect(article.valid?).to be(false)
expect(article.errors[:date_time]).to include("must be entered in DD/MM/YYYY format with current or past date")
end
end