mirror of
https://github.com/discourse/discourse-data-explorer.git
synced 2025-07-10 08:03:26 +00:00
FIX: Don't add only: nil
serializing options of data explorer results (#381)
`only: nil` will cause ArraySerializer to overwrite the default Serializer settings, which will cause Topic, Post, etc. to be serialized as empty `{}`. We need to exclude the configuration without only. The current test case only ensures that no error is raised, but does not guarantee the accuracy of the result, which indirectly introduces this bug. Additional tests are added to ensure consistent results.
This commit is contained in:
parent
12a26cc821
commit
12a3fdc246
@ -198,11 +198,9 @@ module ::DiscourseDataExplorer
|
|||||||
.includes(support_info[:include])
|
.includes(support_info[:include])
|
||||||
.order(:id)
|
.order(:id)
|
||||||
|
|
||||||
ret[cls] = ActiveModel::ArraySerializer.new(
|
opts = { each_serializer: support_info[:serializer] }
|
||||||
all_objs,
|
opts[:only] = support_info[:only] if support_info[:only]
|
||||||
each_serializer: support_info[:serializer],
|
ret[cls] = ActiveModel::ArraySerializer.new(all_objs, **opts)
|
||||||
only: support_info[:only],
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
[ret, col_map]
|
[ret, col_map]
|
||||||
end
|
end
|
||||||
|
@ -100,6 +100,9 @@ describe DiscourseDataExplorer::DataExplorer do
|
|||||||
records = relations[:topic].object
|
records = relations[:topic].object
|
||||||
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
|
records.map { |t| BasicTopicSerializer.new(t, root: false).as_json }
|
||||||
}.not_to raise_error
|
}.not_to raise_error
|
||||||
|
|
||||||
|
json = relations[:topic].as_json
|
||||||
|
expect(json).to include(BasicTopicSerializer.new(topic, root: false).as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "chooses the correct serializer for tag_group" do
|
it "chooses the correct serializer for tag_group" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user