mirror of
https://ghfast.top/https://github.com/discourse/discourse-topic-voting.git
synced 2026-05-28 00:44:08 +08:00
Renaming discourse_voting to topic_voting since there are two forms of voting in Discourse - posts and topics. This PR also moves a OnceOff into a post migration. The post migration will be executed, but should ideally be a no-op. This allows us to not have to maintain the OnceOff as it had to be modified before with a previous migration. I considered removing this file altogether, but I don't think there is anything negative from just converting it into a migration, and it might be useful in the unlikely scenario that a forum from the past has never ran the OnceOff before.
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "rails_helper"
|
|
|
|
describe SearchController do
|
|
fab!(:user)
|
|
|
|
fab!(:category)
|
|
|
|
fab!(:topic) { Fabricate(:topic, category: category) }
|
|
fab!(:topic_2) { Fabricate(:topic, category: category) }
|
|
|
|
fab!(:post_1) do
|
|
SearchIndexer.enable
|
|
Fabricate(:post, topic: topic, raw: "this is an awesome topic")
|
|
end
|
|
|
|
fab!(:post_2) do
|
|
SearchIndexer.enable
|
|
Fabricate(:post, topic: topic_2, raw: "this is an awesome topic")
|
|
end
|
|
|
|
before do
|
|
DiscourseTopicVoting::CategorySetting.create!(category: category)
|
|
SiteSetting.topic_voting_enabled = true
|
|
sign_in(user)
|
|
end
|
|
|
|
it "can search for posts ordered by votes" do
|
|
post "/voting/vote.json", params: { topic_id: post_2.topic_id }
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
get "/search/query.json", params: { term: "awesome order:votes" }
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
data = response.parsed_body
|
|
|
|
expect(data["posts"].length).to eq(2)
|
|
expect(data["posts"][0]["id"]).to eq(post_2.id)
|
|
expect(data["posts"][1]["id"]).to eq(post_1.id)
|
|
end
|
|
end
|