0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-calendar/spec/serializers/user_serializer_spec.rb
Jarek Radosz 506c233c78
DEV: Don't use fab! for non-ActiveRecord model objects (#39272)
should fix a flake or two (`fab!` was making guardian state leak between
specs)
2026-04-15 00:52:34 +02:00

36 lines
906 B
Ruby
Vendored

# frozen_string_literal: true
describe UserSerializer do
fab!(:user)
subject(:json) { described_class.new(user, scope: guardian).as_json }
before do
SiteSetting.calendar_enabled = true
user.upsert_custom_fields(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk")
end
context "as another user" do
let(:guardian) { Fabricate(:user).guardian }
it "does not return user region" do
expect(json[:user][:custom_fields]).to be_blank
end
end
context "as current user" do
let(:guardian) { user.guardian }
it "returns user region" do
expect(json[:user][:custom_fields]).to eq(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk")
end
end
context "as staff" do
let(:guardian) { Fabricate(:admin).guardian }
it "returns user region" do
expect(json[:user][:custom_fields]).to eq(DiscourseCalendar::REGION_CUSTOM_FIELD => "uk")
end
end
end