docbrown/spec/system/articles/user_fixes_a_draft_spec.rb
Michael Kohl 6afaa25f50
Fix accidental publishing of draft articles (#12288)
* Fix accidental publishing of draft articles

* Add regression spec

* Fix spec
2021-01-22 08:47:16 +07:00

38 lines
1.4 KiB
Ruby

require "rails_helper"
# Regression test for https://github.com/forem/forem/issues/12131
RSpec.describe "", type: :system do
let(:correct_liquid_tag) do
"{% codepen https://codepen.io/user/pen/abcdefg default-tab=result %}"
end
let(:incorrect_liquid_tag) do
'{% codepen https://codepen.io/user/pen/abcdefg default-tab="result" %}'
end
it "let's the user fix a broken draft without publishing", js: true, aggregate_failures: true do
# Create a new blog post and add content that validates correctly
sign_in create(:user, editor_version: "v2")
visit new_path
fill_in "article-form-title", with: "Regression spec"
fill_in "article_body_markdown", with: correct_liquid_tag
# Save the draft
click_button "Save draft"
expect(page).to have_content("Unpublished Post")
# Edit the blog post with content that doesn't pass validations
click_link("Click to edit")
fill_in "article_body_markdown", with: incorrect_liquid_tag
# Try to save the draft, there should still be both "Publish" and "Save Draft" buttons
click_button "Save draft"
expect(page).to have_content("Whoops, something went wrong")
expect(page).to have_selector(:link_or_button, "Publish")
expect(page).to have_selector(:link_or_button, "Save ")
# Fix the error
fill_in "article_body_markdown", with: correct_liquid_tag
click_button "Save draft"
expect(page).to have_content("Unpublished Post")
end
end