discourse/spec/components/plugin_spec.rb
2013-08-01 16:13:37 +10:00

66 lines
1.8 KiB
Ruby

require 'spec_helper'
require_dependency 'plugin'
describe Plugin do
context "parse" do
it "correctly parses plugin info" do
plugin = Plugin.parse <<TEXT
# name: plugin-name
# about: about: my plugin
# version: 0.1
# authors: Frank Zappa
some_ruby
TEXT
plugin.name.should == "plugin-name"
plugin.about.should == "about: my plugin"
plugin.version.should == "0.1"
plugin.authors.should == "Frank Zappa"
end
end
context "find_all" do
it "can find plugins correctly" do
plugins = Plugin.find_all("#{Rails.root}/spec/fixtures/plugins")
plugins.count.should == 1
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.find_all("#{Rails.root}/frank_zappa")
plugins.count.should == 0
end
end
context "activate!" do
it "can activate plugins correctly" do
plugin = Plugin.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]
auth_provider.options.should == {:identifier => 'https://zappa.com'}
auth_provider.type.should == :open_id
# calls ensure_assets! make sure they are there
plugin.assets.count.should == 2
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