1
0
mirror of synced 2026-08-05 09:46:57 +00:00

FIX: Correctly serialize accepted_answers (#158)

This commit is contained in:
Bianca Nenciu
2021-08-26 16:16:22 +03:00
committed by GitHub
parent e217925e13
commit f20274f44a
2 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -689,7 +689,7 @@ SQL
add_to_serializer(:user_card, :accepted_answers) do
Post
.where(user: User.find_by_username('bar3'))
.where(user_id: object.id)
.joins(:_custom_fields)
.where(_custom_fields: { name: 'is_accepted_answer', value: 'true' })
.count
@@ -0,0 +1,19 @@
# frozen_string_literal: true
require 'rails_helper'
describe UserCardSerializer do
let(:user) { Fabricate(:user) }
let(:serializer) { described_class.new(user, scope: Guardian.new, root: false) }
let(:json) { serializer.as_json }
it "accepted_answers serializes number of accepted answers" do
post = Fabricate(:post, user: user)
post.upsert_custom_fields(is_accepted_answer: 'true')
expect(serializer.as_json[:accepted_answers]).to eq(1)
post = Fabricate(:post, user: user)
post.upsert_custom_fields(is_accepted_answer: 'true')
expect(serializer.as_json[:accepted_answers]).to eq(2)
end
end