test/unit/test_plugins.rb in mongo_mapper-0.8.6 vs test/unit/test_plugins.rb in mongo_mapper-0.9.0
- old
+ new
@@ -1,31 +1,37 @@
require 'test_helper'
-module MyPlugin
- def self.configure(model)
- model.class_eval { attr_accessor :from_configure }
+class PluginsTest < Test::Unit::TestCase
+ should "default plugins to empty array" do
+ Class.new { extend MongoMapper::Plugins }.plugins.should == []
end
- module ClassMethods
- def class_foo
- 'class_foo'
- end
- end
+ context "ActiveSupport::Concern" do
+ module MyConcern
+ extend ActiveSupport::Concern
- module InstanceMethods
- def instance_foo
- 'instance_foo'
+ included do
+ attr_accessor :from_concern
+ end
+
+ module ClassMethods
+ def class_foo
+ 'class_foo'
+ end
+ end
+
+ module InstanceMethods
+ def instance_foo
+ 'instance_foo'
+ end
+ end
end
- end
-end
-class PluginsTest < Test::Unit::TestCase
- context "plugin" do
setup do
@document = Class.new do
extend MongoMapper::Plugins
- plugin MyPlugin
+ plugin MyConcern
end
end
should "include instance methods" do
@document.new.instance_foo.should == 'instance_foo'
@@ -34,17 +40,97 @@
should "extend class methods" do
@document.class_foo.should == 'class_foo'
end
should "pass model to configure" do
- @document.new.should respond_to(:from_configure)
+ @document.new.should respond_to(:from_concern)
end
- should "default plugins to empty array" do
- Class.new { extend MongoMapper::Plugins }.plugins.should == []
+ should "add plugin to plugins" do
+ @document.plugins.should include(MyConcern)
end
+ context "Document" do
+ setup do
+ MongoMapper::Document.plugins.delete(MyConcern)
+ end
+
+ should 'allow plugins on Document' do
+ MongoMapper::Document.plugin(MyConcern)
+ Doc().should respond_to(:class_foo)
+ Doc().new.should respond_to(:instance_foo)
+ end
+
+ should 'add plugins to classes that include Document before they are added' do
+ article = Doc()
+ MongoMapper::Document.plugin(MyConcern)
+ article.should respond_to(:class_foo)
+ article.new.should respond_to(:instance_foo)
+ end
+ end
+
+ context "EmbeddedDocument" do
+ setup do
+ MongoMapper::EmbeddedDocument.plugins.delete(MyConcern)
+ end
+
+ should 'allow plugins on EmbeddedDocument' do
+ MongoMapper::EmbeddedDocument.plugin(MyConcern)
+ article = EDoc()
+ article.should respond_to(:class_foo)
+ article.new.should respond_to(:instance_foo)
+ end
+
+ should 'add plugins to classes that include EmbeddedDocument before they are added' do
+ article = EDoc()
+ MongoMapper::EmbeddedDocument.plugin(MyConcern)
+ article.should respond_to(:class_foo)
+ article.new.should respond_to(:instance_foo)
+ end
+ end
+ end
+
+ context "deprecated plugin" do
+ module DeprecatedPlugin
+ def self.configure(model)
+ model.class_eval { attr_accessor :from_configure }
+ end
+
+ module ClassMethods
+ def class_foo
+ 'class_foo'
+ end
+ end
+
+ module InstanceMethods
+ def instance_foo
+ 'instance_foo'
+ end
+ end
+ end
+
+ setup do
+ silence_stderr do
+ @document = Class.new do
+ extend MongoMapper::Plugins
+ plugin DeprecatedPlugin
+ end
+ end
+ end
+
+ should "include instance methods" do
+ @document.new.instance_foo.should == 'instance_foo'
+ end
+
+ should "extend class methods" do
+ @document.class_foo.should == 'class_foo'
+ end
+
+ should "pass model to configure" do
+ @document.new.should respond_to(:from_configure)
+ end
+
should "add plugin to plugins" do
- @document.plugins.should include(MyPlugin)
+ @document.plugins.should include(DeprecatedPlugin)
end
end
end
\ No newline at end of file