FIX: only count votes when we have an array of votes

This commit is contained in:
Jeff Wong 2018-08-09 12:02:04 -07:00
parent a6b0e9753a
commit 85f39aff81
2 changed files with 12 additions and 1 deletions

View File

@ -108,7 +108,7 @@ after_initialize do
require_dependency 'user'
class ::User
def vote_count
if self.custom_fields["votes"]
if self.custom_fields["votes"] && self.custom_fields["votes"].kind_of?(Array)
user_votes = self.custom_fields["votes"].reject { |v| v.blank? }.length
else
0

View File

@ -43,4 +43,15 @@ describe DiscourseVoting do
expect(topic1.vote_count).to eq(3)
end
context "when a user has an empty string as the votes custom field" do
before do
user0.custom_fields["votes"] = ""
user0.save
end
it "returns a vote count of zero" do
expect(user0.vote_count).to eq (0)
end
end
end