mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
REFACTOR: use tables instead of custom fields for polls (#6359)
Co-authored-by: Guo Xiang Tan <tgx_world@hotmail.com>
This commit is contained in:
@ -4,12 +4,14 @@ describe "DiscoursePoll endpoints" do
|
||||
describe "fetch voters for a poll" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:post) { Fabricate(:post, raw: "[poll public=true]\n- A\n- B\n[/poll]") }
|
||||
let(:option_a) { "5c24fc1df56d764b550ceae1b9319125" }
|
||||
let(:option_b) { "e89dec30bbd9bf50fabf6a05b4324edf" }
|
||||
|
||||
it "should return the right response" do
|
||||
DiscoursePoll::Poll.vote(
|
||||
post.id,
|
||||
DiscoursePoll::DEFAULT_POLL_NAME,
|
||||
["5c24fc1df56d764b550ceae1b9319125"],
|
||||
[option_a],
|
||||
user
|
||||
)
|
||||
|
||||
@ -20,8 +22,8 @@ describe "DiscoursePoll endpoints" do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
poll = JSON.parse(response.body)[DiscoursePoll::DEFAULT_POLL_NAME]
|
||||
option = poll["5c24fc1df56d764b550ceae1b9319125"]
|
||||
poll = JSON.parse(response.body)["voters"]
|
||||
option = poll[option_a]
|
||||
|
||||
expect(option.length).to eq(1)
|
||||
expect(option.first["id"]).to eq(user.id)
|
||||
@ -32,23 +34,23 @@ describe "DiscoursePoll endpoints" do
|
||||
DiscoursePoll::Poll.vote(
|
||||
post.id,
|
||||
DiscoursePoll::DEFAULT_POLL_NAME,
|
||||
["5c24fc1df56d764b550ceae1b9319125", "e89dec30bbd9bf50fabf6a05b4324edf"],
|
||||
[option_a, option_b],
|
||||
user
|
||||
)
|
||||
|
||||
get "/polls/voters.json", params: {
|
||||
post_id: post.id,
|
||||
poll_name: DiscoursePoll::DEFAULT_POLL_NAME,
|
||||
option_id: 'e89dec30bbd9bf50fabf6a05b4324edf'
|
||||
option_id: option_b
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
poll = JSON.parse(response.body)[DiscoursePoll::DEFAULT_POLL_NAME]
|
||||
poll = JSON.parse(response.body)["voters"]
|
||||
|
||||
expect(poll['5c24fc1df56d764b550ceae1b9319125']).to eq(nil)
|
||||
expect(poll[option_a]).to eq(nil)
|
||||
|
||||
option = poll['e89dec30bbd9bf50fabf6a05b4324edf']
|
||||
option = poll[option_b]
|
||||
|
||||
expect(option.length).to eq(1)
|
||||
expect(option.first["id"]).to eq(user.id)
|
||||
@ -68,7 +70,7 @@ describe "DiscoursePoll endpoints" do
|
||||
post_id: -1,
|
||||
poll_name: DiscoursePoll::DEFAULT_POLL_NAME
|
||||
}
|
||||
expect(response.status).to eq(400)
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.body).to include('post_id is invalid')
|
||||
end
|
||||
end
|
||||
@ -83,7 +85,7 @@ describe "DiscoursePoll endpoints" do
|
||||
describe 'when poll_name is not valid' do
|
||||
it 'should raise the right error' do
|
||||
get "/polls/voters.json", params: { post_id: post.id, poll_name: 'wrongpoll' }
|
||||
expect(response.status).to eq(400)
|
||||
expect(response.status).to eq(422)
|
||||
expect(response.body).to include('poll_name is invalid')
|
||||
end
|
||||
end
|
||||
@ -108,7 +110,7 @@ describe "DiscoursePoll endpoints" do
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
poll = JSON.parse(response.body)[DiscoursePoll::DEFAULT_POLL_NAME]
|
||||
poll = JSON.parse(response.body)["voters"]
|
||||
|
||||
expect(poll.first["id"]).to eq(user.id)
|
||||
expect(poll.first["username"]).to eq(user.username)
|
||||
|
Reference in New Issue
Block a user