mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Shorten a condition (#25951)
This commit is contained in:
parent
5f119c57e8
commit
ef292d1fed
@ -131,13 +131,10 @@ module DiscoursePoll
|
|||||||
return true if old_poll.public_send(attr) != new_poll.public_send(attr)
|
return true if old_poll.public_send(attr) != new_poll.public_send(attr)
|
||||||
end
|
end
|
||||||
|
|
||||||
# an option was changed?
|
sorted_old_options = old_poll.poll_options.map { |o| o.digest }.sort
|
||||||
if old_poll.poll_options.map { |o| o.digest }.sort != new_options.map { |o| o["id"] }.sort
|
sorted_new_options = new_options.map { |o| o["id"] }.sort
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
# it's the same!
|
sorted_old_options != sorted_new_options
|
||||||
false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -206,7 +206,25 @@ RSpec.describe PostsController do
|
|||||||
expect(json["post"]["polls"][0]["options"][2]["html"]).to eq("C")
|
expect(json["post"]["polls"][0]["options"][2]["html"]).to eq("C")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "resets the votes" do
|
it "does not clear votes when poll has no change" do
|
||||||
|
DiscoursePoll::Poll.vote(user, post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"])
|
||||||
|
put :update,
|
||||||
|
params: {
|
||||||
|
id: post_id,
|
||||||
|
post: {
|
||||||
|
raw: "[poll]\n- A\n- B\n[/poll]\n This poll has no change, but the raw does.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
format: :json
|
||||||
|
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
json = response.parsed_body
|
||||||
|
expect(json["post"]["polls_votes"]["poll"]).to match_array(
|
||||||
|
"5c24fc1df56d764b550ceae1b9319125",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "resets the votes when poll is changed" do
|
||||||
DiscoursePoll::Poll.vote(user, post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"])
|
DiscoursePoll::Poll.vote(user, post_id, "poll", ["5c24fc1df56d764b550ceae1b9319125"])
|
||||||
|
|
||||||
put :update,
|
put :update,
|
||||||
|
Loading…
Reference in New Issue
Block a user