FIX: only count votes when we have an array of votes
This commit is contained in:
parent
a6b0e9753a
commit
85f39aff81
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue