discourse/spec/serializers/basic_group_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

99 lines
2.5 KiB
Ruby

# frozen_string_literal: true
RSpec.describe BasicGroupSerializer do
subject(:serializer) { described_class.new(group, scope: guardian, root: false) }
let(:guardian) { Guardian.new }
fab!(:group)
describe "#display_name" do
describe "automatic group" do
let(:group) { Group.find(1) }
it "should include the display name" do
expect(serializer.display_name).to eq(I18n.t("groups.default_names.admins"))
end
end
describe "normal group" do
fab!(:group)
it "should not include the display name" do
expect(serializer.display_name).to eq(nil)
end
end
end
describe "#bio_raw" do
subject(:serializer) do
described_class.new(group, scope: guardian, root: false, owner_group_ids: [group.id])
end
fab!(:group) { Fabricate(:group, bio_raw: "testing :slightly_smiling_face:") }
describe "group owner" do
it "should include bio_raw" do
expect(serializer.as_json[:bio_raw]).to eq("testing :slightly_smiling_face:")
expect(serializer.as_json[:bio_excerpt]).to start_with("testing <img")
end
end
end
describe "#has_messages" do
fab!(:group) { Fabricate(:group, has_messages: true) }
before { Group.refresh_automatic_groups! }
describe "for a staff user" do
let(:guardian) { Guardian.new(Fabricate(:moderator)) }
it "should be present" do
Group.refresh_automatic_groups!
expect(serializer.as_json[:has_messages]).to eq(true)
end
end
describe "for a group user" do
fab!(:user)
let(:guardian) { Guardian.new(user) }
before { group.add(user) }
it "should be present" do
expect(serializer.as_json[:has_messages]).to eq(true)
end
end
describe "for a normal user" do
let(:guardian) { Guardian.new(Fabricate(:user)) }
it "should not be present" do
expect(serializer.as_json[:has_messages]).to eq(nil)
end
end
end
describe "#can_see_members" do
fab!(:group) { Fabricate(:group, members_visibility_level: Group.visibility_levels[:members]) }
describe "for a group user" do
fab!(:user)
let(:guardian) { Guardian.new(user) }
before { group.add(user) }
it "should be true" do
expect(serializer.as_json[:can_see_members]).to eq(true)
end
end
describe "for a normal user" do
let(:guardian) { Guardian.new(Fabricate(:user)) }
it "should be false" do
expect(serializer.as_json[:can_see_members]).to eq(false)
end
end
end
end