FIX: Correctly serialize accepted_answers (#158)
This commit is contained in:
parent
e217925e13
commit
f20274f44a
|
@ -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
|
Loading…
Reference in New Issue