mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 19:01:52 +08:00
0ea5ae86ff
We call the `/u/search/users` URL when autocompleting users. It returns user's name, username and avatar template, but not user ID. We need it to return user IDs in order to display user status in certain situations. I could add ID to FoundUserWithStatusSerializer, so it will be added only if user status is enabled in site settings. But I feel that it's good to always return it, it's not a lot of data comparing to what we already return, and it should be useful in other scenarios.
30 lines
773 B
Ruby
30 lines
773 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe FoundUserSerializer do
|
|
fab!(:user) { Fabricate(:user) }
|
|
let(:serializer) { described_class.new(user, root: false) }
|
|
|
|
describe "#id" do
|
|
it "returns user id" do
|
|
json = serializer.as_json
|
|
expect(json.keys).to include :id
|
|
expect(json[:id]).to eq(user.id)
|
|
end
|
|
end
|
|
|
|
describe "#name" do
|
|
it "returns name if enabled in site settings" do
|
|
SiteSetting.enable_names = true
|
|
json = serializer.as_json
|
|
expect(json.keys).to include :name
|
|
expect(json[:name]).to eq(user.name)
|
|
end
|
|
|
|
it "doesn't return name if disabled in site settings" do
|
|
SiteSetting.enable_names = false
|
|
json = serializer.as_json
|
|
expect(json.keys).not_to include :name
|
|
end
|
|
end
|
|
end
|