2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-19 21:50:00 +08:00
|
|
|
require "rails_helper"
|
2017-01-26 13:29:43 +08:00
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe NewPostManager do
|
2017-01-26 13:29:43 +08:00
|
|
|
let(:user) { Fabricate(:newuser) }
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
2018-11-19 21:50:00 +08:00
|
|
|
describe "when new post containing a poll is queued for approval" do
|
2017-12-04 23:12:40 +08:00
|
|
|
before { SiteSetting.poll_minimum_trust_level_to_create = 0 }
|
|
|
|
|
2019-08-15 02:02:59 +08:00
|
|
|
let(:params) do
|
|
|
|
{
|
2017-01-26 13:29:43 +08:00
|
|
|
raw: "[poll]\n* 1\n* 2\n* 3\n[/poll]",
|
|
|
|
archetype: "regular",
|
|
|
|
category: "",
|
|
|
|
typing_duration_msecs: "2700",
|
|
|
|
composer_open_duration_msecs: "12556",
|
|
|
|
visible: true,
|
|
|
|
image_sizes: nil,
|
|
|
|
is_warning: false,
|
|
|
|
title: "This is a test post with a poll",
|
|
|
|
ip_address: "127.0.0.1",
|
|
|
|
user_agent:
|
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36",
|
|
|
|
referrer: "http://localhost:3000/",
|
|
|
|
first_post_checks: true,
|
|
|
|
}
|
2019-08-15 02:02:59 +08:00
|
|
|
end
|
2017-01-26 13:29:43 +08:00
|
|
|
|
2019-08-15 02:02:59 +08:00
|
|
|
it "should render the poll upon approval" do
|
2019-01-04 01:03:01 +08:00
|
|
|
result = NewPostManager.new(user, params).perform
|
|
|
|
expect(result.action).to eq(:enqueued)
|
|
|
|
expect(result.reviewable).to be_present
|
2017-01-26 13:29:43 +08:00
|
|
|
|
2019-04-24 03:29:26 +08:00
|
|
|
review_result = result.reviewable.perform(admin, :approve_post)
|
2019-03-29 01:55:04 +08:00
|
|
|
expect(Poll.where(post: review_result.created_post).exists?).to eq(true)
|
2017-01-26 13:29:43 +08:00
|
|
|
end
|
2019-08-15 02:02:59 +08:00
|
|
|
|
|
|
|
it "re-validates the poll when the approve_post event is triggered" do
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
invalid_raw_poll = <<~MD
|
2019-08-15 02:02:59 +08:00
|
|
|
[poll type=multiple min=0]
|
|
|
|
* 1
|
|
|
|
* 2
|
|
|
|
[/poll]
|
DEV: Correctly tag heredocs (#16061)
This allows text editors to use correct syntax coloring for the heredoc sections.
Heredoc tag names we use:
languages: SQL, JS, RUBY, LUA, HTML, CSS, SCSS, SH, HBS, XML, YAML/YML, MF, ICS
other: MD, TEXT/TXT, RAW, EMAIL
2022-03-01 03:50:55 +08:00
|
|
|
MD
|
2019-08-15 02:02:59 +08:00
|
|
|
|
|
|
|
result = NewPostManager.new(user, params).perform
|
|
|
|
|
|
|
|
reviewable = result.reviewable
|
|
|
|
reviewable.payload["raw"] = invalid_raw_poll
|
|
|
|
reviewable.save!
|
|
|
|
|
|
|
|
review_result = result.reviewable.perform(admin, :approve_post)
|
|
|
|
expect(Poll.where(post: review_result.created_post).exists?).to eq(false)
|
|
|
|
end
|
2017-01-26 13:29:43 +08:00
|
|
|
end
|
|
|
|
end
|