mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 02:14:58 +08:00
DEV: Move about_stat_groups to DiscoursePluginRegistry (#20496)
Follow up to 098ab29d4150a5a39880d59ef6cad5f6795a18fd. Since we just used a `cattr_reader` on `About` this was not safe for multisite, since some sites could have the chat plugin enabled and some may not. Using `DiscoursePluginRegistry` gets around this issue, and makes it so the chat stats only show for a site if `chat_enabled` is true.
This commit is contained in:
@ -5,12 +5,19 @@ RSpec.describe About do
|
||||
include_examples "stats cacheable"
|
||||
end
|
||||
|
||||
describe "#stats" do
|
||||
after { About.clear_plugin_stat_groups }
|
||||
def register_about_stat_group(name, stats_block, show_in_ui: true)
|
||||
DiscoursePluginRegistry.register_about_stat_group(
|
||||
{ name: name, show_in_ui: show_in_ui, block: stats_block },
|
||||
stub(enabled?: true),
|
||||
)
|
||||
end
|
||||
|
||||
after { DiscoursePluginRegistry.reset! }
|
||||
|
||||
describe "#stats" do
|
||||
it "adds plugin stats to the output" do
|
||||
stats = { :last_day => 1, "7_days" => 10, "30_days" => 100, :count => 1000 }
|
||||
About.add_plugin_stat_group("some_group", show_in_ui: true) { stats }
|
||||
register_about_stat_group("some_group", Proc.new { stats })
|
||||
expect(described_class.new.stats.with_indifferent_access).to match(
|
||||
hash_including(
|
||||
some_group_last_day: 1,
|
||||
@ -23,7 +30,7 @@ RSpec.describe About do
|
||||
|
||||
it "does not add plugin stats to the output if they are missing one of the required keys" do
|
||||
stats = { "7_days" => 10, "30_days" => 100, :count => 1000 }
|
||||
About.add_plugin_stat_group("some_group", show_in_ui: true) { stats }
|
||||
register_about_stat_group("some_group", Proc.new { stats })
|
||||
expect(described_class.new.stats).not_to match(
|
||||
hash_including(
|
||||
some_group_last_day: 1,
|
||||
@ -36,8 +43,8 @@ RSpec.describe About do
|
||||
|
||||
it "does not error if any of the plugin stat blocks throw an error and still adds the non-errored stats to output" do
|
||||
stats = { :last_day => 1, "7_days" => 10, "30_days" => 100, :count => 1000 }
|
||||
About.add_plugin_stat_group("some_group", show_in_ui: true) { stats }
|
||||
About.add_plugin_stat_group("other_group", show_in_ui: true) { raise StandardError }
|
||||
register_about_stat_group("some_group", Proc.new { stats })
|
||||
register_about_stat_group("other_group", Proc.new { raise StandardError })
|
||||
expect(described_class.new.stats.with_indifferent_access).to match(
|
||||
hash_including(
|
||||
some_group_last_day: 1,
|
||||
@ -48,13 +55,6 @@ RSpec.describe About do
|
||||
)
|
||||
expect { described_class.new.stats.with_indifferent_access }.not_to raise_error
|
||||
end
|
||||
|
||||
it "does not allow duplicate displayed stat groups" do
|
||||
stats = { :last_day => 1, "7_days" => 10, "30_days" => 100, :count => 1000 }
|
||||
About.add_plugin_stat_group("some_group", show_in_ui: true) { stats }
|
||||
About.add_plugin_stat_group("some_group", show_in_ui: true) { stats }
|
||||
expect(described_class.displayed_plugin_stat_groups).to eq(["some_group"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#category_moderators" do
|
||||
|
Reference in New Issue
Block a user