2013-02-06 03:16:51 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
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
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.stylesheets).to eq(Set.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
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.mobile_stylesheets).to eq(Set.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
|
|
|
|
|
|
|
|
context '#server_side_javascripts' do
|
|
|
|
it 'defaults to an empty Set' do
|
2014-04-01 13:08:18 +08:00
|
|
|
registry.server_side_javascripts = nil
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.server_side_javascripts).to eq(Set.new)
|
2014-03-17 20:19:08 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
context '.register_css' do
|
|
|
|
before do
|
2014-04-01 13:08:18 +08:00
|
|
|
registry_instance.register_css('hello.css')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not leaking' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(DiscoursePluginRegistry.new.stylesheets).to be_blank
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is returned by DiscoursePluginRegistry.stylesheets' do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry_instance.stylesheets.include?('hello.css')).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_css('hello.css') }.not_to change(registry.stylesheets, :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
|
|
|
|
|
|
|
|
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
|
|
|
|
registry.register_asset("test.css")
|
|
|
|
registry.register_asset("test2.css")
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.mobile_stylesheets.count).to eq(0)
|
|
|
|
expect(registry.stylesheets.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)
|
|
|
|
expect(registry.server_side_javascripts.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers server side javascript properly" do
|
|
|
|
registry.register_asset("my_admin.js", :server_side)
|
|
|
|
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(registry.server_side_javascripts.count).to eq(1)
|
|
|
|
expect(registry.javascripts.count).to eq(1)
|
|
|
|
expect(registry.admin_javascripts.count).to eq(0)
|
2014-12-10 03:20:53 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|