discourse/spec/serializers/found_user_serializer_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
The most common thing that we do with fab! is:

    fab!(:thing) { Fabricate(:thing) }

This commit adds a shorthand for this which is just simply:

    fab!(:thing)

i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
2023-11-09 16:47:59 -06:00

30 lines
752 B
Ruby

# frozen_string_literal: true
RSpec.describe FoundUserSerializer do
fab!(: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