mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 12:24:38 +08:00
80449d39d3
Because of caching, whenever flags are created, they have to be destroyed to not modify the state.
65 lines
2.3 KiB
Ruby
65 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe FlagSerializer do
|
|
let(:flag) { Flag.find_by(name: "illegal") }
|
|
|
|
context "when system flag" do
|
|
it "returns translated name" do
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:name]).to eq(I18n.t("post_action_types.illegal.title"))
|
|
end
|
|
|
|
it "returns translated description" do
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:description]).to eq(I18n.t("post_action_types.illegal.description"))
|
|
end
|
|
end
|
|
|
|
context "when custom flag" do
|
|
it "returns translated name and description" do
|
|
flag = Fabricate(:flag, name: "custom title", description: "custom description")
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:name]).to eq("custom title")
|
|
expect(serialized[:flag][:description]).to eq("custom description")
|
|
flag.destroy!
|
|
end
|
|
end
|
|
|
|
it "returns is_flag true for flags" do
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:is_flag]).to be true
|
|
end
|
|
|
|
it "returns is_flag false for like" do
|
|
flag = Flag.unscoped.find_by(name: "like")
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:is_flag]).to be false
|
|
end
|
|
|
|
it "returns is_used false when not used" do
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:is_used]).to be false
|
|
end
|
|
|
|
it "returns is_used true when used" do
|
|
serialized = described_class.new(flag, used_flag_ids: [flag.id]).as_json
|
|
expect(serialized[:flag][:is_used]).to be true
|
|
end
|
|
|
|
it "returns applies_to" do
|
|
serialized = described_class.new(flag, used_flag_ids: []).as_json
|
|
expect(serialized[:flag][:applies_to]).to eq(%w[Post Topic Chat::Message])
|
|
end
|
|
|
|
describe "#description" do
|
|
let(:serializer) { described_class.new(flag, scope: Guardian.new, root: false) }
|
|
let(:flag) { Flag.find_by(name_key: :inappropriate) }
|
|
|
|
before { allow(Discourse).to receive(:base_path).and_return("discourse.org") }
|
|
|
|
it "returns properly interpolated translation" do
|
|
expect(serializer.description).to match(%r{discourse\.org/guidelines})
|
|
end
|
|
end
|
|
end
|