Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

FIX: Add new attribute that is required when using the basic topic serializer #375

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/discourse_data_explorer/data_explorer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def self.extra_data_pluck_fields
},
topic: {
class: Topic,
fields: %i[id title slug posts_count],
fields: %i[id title slug posts_count locale],
serializer: BasicTopicSerializer,
},
group: {
Expand Down
15 changes: 15 additions & 0 deletions spec/data_explorer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@
_, colrender = DiscourseDataExplorer::DataExplorer.add_extra_data(result[:pg_result])
expect(colrender).to eq({ 1 => "json" })
end

describe "serializing models to serializer" do
it "serializes correctly to BasicTopicSerializer for topic relations" do
topic = Fabricate(:topic, locale: "ja")
query = Fabricate(:query, sql: "SELECT id AS topic_id FROM topics WHERE id = #{topic.id}")

pg_result = described_class.run_query(query)[:pg_result]
relations, _ = DiscourseDataExplorer::DataExplorer.add_extra_data(pg_result)

expect {
records = relations[:topic].object
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
}.not_to raise_error
end
end
end
end
end