mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:45:26 +08:00
(experimental) added framework for filtering all sorts of internals in discourse and consuming by plugins
This commit is contained in:
35
spec/components/plugin/filter_manager_spec.rb
Normal file
35
spec/components/plugin/filter_manager_spec.rb
Normal file
@ -0,0 +1,35 @@
|
||||
require 'spec_helper'
|
||||
require_dependency 'plugin/filter_manager'
|
||||
|
||||
describe Plugin::FilterManager do
|
||||
let(:instance){ Plugin::FilterManager.new }
|
||||
|
||||
it "calls registered filters correctly" do
|
||||
instance.register(:added_numbers) do |context,result|
|
||||
context + result + 1
|
||||
end
|
||||
|
||||
instance.register(:added_numbers) do |context,result|
|
||||
context + result + 2
|
||||
end
|
||||
|
||||
instance.apply(:added_numbers, 1, 0).should == 5
|
||||
end
|
||||
|
||||
it "should raise an exception if wrong arity is passed in" do
|
||||
lambda do
|
||||
instance.register(:test) do
|
||||
end
|
||||
end.should raise_exception
|
||||
end
|
||||
|
||||
it "should return the original if no filters exist" do
|
||||
instance.apply(:foo, nil, 42).should == 42
|
||||
end
|
||||
|
||||
it "should raise an exception if no block is passed in" do
|
||||
lambda do
|
||||
instance.register(:test)
|
||||
end.should raise_exception
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user