2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-19 08:50:00 -05:00
|
|
|
require "rails_helper"
|
2017-01-26 00:29:43 -05:00
|
|
|
|
|
|
|
describe NewPostManager do
|
|
|
|
let(:user) { Fabricate(:newuser) }
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
2018-11-19 08:50:00 -05:00
|
|
|
describe "when new post containing a poll is queued for approval" do
|
2017-12-04 10:12:40 -05:00
|
|
|
before do
|
|
|
|
SiteSetting.poll_minimum_trust_level_to_create = 0
|
|
|
|
end
|
|
|
|
|
2019-08-14 14:02:59 -04:00
|
|
|
let(:params) do
|
|
|
|
{
|
2017-01-26 00:29:43 -05: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-14 14:02:59 -04:00
|
|
|
end
|
2017-01-26 00:29:43 -05:00
|
|
|
|
2019-08-14 14:02:59 -04:00
|
|
|
it "should render the poll upon approval" do
|
2019-01-03 12:03:01 -05:00
|
|
|
result = NewPostManager.new(user, params).perform
|
|
|
|
expect(result.action).to eq(:enqueued)
|
|
|
|
expect(result.reviewable).to be_present
|
2017-01-26 00:29:43 -05:00
|
|
|
|
2019-04-23 15:29:26 -04:00
|
|
|
review_result = result.reviewable.perform(admin, :approve_post)
|
2019-03-28 13:55:04 -04:00
|
|
|
expect(Poll.where(post: review_result.created_post).exists?).to eq(true)
|
2017-01-26 00:29:43 -05:00
|
|
|
end
|
2019-08-14 14:02:59 -04:00
|
|
|
|
|
|
|
it 're-validates the poll when the approve_post event is triggered' do
|
|
|
|
invalid_raw_poll = <<~RAW
|
|
|
|
[poll type=multiple min=0]
|
|
|
|
* 1
|
|
|
|
* 2
|
|
|
|
[/poll]
|
|
|
|
RAW
|
|
|
|
|
|
|
|
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 00:29:43 -05:00
|
|
|
end
|
|
|
|
end
|