public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
octopod (author)
Sat Jan 05 12:24:20 -0800 2008
technoweenie (committer)
Sat Feb 02 14:07:09 -0800 2008
commit  badeb2d4e4e49a389091ba7bcd44c49ca9c88684
tree    420fc2def6b2ffdc6fecb09a7e6712964fb42fe2
parent  cacc91d76ac80f6dc0a3a46df8f46ee532f7e5b5
mephisto / test / unit / plugin_test.rb
100644 101 lines (81 sloc) 2.944 kb
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
 
class PluginTest < Test::Unit::TestCase
  fixtures :mephisto_plugins
 
  def test_should_create_plugin_name
    assert_equal 'plugin_whammy_jammy', Mephisto::Plugins::PluginWhammyJammy.plugin_name
  end
  
  def test_should_find_plugin_class_by_name
    assert_equal Mephisto::Plugins::PluginWhammyJammy, Mephisto::Plugin.find_class(:plugin_whammy_jammy)
  end
  
  def test_should_not_find_missing_class
    assert_raises NameError do
      Mephisto::Plugin[:blah]
    end
  end
  
  def test_should_not_find_a_non_model
    assert Mephisto::Plugins.const_defined?(:NonPlugin)
    assert_raises NameError do
      Mephisto::Plugin[:non_plugin]
    end
  end
  
  def test_plugin_option_defaults
    plugin = Mephisto::Plugins::PluginWhammyJammy.new
    assert_equal 'one', plugin.foo
    assert_equal 2, plugin.bar
    assert_equal [3], plugin.baz
  end
  
  def test_should_set_plugin_options
    plugin = Mephisto::Plugins::PluginWhammyJammy.new
    
    plugin.foo = 'two'
    plugin.bar = 3
    plugin.baz = [4]
    assert_equal 'two', plugin.foo
    assert_equal 3, plugin.bar
    assert_equal [4], plugin.baz
    
    plugin.foo = ''
    assert_equal 'one', plugin.foo
    
    plugin.bar = nil
    assert_equal 2, plugin.bar
  end
  
  def test_should_get_and_set_plugin_properties
    properties = %w(notes author version homepage)
    properties.each do |property|
      assert_nil Mephisto::Plugins::PluginWhammyJammy.send(property)
      Mephisto::Plugins::PluginWhammyJammy.send(property, 'foo')
      assert_equal 'foo', Mephisto::Plugins::PluginWhammyJammy.send(property)
      assert_equal 'foo', Mephisto::Plugins::PluginWhammyJammy.new.send(property)
    end
  end
  
  def test_should_find_plugin
    assert_equal Mephisto::Plugins::PluginWhammyJammy.find(1), Mephisto::Plugin[:plugin_whammy_jammy]
  end
  
  def test_should_persist_options
    plugin = Mephisto::Plugin[:plugin_whammy_jammy]
    assert_equal 'one', plugin.foo
    plugin.foo = 'two'
    plugin.save!
    assert_equal 'two', plugin.reload.foo
  end
  
  def test_should_persist_options_on_new_plugin_record
    Mephisto::Plugins::PluginWhammyJammy.delete_all
    plugin = Mephisto::Plugin[:plugin_whammy_jammy]
    klass1 = plugin.class.name
    
    assert plugin.new_record?
    assert_equal 'one', plugin.foo
    plugin.save!
    assert plugin.reload.options.empty?
 
    plugin2 = Mephisto::Plugin[:plugin_whammy_jammy]
    assert_equal 'one', plugin2.foo
    reloaded_klass = plugin2.class.name
    
    assert_equal klass1, reloaded_klass
    plugin.foo = 'two'
    plugin.save
    
    plugin2.reload
 
    assert_equal 'two', plugin2.foo
  end
  
  # def test_should_load_or_initialize_plugin_list
 # plugins = Mephisto::Plugin.load(%w(plugin_whammy_jammy foo_bar baz))
 # assert_equal 2, plugins.size
 # assert plugins['foo_bar'].new_record?
 # end
end