Renamed helpers to correspond to renamed Controller classes.
[merb_radiant.git] / radiant_specs / spec / lib / radiant / .svn / text-base / admin_ui_spec.rb.svn-base
blob19f2551402d35e6105ba05ed0e782fb06c449f5a
1 require File.dirname(__FILE__) + "/../../spec_helper"
3 describe Radiant::AdminUI do
4   before :each do
5     @admin = Radiant::AdminUI.instance
6   end
7   
8   it "should be a Simpleton" do
9     Radiant::AdminUI.included_modules.should include(Simpleton)
10     Radiant::AdminUI.should respond_to(:instance)
11   end
12   
13   it "should have a TabSet" do
14     @admin.should respond_to(:tabs)
15     @admin.tabs.should_not be_nil
16     @admin.tabs.should be_instance_of(Radiant::AdminUI::TabSet)
17   end
18 end
20 describe Radiant::AdminUI::TabSet do
22   before :each do
23     @tabs = Radiant::AdminUI::TabSet.new
24     @tab_names = %w{First Second Third}
25     @tab_names.each do |name|
26       @tabs.add name, "/#{name.underscore}"
27     end
28   end
30   it "should be Enumerable" do
31     @tabs.class.included_modules.should include(Enumerable)
32   end
33   
34   it "should have its tabs accessible by name using brackets" do
35     @tabs.should respond_to(:[])
36     @tab_names.each do |name|
37       @tabs[name].should be_instance_of(Radiant::AdminUI::Tab)
38       @tabs[name].name.should == name
39     end
40   end
41   
42   it "should have its tabs accessible by index using brackets" do
43     @tab_names.each_with_index do |name, index|
44       @tabs[index].should be_instance_of(Radiant::AdminUI::Tab)
45       @tabs[index].name.should == name
46     end 
47   end
48   
49   it "should add new tabs to the end by default" do
50     @tabs.size.should == 3
51     @tabs.add "Test", "/test"
52     @tabs[3].name.should == "Test"
53   end
54   
55   it "should add a new tab before the specified tab" do
56     @tabs[1].name.should == "Second"
57     @tabs.add "Before", "/before", :before => "Second"
58     @tabs[1].name.should == "Before"
59     @tabs[2].name.should == "Second"
60   end
61   
62   it "should add a new tab after the specified tab" do
63     @tabs[1].name.should == "Second"
64     @tabs[2].name.should == "Third"
65     @tabs.add "After", "/after", :after => "Second"
66     @tabs[2].name.should == "After"
67     @tabs[1].name.should == "Second"
68     @tabs[3].name.should == "Third"
69   end
70   
71   it "should remove a tab by name" do
72     @tabs.size.should == 3
73     @tabs.remove "Second"
74     @tabs.size.should == 2
75     @tabs[1].name.should == "Third"
76   end
77   
78   it "should not allow adding a tab with the same name as an existing tab" do
79     lambda { @tabs.add "First", "/first" }.should raise_error(Radiant::AdminUI::DuplicateTabNameError)
80   end
81   
82   it "should remove all tabs when cleared" do
83     @tabs.size.should == 3
84     @tabs.clear
85     @tabs.size.should == 0
86   end
87 end
89 describe Radiant::AdminUI::Tab do
90   scenario :users
92   before :each do
93     @tab = Radiant::AdminUI::Tab.new "Test", "/test"
94   end
96   it "should be shown to all users by default" do
97     @tab.visibility.should == [:all]
98     [:existing, :another, :admin, :developer, :non_admin].each do |user|
99       @tab.should be_shown_for(users(user))
100     end
101   end
102   
103   it "should be shown only to admin users when visibility is admin" do
104     @tab.visibility = [:admin]
105     @tab.should be_shown_for(users(:admin))
106     [:existing, :another, :developer, :non_admin].each do |user|
107       @tab.should_not be_shown_for(users(user))
108     end
109   end
110   
111   it "should be shown only to developer users when visibility is developer" do
112     @tab.visibility = [:developer]
113     @tab.should be_shown_for(users(:developer))
114     [:existing, :another, :admin, :non_admin].each do |user|
115       @tab.should_not be_shown_for(users(user))
116     end    
117   end
118   
119   it "should assign visibility from :for option when created" do
120     @tab = Radiant::AdminUI::Tab.new "Test", "/test", :for => :developer
121     @tab.visibility.should == [:developer]
122   end
123   
124   it "should assign visibility from :visibility option when created" do
125     @tab = Radiant::AdminUI::Tab.new "Test", "/test", :visibility => :developer
126     @tab.visibility.should == [:developer]
127   end
128   
129   it "should assign visibility from both :for and :visibility options when created" do
130     @tab = Radiant::AdminUI::Tab.new "Test", "/test", :for => :developer, :visibility => :admin
131     @tab.visibility.should == [:developer, :admin]
132   end