docbrown/spec/services/articles/unpublish_spec.rb
Fernando Valverde b8abbda72e
Unpublish post service class + V1 API endpoint (#18031)
* Unpublish post service + API

* Apply PR feedback

* Use module_function on service class
2022-07-08 09:08:55 -06:00

24 lines
920 B
Ruby

require "rails_helper"
RSpec.describe Articles::Unpublish, type: :service do
let(:user) { create(:user) }
let(:article) { create(:article, published: true) }
let(:frontmatter) { "---\ntitle: Hellohnnnn#{rand(1000)}\npublished: true\ntags: hiring\n---\n\nHello" }
let(:frontmatter_article) { create(:article, body_markdown: frontmatter) }
before { article.update(body_markdown: Faker::Hipster.paragraph(sentence_count: 2)) }
it "unpublishes article without frontmatter" do
expect(article.has_frontmatter?).to be(false)
expect do
described_class.call(user, article)
end.to change(article, :published?).from(true).to(false)
end
it "unpublishes article with frontmatter" do
expect(frontmatter_article.has_frontmatter?).to be(true)
expect do
described_class.call(user, frontmatter_article)
end.to change(frontmatter_article, :published?).from(true).to(false)
end
end