mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 22:22:18 +08:00
427d54b2b0
Zeitwerk simplifies working with dependencies in dev and makes it easier reloading class chains. We no longer need to use Rails "require_dependency" anywhere and instead can just use standard Ruby patterns to require files. This is a far reaching change and we expect some followups here.
57 lines
1.2 KiB
Ruby
57 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'rails_helper'
|
|
|
|
describe DiscoursePlugin do
|
|
|
|
class TestPlugin < DiscoursePlugin
|
|
module SomeModule
|
|
end
|
|
|
|
module TestMixin
|
|
end
|
|
end
|
|
|
|
let(:registry) { mock }
|
|
let(:plugin) { TestPlugin.new(registry) }
|
|
|
|
describe ".mixins" do
|
|
it "finds its mixins" do
|
|
expect(TestPlugin.mixins).to eq([TestPlugin::TestMixin])
|
|
end
|
|
end
|
|
|
|
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', 'test')
|
|
plugin.register_css('test.css', 'test')
|
|
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)
|
|
@proc = plugin.listen_for(:hello).first
|
|
end
|
|
|
|
after do
|
|
DiscourseEvent.off(:hello, &@proc)
|
|
end
|
|
|
|
it "calls the method when it is triggered" do
|
|
plugin.expects(:hello).with('there')
|
|
DiscourseEvent.trigger(:hello, 'there')
|
|
end
|
|
|
|
end
|
|
|
|
end
|