discourse-solved/spec/serializers/user_card_serializer_spec.rb
Natalie Tay 55c1eb4d60
DEV: Move solved custom fields into a table (#342)
Related: 
- https://github.com/discourse/discourse-solved/pull/309
- https://github.com/discourse/discourse-solved/pull/341

Requires:
- https://github.com/discourse/discourse/pull/31954

This commit converts all use of post and topic custom fields into a dedicated table:
- migration for copying custom field into table
- swap app usage of custom fields to table

This commit does not attempt to fix issues or optimise, and does not delete old data from custom fields _yet_.
2025-03-25 14:51:32 +08:00

36 lines
1.2 KiB
Ruby

# 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
expect(serializer.as_json[:accepted_answers]).to eq(0)
post1 = Fabricate(:post, user: user)
DiscourseSolved.accept_answer!(post1, Discourse.system_user)
post1.topic.reload
expect(serializer.as_json[:accepted_answers]).to eq(1)
post2 = Fabricate(:post, user: user)
DiscourseSolved.accept_answer!(post2, Discourse.system_user)
expect(serializer.as_json[:accepted_answers]).to eq(2)
post3 = Fabricate(:post, user: user)
DiscourseSolved.accept_answer!(post3, Discourse.system_user)
expect(serializer.as_json[:accepted_answers]).to eq(3)
DiscourseSolved.unaccept_answer!(post1)
expect(serializer.as_json[:accepted_answers]).to eq(2)
post2.topic.trash!(Discourse.system_user)
expect(serializer.as_json[:accepted_answers]).to eq(1)
post3.topic.convert_to_private_message(Discourse.system_user)
expect(serializer.as_json[:accepted_answers]).to eq(0)
end
end