discourse/plugins/discourse-post-voting/spec/requests/posts_controller_spec.rb
Kris 871dd2da01
FIX: update post voting for new JSON encoding (#39206)
In
5080cebb0a
the post adapter was changed to JSON which resulted in a `true ==
"true"` comparison, which is false and broke new post voting topics. The
test used the old encoding which is why it didn't fail.

This adds `.to_s` to convert to a string and updates the test to reflect
the JSON encoding.
2026-04-14 11:55:27 -05:00

62 lines
1.8 KiB
Ruby

# frozen_string_literal: true
describe PostsController do
fab!(:user) { Fabricate(:user, refresh_auto_groups: true) }
describe "#create" do
before do
sign_in(user)
SiteSetting.post_voting_enabled = true
end
it "creates a topic with the right subtype when create_as_post_voting param is provided" do
post "/posts.json",
params: {
raw: "this is some raw",
title: "this is some title",
create_as_post_voting: true,
}.to_json,
headers: {
"CONTENT_TYPE" => "application/json",
}
expect(response.status).to eq(200)
topic = Topic.last
expect(topic.is_post_voting?).to eq(true)
end
it "ignores create_as_post_voting param when trying to create private message" do
Group.refresh_automatic_groups!
post "/posts.json",
params: {
raw: "this is some raw",
title: "this is some title",
create_as_post_voting: true,
archetype: Archetype.private_message,
target_recipients: user.username,
}.to_json,
headers: {
"CONTENT_TYPE" => "application/json",
}
expect(response.status).to eq(200)
topic = Topic.last
expect(topic.is_post_voting?).to eq(false)
end
it "returns all post-voting fields" do
topic = Fabricate(:topic, subtype: Topic::POST_VOTING_SUBTYPE)
post "/posts.json", params: { raw: "this is some raw", topic_id: topic.id }
expect(response.parsed_body["post_voting_vote_count"]).to eq(0)
expect(response.parsed_body["post_voting_has_votes"]).to eq(false)
expect(response.parsed_body["comments"]).to eq([])
expect(response.parsed_body["comments_count"]).to eq(0)
end
end
end