discourse/spec/components/plugin/instance_spec.rb

53 lines
1.5 KiB
Ruby
Raw Normal View History

require 'spec_helper'
require_dependency 'plugin/instance'
describe Plugin::Instance do
2014-04-02 01:22:12 -04:00
after do
DiscoursePluginRegistry.javascripts.clear
DiscoursePluginRegistry.stylesheets.clear
end
context "find_all" do
it "can find plugins correctly" do
plugins = Plugin::Instance.find_all("#{Rails.root}/spec/fixtures/plugins")
plugins.count.should == 1
2013-10-21 05:18:24 -04:00
plugin = plugins[0]
plugin.name.should == "plugin-name"
plugin.path.should == "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
end
it "does not blow up on missing directory" do
plugins = Plugin::Instance.find_all("#{Rails.root}/frank_zappa")
plugins.count.should == 0
end
end
context "activate!" do
it "can activate plugins correctly" do
plugin = Plugin::Instance.new
plugin.path = "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
junk_file = "#{plugin.auto_generated_path}/junk"
plugin.ensure_directory(junk_file)
File.open("#{plugin.auto_generated_path}/junk", "w") {|f| f.write("junk")}
plugin.activate!
plugin.auth_providers.count.should == 1
auth_provider = plugin.auth_providers[0]
2013-08-26 00:39:34 -04:00
auth_provider.authenticator.name.should == 'ubuntu'
# calls ensure_assets! make sure they are there
2013-09-19 21:40:46 -04:00
plugin.assets.count.should == 1
plugin.assets.each do |a|
File.exists?(a).should be_true
end
# ensure it cleans up all crap in autogenerated directory
File.exists?(junk_file).should be_false
end
end
end