mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 11:23:36 +08:00
6e161d3e75
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.
70 lines
2.0 KiB
Ruby
70 lines
2.0 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
describe Summarization::Base do
|
|
fab!(:user)
|
|
fab!(:group)
|
|
fab!(:topic)
|
|
|
|
let(:plugin) { Plugin::Instance.new }
|
|
|
|
before do
|
|
group.add(user)
|
|
|
|
strategy = DummyCustomSummarization.new({ summary: "dummy", chunks: [] })
|
|
plugin.register_summarization_strategy(strategy)
|
|
SiteSetting.summarization_strategy = strategy.model
|
|
end
|
|
|
|
after { DiscoursePluginRegistry.reset_register!(:summarization_strategies) }
|
|
|
|
describe "#can_see_summary?" do
|
|
context "when the user cannot generate a summary" do
|
|
before { SiteSetting.custom_summarization_allowed_groups = "" }
|
|
|
|
it "returns false" do
|
|
SiteSetting.custom_summarization_allowed_groups = ""
|
|
|
|
expect(described_class.can_see_summary?(topic, user)).to eq(false)
|
|
end
|
|
|
|
it "returns true if there is a cached summary" do
|
|
SummarySection.create!(
|
|
target: topic,
|
|
summarized_text: "test",
|
|
original_content_sha: "123",
|
|
algorithm: "test",
|
|
meta_section_id: nil,
|
|
)
|
|
|
|
expect(described_class.can_see_summary?(topic, user)).to eq(true)
|
|
end
|
|
end
|
|
|
|
context "when the user can generate a summary" do
|
|
before { SiteSetting.custom_summarization_allowed_groups = group.id }
|
|
|
|
it "returns true if the user group is present in the custom_summarization_allowed_groups_map setting" do
|
|
expect(described_class.can_see_summary?(topic, user)).to eq(true)
|
|
end
|
|
end
|
|
|
|
context "when there is no user" do
|
|
it "returns false for anons" do
|
|
expect(described_class.can_see_summary?(topic, nil)).to eq(false)
|
|
end
|
|
|
|
it "returns true for anons when there is a cached summary" do
|
|
SummarySection.create!(
|
|
target: topic,
|
|
summarized_text: "test",
|
|
original_content_sha: "123",
|
|
algorithm: "test",
|
|
meta_section_id: nil,
|
|
)
|
|
|
|
expect(described_class.can_see_summary?(topic, nil)).to eq(true)
|
|
end
|
|
end
|
|
end
|
|
end
|