docbrown/spec/system/articles/user_edits_an_article_spec.rb
Julianna Tetreault 45b7806120
Remove Remaining logo_svg Code (#16291)
* Removes logo_svg-related code

* Removes logo_svg-related specs

* Removes the logo_uploader and logo_uploader DUS spec

* Removes the logo_uploader_spec.rb

* Adds a DUS to remove the logo_svg var from the DB

* Reverts the removal of the logo_svg_uploader.rb
2022-02-22 12:05:16 -07:00

58 lines
2.3 KiB
Ruby

require "rails_helper"
RSpec.describe "Editing with an editor", type: :system, js: true do
let(:template) { file_fixture("article_published.txt").read }
let(:user) { create(:user) }
let(:article) { create(:article, user: user, body_markdown: template) }
let(:svg_image) { file_fixture("300x100.svg").read }
before do
allow(Settings::General).to receive(:main_social_image).and_return("https://dummyimage.com/800x600.jpg")
allow(Settings::General).to receive(:logo_png).and_return("https://dummyimage.com/800x600.png")
allow(Settings::General).to receive(:mascot_image_url).and_return("https://dummyimage.com/800x600.jpg")
allow(Settings::General).to receive(:suggested_tags).and_return("coding, beginners")
allow(Settings::General).to receive(:suggested_users).and_return("romagueramica")
sign_in user
end
it "user previews their changes" do
visit "/#{user.username}/#{article.slug}/edit"
fill_in "article_body_markdown", with: template.gsub("Suspendisse", "Yooo")
click_button("Preview")
expect(page).to have_text("Yooo")
end
it "user updates their post" do
visit "/#{user.username}/#{article.slug}/edit"
fill_in "article_body_markdown", with: template.gsub("Suspendisse", "Yooo")
click_button("Save changes")
expect(page).to have_text("Yooo")
end
it "user unpublishes their post" do
visit "/#{user.username}/#{article.slug}/edit"
fill_in("article_body_markdown", with: template.gsub("true", "false"), fill_options: { clear: :backspace })
click_button("Save changes")
expect(page).to have_text("Unpublished Post.")
end
context "when user edits too many articles" do
let(:rate_limit_checker) { RateLimitChecker.new(user) }
before do
# avoid hitting new user rate limit check
allow(user).to receive(:created_at).and_return(1.week.ago)
allow(RateLimitChecker).to receive(:new).and_return(rate_limit_checker)
allow(rate_limit_checker).to receive(:limit_by_action)
.with(:article_update)
.and_return(true)
end
it "displays a rate limit warning", :flaky, js: true do
visit "/#{user.username}/#{article.slug}/edit"
fill_in "article_body_markdown", with: template.gsub("Suspendisse", "Yooo")
click_button "Save changes"
expect(page).to have_text("Rate limit reached")
end
end
end