mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 19:13:40 +08:00
2987901043
#b19dcac2 improved the serializer so it sends default notification
levels to users to work around cases where a category edit would
would result in clients being left with invalid notification state
Unfortunately this did not address the root issue.
When we edit categories we publish state to multiple users this
means that the serializer is executed unscoped with no user.
The client already handles this case per:
dcad720a4c/app/assets/javascripts/discourse/app/models/site.js (L119-L119)
If a property is not shipped to it, it will leave it alone on the
existing category.
This fix ensures that these wide category info updates do not
include notification state to avoid corruption of local state.
47 lines
1.7 KiB
Ruby
47 lines
1.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe CategorySerializer do
|
|
fab!(:group) { Fabricate(:group) }
|
|
fab!(:category) { Fabricate(:category, reviewable_by_group_id: group.id) }
|
|
|
|
it "includes the reviewable by group name if enabled" do
|
|
SiteSetting.enable_category_group_review = true
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
expect(json[:reviewable_by_group_name]).to eq(group.name)
|
|
end
|
|
|
|
it "doesn't include the reviewable by group name if disabled" do
|
|
SiteSetting.enable_category_group_review = false
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
expect(json[:reviewable_by_group_name]).to be_blank
|
|
end
|
|
|
|
it "includes custom fields" do
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
expect(json[:custom_fields]).to be_empty
|
|
|
|
category.custom_fields["enable_marketplace"] = true
|
|
category.save_custom_fields
|
|
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
expect(json[:custom_fields]).to be_present
|
|
end
|
|
|
|
it "does not include the default notification level when there is no user" do
|
|
json = described_class.new(category, scope: Guardian.new, root: false).as_json
|
|
expect(json.key?(:notification_level)).to eq(false)
|
|
end
|
|
|
|
describe "user notification level" do
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
it "includes the user's notification level" do
|
|
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching], category.id)
|
|
json = described_class.new(category, scope: Guardian.new(user), root: false).as_json
|
|
expect(json[:notification_level]).to eq(NotificationLevels.all[:watching])
|
|
end
|
|
end
|
|
end
|