Fix `MigratePollsData` failing when poll-votes have duplicated options.

This commit is contained in:
Guo Xiang Tan 2018-11-21 10:52:21 +08:00
parent f4020d9134
commit 439b3fe10a
2 changed files with 6 additions and 2 deletions

View File

@ -134,7 +134,10 @@ class MigratePollsData < ActiveRecord::Migration[5.2]
options
.select { |o| option_ids.has_key?(o) }
.map { |o| "(#{poll_id}, #{option_ids[o]}, #{user_id.to_i}, '#{r.created_at}', '#{r.updated_at}')" }
end.flatten
end
poll_votes.flatten!
poll_votes.uniq!
if poll_votes.present?
execute <<~SQL

View File

@ -90,7 +90,8 @@ RSpec.describe MigratePollsData do
"1" => {
"testing" => [
"b2c3e3668a886d09e97e38b8adde7d45",
"28df49fa9e9c09d3a1eb8cfbcdcda7790",
"b2c3e3668a886d09e97e38b8adde7d45",
"28df49fa9e9c09d3a1eb8cfbcdcda7790"
]
},
"2" => {