markbates / mack-more

All the extra stuff you could want for the Mack Framework.

This URL has Read+Write access

mack-more / mack-facets / spec / lib / utils / registry_list_spec.rb
100644 73 lines (55 sloc) 1.819 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
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
 
describe Mack::Utils::RegistryList do
 
  class FooRegistry < Mack::Utils::RegistryList
  end
  
  class BarRegistry < Mack::Utils::RegistryList
    def initial_state
      [1,2,3]
    end
  end
  
  before(:each) do
    FooRegistry.reset!
    BarRegistry.reset!
  end
  
  describe "self.registered_items" do
    
    it "should return the list of registered items" do
      FooRegistry.registered_items.should == []
      FooRegistry.registered_items << 1
      FooRegistry.registered_items.should == [1]
    end
    
  end
  
  describe "self.add" do
    
    it "should add a object only once" do
      BarRegistry.registered_items.should == [1,2,3]
      BarRegistry.add(1)
      BarRegistry.registered_items.should == [1,2,3]
    end
    
    it "should allow for a object to be inserted anywhere in the list" do
      BarRegistry.registered_items.should == [1,2,3]
      BarRegistry.add(4, 1)
      BarRegistry.registered_items.should == [1,4,2,3]
    end
    
  end
  
  describe "self.remove" do
    
    it "should remove an object from the list" do
      BarRegistry.registered_items.should == [1,2,3]
      BarRegistry.remove(2)
      BarRegistry.registered_items.should == [1,3]
    end
  end
  
  describe "self.move_to_top" do
    
    it "should move an object to the top of the list" do
      BarRegistry.registered_items.should == [1,2,3]
      BarRegistry.move_to_top(2)
      BarRegistry.registered_items.should == [2,1,3]
    end
    
  end
  
  describe "self.move_to_bottom" do
    it "should move an object to the bottom of the list" do
      BarRegistry.registered_items.should == [1,2,3]
      BarRegistry.move_to_bottom(2)
      BarRegistry.registered_items.should == [1,3,2]
    end
  end
  
end