FEATURE: Allow users to remove their vote (#14459)

They can use the remove vote button or select the same option again for
single choice polls.

This commit refactor the plugin to properly organize code and make it
easier to follow.
This commit is contained in:
Bianca Nenciu
2021-10-05 11:38:49 +03:00
committed by GitHub
parent 12856ab8c2
commit 6a143030f8
13 changed files with 550 additions and 521 deletions

View File

@ -11,10 +11,10 @@ describe "DiscoursePoll endpoints" do
it "should return the right response" do
DiscoursePoll::Poll.vote(
user,
post.id,
DiscoursePoll::DEFAULT_POLL_NAME,
[option_a],
user
[option_a]
)
get "/polls/voters.json", params: {
@ -34,10 +34,10 @@ describe "DiscoursePoll endpoints" do
it 'should return the right response for a single option' do
DiscoursePoll::Poll.vote(
user,
post.id,
DiscoursePoll::DEFAULT_POLL_NAME,
[option_a, option_b],
user
[option_a, option_b]
)
get "/polls/voters.json", params: {
@ -72,7 +72,7 @@ describe "DiscoursePoll endpoints" do
post_id: -1,
poll_name: DiscoursePoll::DEFAULT_POLL_NAME
}
expect(response.status).to eq(422)
expect(response.status).to eq(400)
expect(response.body).to include('post_id')
end
end
@ -87,7 +87,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(422)
expect(response.status).to eq(400)
expect(response.body).to include('poll_name')
end
end
@ -99,10 +99,10 @@ describe "DiscoursePoll endpoints" do
post
DiscoursePoll::Poll.vote(
user,
post.id,
DiscoursePoll::DEFAULT_POLL_NAME,
["4d8a15e3cc35750f016ce15a43937620"],
user
["4d8a15e3cc35750f016ce15a43937620"]
)
get "/polls/voters.json", params: {
@ -137,20 +137,20 @@ describe "DiscoursePoll endpoints" do
}
[user1, user2, user3].each_with_index do |user, index|
DiscoursePoll::Poll.vote(
user,
post.id,
DiscoursePoll::DEFAULT_POLL_NAME,
[user_votes["user_#{index}".to_sym]],
user
[user_votes["user_#{index}".to_sym]]
)
UserCustomField.create(user_id: user.id, name: "something", value: "value#{index}")
end
# Add another user to one of the fields to prove it groups users properly
DiscoursePoll::Poll.vote(
user4,
post.id,
DiscoursePoll::DEFAULT_POLL_NAME,
[option_a, option_b],
user4
[option_a, option_b]
)
UserCustomField.create(user_id: user4.id, name: "something", value: "value1")
end
@ -182,7 +182,7 @@ describe "DiscoursePoll endpoints" do
user_field_name: "something"
}
expect(response.status).to eq(422)
expect(response.status).to eq(400)
expect(response.body).to include('user_field_name')
end
end