2019-05-12 23:04:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-23 15:36:08 -05:00
|
|
|
require "rails_helper"
|
2019-03-17 14:13:20 -04:00
|
|
|
|
|
|
|
describe TopicAnswerMixin do
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
|
|
let(:post) { Fabricate(:post, topic: topic) }
|
2023-12-06 01:26:40 -05:00
|
|
|
let(:guardian) { Guardian.new }
|
2019-03-17 14:13:20 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
topic.custom_fields["accepted_answer_post_id"] = post.id
|
|
|
|
topic.save_custom_fields
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have true for `has_accepted_answer` field in each serializer" do
|
|
|
|
[
|
|
|
|
TopicListItemSerializer,
|
|
|
|
SearchTopicListItemSerializer,
|
|
|
|
SuggestedTopicSerializer,
|
2022-12-23 15:36:08 -05:00
|
|
|
UserSummarySerializer::TopicSerializer,
|
2019-03-17 14:13:20 -04:00
|
|
|
].each do |serializer|
|
|
|
|
json = serializer.new(topic, scope: guardian, root: false).as_json
|
|
|
|
expect(json[:has_accepted_answer]).to be_truthy
|
|
|
|
end
|
2019-03-18 11:27:29 -04:00
|
|
|
end
|
2019-03-17 14:13:20 -04:00
|
|
|
end
|