forked from mongomapper/mongomapper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_plugins.rb
50 lines (41 loc) · 1009 Bytes
/
test_plugins.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require 'test_helper'
module MyPlugin
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
class PluginsTest < Test::Unit::TestCase
context "plugin" do
setup do
@document = Class.new do
extend MongoMapper::Plugins
plugin MyPlugin
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 "default plugins to empty array" do
Class.new { extend MongoMapper::Plugins }.plugins.should == []
end
should "add plugin to plugins" do
@document.plugins.should include(MyPlugin)
end
end
end