2013-08-23 14:21:52 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
require_dependency 'plugin/instance'
|
|
|
|
|
|
|
|
describe Plugin::Instance do
|
|
|
|
|
2014-04-02 13:22:12 +08:00
|
|
|
after do
|
|
|
|
DiscoursePluginRegistry.javascripts.clear
|
2014-04-07 22:33:35 +08:00
|
|
|
DiscoursePluginRegistry.admin_javascripts.clear
|
|
|
|
DiscoursePluginRegistry.server_side_javascripts.clear
|
2014-04-02 13:22:12 +08:00
|
|
|
DiscoursePluginRegistry.stylesheets.clear
|
2014-04-07 22:33:35 +08:00
|
|
|
DiscoursePluginRegistry.mobile_stylesheets.clear
|
2014-04-25 16:26:37 +08:00
|
|
|
DiscoursePluginRegistry.desktop_stylesheets.clear
|
|
|
|
DiscoursePluginRegistry.sass_variables.clear
|
2014-04-02 13:22:12 +08:00
|
|
|
end
|
|
|
|
|
2013-08-26 09:04:16 +08:00
|
|
|
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 17:18:24 +08:00
|
|
|
plugin = plugins[0]
|
2013-08-26 09:04:16 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
context "register asset" do
|
2014-04-10 14:30:22 +08:00
|
|
|
it "does register general css properly" do
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("test.css")
|
|
|
|
plugin.register_asset("test2.css")
|
|
|
|
|
2014-04-10 14:30:22 +08:00
|
|
|
plugin.send :register_assets!
|
|
|
|
|
2014-04-25 16:26:37 +08:00
|
|
|
DiscoursePluginRegistry.mobile_stylesheets.count.should == 0
|
2014-04-10 14:30:22 +08:00
|
|
|
DiscoursePluginRegistry.stylesheets.count.should == 2
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
2014-04-10 14:30:22 +08:00
|
|
|
|
|
|
|
it "registers desktop css properly" do
|
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("test.css", :desktop)
|
|
|
|
plugin.send :register_assets!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.mobile_stylesheets.count.should == 0
|
2014-04-25 16:26:37 +08:00
|
|
|
DiscoursePluginRegistry.desktop_stylesheets.count.should == 1
|
|
|
|
DiscoursePluginRegistry.stylesheets.count.should == 0
|
2014-04-10 14:30:22 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "registers mobile css properly" do
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("test.css", :mobile)
|
2014-04-10 14:30:22 +08:00
|
|
|
plugin.send :register_assets!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.mobile_stylesheets.count.should == 1
|
|
|
|
DiscoursePluginRegistry.stylesheets.count.should == 0
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
2014-04-10 14:30:22 +08:00
|
|
|
|
2014-04-25 16:26:37 +08:00
|
|
|
it "registers desktop css properly" do
|
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("test.css", :desktop)
|
|
|
|
plugin.send :register_assets!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.desktop_stylesheets.count.should == 1
|
|
|
|
DiscoursePluginRegistry.stylesheets.count.should == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
it "registers sass variable properly" do
|
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("test.css", :variables)
|
|
|
|
plugin.send :register_assets!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.sass_variables.count.should == 1
|
|
|
|
DiscoursePluginRegistry.stylesheets.count.should == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2014-04-10 14:30:22 +08:00
|
|
|
it "registers admin javascript properly" do
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("my_admin.js", :admin)
|
2014-04-10 14:30:22 +08:00
|
|
|
|
|
|
|
plugin.send :register_assets!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.admin_javascripts.count.should == 1
|
|
|
|
DiscoursePluginRegistry.javascripts.count.should == 0
|
|
|
|
DiscoursePluginRegistry.server_side_javascripts.count.should == 0
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
2014-04-10 14:30:22 +08:00
|
|
|
|
|
|
|
it "registers server side javascript properly" do
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin = Plugin::Instance.new nil, "/tmp/test.rb"
|
|
|
|
plugin.register_asset("my_admin.js", :server_side)
|
2014-04-10 14:30:22 +08:00
|
|
|
|
|
|
|
plugin.send :register_assets!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.server_side_javascripts.count.should == 1
|
|
|
|
DiscoursePluginRegistry.javascripts.count.should == 1
|
|
|
|
DiscoursePluginRegistry.admin_javascripts.count.should == 0
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
2014-04-10 14:30:22 +08:00
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-08-23 14:21:52 +08:00
|
|
|
context "activate!" do
|
|
|
|
it "can activate plugins correctly" do
|
2013-08-26 09:04:16 +08:00
|
|
|
plugin = Plugin::Instance.new
|
2013-08-23 14:21:52 +08:00
|
|
|
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 12:39:34 +08:00
|
|
|
auth_provider.authenticator.name.should == 'ubuntu'
|
2013-08-23 14:21:52 +08:00
|
|
|
|
|
|
|
# calls ensure_assets! make sure they are there
|
2013-09-20 09:40:46 +08:00
|
|
|
plugin.assets.count.should == 1
|
2014-04-10 14:30:22 +08:00
|
|
|
plugin.assets.each do |a, opts|
|
2013-08-23 14:21:52 +08:00
|
|
|
File.exists?(a).should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
# ensure it cleans up all crap in autogenerated directory
|
|
|
|
File.exists?(junk_file).should be_false
|
|
|
|
end
|
2014-04-07 22:33:35 +08:00
|
|
|
|
|
|
|
it "finds all the custom assets" do
|
|
|
|
plugin = Plugin::Instance.new
|
|
|
|
plugin.path = "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
|
2014-04-10 14:30:22 +08:00
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin.register_asset("test.css")
|
|
|
|
plugin.register_asset("test2.scss")
|
2014-04-10 14:30:22 +08:00
|
|
|
plugin.register_asset("mobile.css", :mobile)
|
|
|
|
plugin.register_asset("desktop.css", :desktop)
|
|
|
|
plugin.register_asset("desktop2.css", :desktop)
|
|
|
|
|
2014-04-25 16:26:37 +08:00
|
|
|
plugin.register_asset("variables1.scss", :variables)
|
|
|
|
plugin.register_asset("variables2.scss", :variables)
|
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin.register_asset("code.js")
|
2014-04-10 14:30:22 +08:00
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin.register_asset("server_side.js", :server_side)
|
2014-04-10 14:30:22 +08:00
|
|
|
|
2014-04-07 22:33:35 +08:00
|
|
|
plugin.register_asset("my_admin.js", :admin)
|
|
|
|
plugin.register_asset("my_admin2.js", :admin)
|
|
|
|
|
|
|
|
plugin.activate!
|
|
|
|
|
|
|
|
DiscoursePluginRegistry.javascripts.count.should == 3
|
|
|
|
DiscoursePluginRegistry.admin_javascripts.count.should == 2
|
|
|
|
DiscoursePluginRegistry.server_side_javascripts.count.should == 1
|
2014-04-25 16:26:37 +08:00
|
|
|
DiscoursePluginRegistry.desktop_stylesheets.count.should == 2
|
|
|
|
DiscoursePluginRegistry.sass_variables.count.should == 2
|
|
|
|
DiscoursePluginRegistry.stylesheets.count.should == 2
|
|
|
|
DiscoursePluginRegistry.mobile_stylesheets.count.should == 1
|
2014-04-07 22:33:35 +08:00
|
|
|
end
|
2013-08-23 14:21:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|