mirror of
https://github.com/discourse/discourse.git
synced 2026-03-03 23:54:20 +08:00
Currently in several endpoints, we return an array of strings for tags.
Our goal with this PR is to expand array tag name strings to an array of
tag objects.
#### before: Tags were returned as string arrays
```
{ "tags": ["support", "bug-report"] }
```
#### after: Tags are returned as object arrays
```
{ "tags": [{"id": 12, "name": "support", "slug": "support"}, {"id": 13, "name": "bug-report", "slug": "bug-report"}] }
```
This allows us to start referencing tags by their ids, and return more
information for a tag for future features.
This commit involves updating several areas:
- topic lists (/latest.json, /top.json, /c/:category/:id.json, etc, for
`top_tags`)
- tag chooser components (`MiniTagChooser`, `TagDrop`, etc)
- topic view (/t/:id.json)
- tag groups (/tag_groups.json, tags, parent_tag)
- category settings
- staff action logs
- synonyms
- ...
APIs that reference tags based on their names will still be supported
with a deprecation warning. Moving on, we will reference them using
their tag ids.
36 lines
1.3 KiB
Ruby
36 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe TopicTrackingStateItemSerializer do
|
|
fab!(:user)
|
|
fab!(:post) { create_post }
|
|
|
|
it "serializes topic tracking state reports" do
|
|
report = TopicTrackingState.report(user)
|
|
serialized = described_class.new(report[0], scope: Guardian.new(user), root: false).as_json
|
|
|
|
expect(serialized[:topic_id]).to eq(post.topic_id)
|
|
expect(serialized[:highest_post_number]).to eq(post.topic.highest_post_number)
|
|
expect(serialized[:last_read_post_number]).to eq(nil)
|
|
expect(serialized[:created_at]).to be_present
|
|
expect(serialized[:notification_level]).to eq(nil)
|
|
expect(serialized[:created_in_new_period]).to eq(true)
|
|
expect(serialized[:treat_as_new_topic_start_date]).to be_present
|
|
end
|
|
|
|
it "includes tags attribute when `tagging_enabled` site setting is `true`" do
|
|
SiteSetting.tagging_enabled = true
|
|
|
|
post.topic.notifier.watch_topic!(post.topic.user_id)
|
|
|
|
DiscourseTagging.tag_topic_by_names(
|
|
post.topic,
|
|
Guardian.new(Discourse.system_user),
|
|
%w[bananas apples],
|
|
)
|
|
|
|
report = TopicTrackingState.report(user)
|
|
serialized = described_class.new(report[0], scope: Guardian.new(user), root: false).as_json
|
|
|
|
expect(serialized[:tags].map { |t| t["name"] }).to contain_exactly("bananas", "apples")
|
|
end
|
|
end
|