2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2013-02-06 03:16:51 +08:00
|
|
|
require 'discourse_plugin_registry'
|
|
|
|
|
|
|
|
describe DiscoursePluginRegistry do
|
|
|
|
|
2014-04-01 13:08:18 +08:00
|
|
|
class TestRegistry < DiscoursePluginRegistry; end
|
|
|
|
|
|
|
|
let(:registry) { TestRegistry }
|
|
|
|
let(:registry_instance) { registry.new }
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-08 15:56:12 +08:00
|
|
|
context '#stylesheets' do
|
|
|
|
it 'defaults to an empty Set' do
|
2014-04-01 13:08:18 +08:00
|
|
|
registry.stylesheets = nil
|
2019-08-21 00:39:52 +08:00
|
|
|
expect(registry.stylesheets).to eq(Hash.new)
|
2013-02-08 15:56:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
context '#mobile_stylesheets' do
|
|
|
|
it 'defaults to an empty Set' do
|
|
|
|
registry.mobile_stylesheets = nil
|
2019-08-21 00:39:52 +08:00
|
|
|
expect(registry.mobile_stylesheets).to eq(Hash.new)
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-08 15:56:12 +08:00
|
|
|
context '#javascripts' do
|
|
|
|
it 'defaults to an empty Set' do
|
2014-04-01 13:08:18 +08:00
|
|
|
registry.javascripts = nil
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.javascripts).to eq(Set.new)
|
2013-02-08 15:56:12 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-23 23:51:57 +08:00
|
|
|
context '#auth_providers' do
|
|
|
|
it 'defaults to an empty Set' do
|
|
|
|
registry.auth_providers = nil
|
|
|
|
expect(registry.auth_providers).to eq(Set.new)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-17 20:19:08 +08:00
|
|
|
context '#admin_javascripts' do
|
|
|
|
it 'defaults to an empty Set' do
|
2014-04-01 13:08:18 +08:00
|
|
|
registry.admin_javascripts = nil
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.admin_javascripts).to eq(Set.new)
|
2013-02-08 15:56:12 +08:00
|
|
|
end
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2015-06-05 03:56:17 +08:00
|
|
|
context '#seed_data' do
|
|
|
|
it 'defaults to an empty Set' do
|
|
|
|
registry.seed_data = nil
|
|
|
|
expect(registry.seed_data).to be_a(Hash)
|
|
|
|
expect(registry.seed_data.size).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-18 03:47:21 +08:00
|
|
|
context '.register_html_builder' do
|
|
|
|
it "can register and build html" do
|
|
|
|
DiscoursePluginRegistry.register_html_builder(:my_html) { "<b>my html</b>" }
|
|
|
|
expect(DiscoursePluginRegistry.build_html(:my_html)).to eq('<b>my html</b>')
|
|
|
|
DiscoursePluginRegistry.reset!
|
|
|
|
expect(DiscoursePluginRegistry.build_html(:my_html)).to be_blank
|
|
|
|
end
|
2017-11-03 23:32:32 +08:00
|
|
|
|
|
|
|
it "can register multiple builders" do
|
|
|
|
DiscoursePluginRegistry.register_html_builder(:my_html) { "one" }
|
|
|
|
DiscoursePluginRegistry.register_html_builder(:my_html) { "two" }
|
|
|
|
expect(DiscoursePluginRegistry.build_html(:my_html)).to eq("one\ntwo")
|
|
|
|
DiscoursePluginRegistry.reset!
|
|
|
|
end
|
2017-04-18 03:47:21 +08:00
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
context '.register_css' do
|
2019-08-21 00:39:52 +08:00
|
|
|
let(:plugin_directory_name) { "hello" }
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
before do
|
2019-08-21 00:39:52 +08:00
|
|
|
registry_instance.register_css('hello.css', plugin_directory_name)
|
2014-04-01 13:08:18 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not leaking' do
|
2019-08-21 00:39:52 +08:00
|
|
|
expect(DiscoursePluginRegistry.new.stylesheets[plugin_directory_name]).to be_nil
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is returned by DiscoursePluginRegistry.stylesheets' do
|
2019-08-21 00:39:52 +08:00
|
|
|
expect(registry_instance.stylesheets[plugin_directory_name].include?('hello.css')).to eq(true)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't add the same file twice" do
|
2019-08-21 00:39:52 +08:00
|
|
|
expect { registry_instance.register_css('hello.css', plugin_directory_name) }.not_to change(registry.stylesheets[plugin_directory_name], :size)
|
2013-02-26 00:42:20 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context '.register_js' do
|
|
|
|
before do
|
2014-04-01 13:08:18 +08:00
|
|
|
registry_instance.register_js('hello.js')
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is returned by DiscoursePluginRegistry.javascripts' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry_instance.javascripts.include?('hello.js')).to eq(true)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "won't add the same file twice" do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect { registry_instance.register_js('hello.js') }.not_to change(registry.javascripts, :size)
|
2013-02-26 00:42:20 +08:00
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2018-07-23 23:51:57 +08:00
|
|
|
context '.register_auth_provider' do
|
|
|
|
let(:registry) { DiscoursePluginRegistry }
|
|
|
|
let(:auth_provider) do
|
2018-07-31 23:18:50 +08:00
|
|
|
provider = Auth::AuthProvider.new
|
2018-07-23 23:51:57 +08:00
|
|
|
provider.authenticator = Auth::Authenticator.new
|
|
|
|
provider
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
registry.register_auth_provider(auth_provider)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
registry.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is returned by DiscoursePluginRegistry.auth_providers' do
|
|
|
|
expect(registry.auth_providers.include?(auth_provider)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-11-23 09:02:01 +08:00
|
|
|
context '.register_service_worker' do
|
|
|
|
let(:registry) { DiscoursePluginRegistry }
|
|
|
|
|
|
|
|
before do
|
|
|
|
registry.register_service_worker('hello.js')
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
registry.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should register the file once" do
|
|
|
|
2.times { registry.register_service_worker('hello.js') }
|
|
|
|
|
|
|
|
expect(registry.service_workers.size).to eq(1)
|
|
|
|
expect(registry.service_workers).to include('hello.js')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
context '.register_archetype' do
|
|
|
|
it "delegates archetypes to the Archetype component" do
|
|
|
|
Archetype.expects(:register).with('threaded', hello: 123)
|
2014-04-01 13:08:18 +08:00
|
|
|
registry_instance.register_archetype('threaded', hello: 123)
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-10 03:20:53 +08:00
|
|
|
context '#register_asset' do
|
|
|
|
let(:registry) { DiscoursePluginRegistry }
|
|
|
|
|
|
|
|
after do
|
|
|
|
registry.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does register general css properly" do
|
2019-08-21 00:39:52 +08:00
|
|
|
plugin_directory_name = "my_plugin"
|
|
|
|
registry.register_asset("test.css", nil, plugin_directory_name)
|
|
|
|
registry.register_asset("test2.css", nil, plugin_directory_name)
|
2014-12-10 03:20:53 +08:00
|
|
|
|
2019-08-21 00:39:52 +08:00
|
|
|
expect(registry.mobile_stylesheets[plugin_directory_name]).to be_nil
|
|
|
|
expect(registry.stylesheets[plugin_directory_name].count).to eq(2)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers desktop css properly" do
|
|
|
|
registry.register_asset("test.css", :desktop)
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.mobile_stylesheets.count).to eq(0)
|
|
|
|
expect(registry.desktop_stylesheets.count).to eq(1)
|
|
|
|
expect(registry.stylesheets.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers mobile css properly" do
|
|
|
|
registry.register_asset("test.css", :mobile)
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.mobile_stylesheets.count).to eq(1)
|
|
|
|
expect(registry.stylesheets.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers desktop css properly" do
|
|
|
|
registry.register_asset("test.css", :desktop)
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.desktop_stylesheets.count).to eq(1)
|
|
|
|
expect(registry.stylesheets.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers sass variable properly" do
|
|
|
|
registry.register_asset("test.css", :variables)
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.sass_variables.count).to eq(1)
|
|
|
|
expect(registry.stylesheets.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers admin javascript properly" do
|
|
|
|
registry.register_asset("my_admin.js", :admin)
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.admin_javascripts.count).to eq(1)
|
|
|
|
expect(registry.javascripts.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
2018-04-10 14:37:16 +08:00
|
|
|
|
|
|
|
it "registers vendored_core_pretty_text properly" do
|
|
|
|
registry.register_asset("my_lib.js", :vendored_core_pretty_text)
|
|
|
|
|
|
|
|
expect(registry.vendored_core_pretty_text.count).to eq(1)
|
|
|
|
expect(registry.javascripts.count).to eq(0)
|
|
|
|
end
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
2015-06-05 03:56:17 +08:00
|
|
|
context '#register_seed_data' do
|
|
|
|
let(:registry) { DiscoursePluginRegistry }
|
|
|
|
|
|
|
|
after do
|
|
|
|
registry.reset!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "registers seed data properly" do
|
|
|
|
registry.register_seed_data("admin_quick_start_title", "Banana Hosting: Quick Start Guide")
|
|
|
|
registry.register_seed_data("admin_quick_start_filename", File.expand_path("../docs/BANANA-QUICK-START.md", __FILE__))
|
|
|
|
|
|
|
|
expect(registry.seed_data["admin_quick_start_title"]).to eq("Banana Hosting: Quick Start Guide")
|
|
|
|
expect(registry.seed_data["admin_quick_start_filename"]).to eq(File.expand_path("../docs/BANANA-QUICK-START.md", __FILE__))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|