1 require File.dirname(__FILE__) + "/../../spec_helper"
3 describe Radiant::AdminUI do
5 @admin = Radiant::AdminUI.instance
8 it "should be a Simpleton" do
9 Radiant::AdminUI.included_modules.should include(Simpleton)
10 Radiant::AdminUI.should respond_to(:instance)
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)
20 describe Radiant::AdminUI::TabSet 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}"
30 it "should be Enumerable" do
31 @tabs.class.included_modules.should include(Enumerable)
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
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
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"
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"
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"
71 it "should remove a tab by name" do
72 @tabs.size.should == 3
74 @tabs.size.should == 2
75 @tabs[1].name.should == "Third"
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)
82 it "should remove all tabs when cleared" do
83 @tabs.size.should == 3
85 @tabs.size.should == 0
89 describe Radiant::AdminUI::Tab do
93 @tab = Radiant::AdminUI::Tab.new "Test", "/test"
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))
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))
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))
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]
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]
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]