2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2014-07-23 07:02:22 +08:00
|
|
|
require_dependency 'discourse_plugin'
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
describe DiscoursePlugin do
|
|
|
|
|
|
|
|
class TestPlugin < DiscoursePlugin
|
2013-02-13 12:45:10 +08:00
|
|
|
module SomeModule
|
|
|
|
end
|
|
|
|
|
|
|
|
module TestMixin
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:registry) { mock }
|
|
|
|
let(:plugin) { TestPlugin.new(registry) }
|
|
|
|
|
2015-02-05 06:33:18 +08:00
|
|
|
after do
|
|
|
|
DiscourseEvent.clear
|
|
|
|
end
|
|
|
|
|
2013-02-13 12:45:10 +08:00
|
|
|
describe ".mixins" do
|
|
|
|
it "finds its mixins" do
|
2015-01-10 00:34:37 +08:00
|
|
|
expect(TestPlugin.mixins).to eq([TestPlugin::TestMixin])
|
2013-02-13 12:45:10 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08: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
|
|
|
|
registry.expects(:register_css).with('test.css')
|
|
|
|
plugin.register_css('test.css')
|
|
|
|
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)
|
|
|
|
plugin.listen_for(:hello)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "calls the method when it is triggered" do
|
|
|
|
plugin.expects(:hello).with('there')
|
|
|
|
DiscourseEvent.trigger(:hello, 'there')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|