2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 05:41:23 -04:00
|
|
|
require 'rails_helper'
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
describe DiscoursePlugin do
|
|
|
|
|
|
|
|
class TestPlugin < DiscoursePlugin
|
2013-02-12 23:45:10 -05:00
|
|
|
module SomeModule
|
|
|
|
end
|
|
|
|
|
|
|
|
module TestMixin
|
|
|
|
end
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:registry) { mock }
|
|
|
|
let(:plugin) { TestPlugin.new(registry) }
|
|
|
|
|
2013-02-12 23:45:10 -05:00
|
|
|
describe ".mixins" do
|
|
|
|
it "finds its mixins" do
|
2015-01-09 11:34:37 -05:00
|
|
|
expect(TestPlugin.mixins).to eq([TestPlugin::TestMixin])
|
2013-02-12 23:45:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
it "delegates adding js to the registry" do
|
|
|
|
registry.expects(:register_js).with('test.js', any_parameters)
|
|
|
|
plugin.register_js('test.js')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "delegates adding css to the registry" do
|
2019-08-20 12:39:52 -04:00
|
|
|
registry.expects(:register_css).with('test.css', 'test')
|
|
|
|
plugin.register_css('test.css', 'test')
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "delegates creating archetypes" do
|
|
|
|
registry.expects(:register_archetype).with('banana', oh: 'no!')
|
|
|
|
plugin.register_archetype('banana', oh: 'no!')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'registering for callbacks' do
|
|
|
|
before do
|
|
|
|
plugin.stubs(:hello)
|
2016-09-05 07:33:03 -04:00
|
|
|
@proc = plugin.listen_for(:hello).first
|
2013-02-05 14:16:51 -05:00
|
|
|
end
|
|
|
|
|
2016-09-05 03:15:26 -04:00
|
|
|
after do
|
2016-09-05 07:33:03 -04:00
|
|
|
DiscourseEvent.off(:hello, &@proc)
|
2016-09-05 03:15:26 -04:00
|
|
|
end
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
it "calls the method when it is triggered" do
|
|
|
|
plugin.expects(:hello).with('there')
|
|
|
|
DiscourseEvent.trigger(:hello, 'there')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|