forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard_controller_spec.rb
More file actions
70 lines (54 loc) · 2.13 KB
/
dashboard_controller_spec.rb
File metadata and controls
70 lines (54 loc) · 2.13 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
require 'spec_helper'
module Admin
class DashboardController < ActiveAdmin::Dashboards::DashboardController
end
end
class DashboardController < ActiveAdmin::Dashboards::DashboardController; end
describe ActiveAdmin::Dashboards::DashboardController do
describe "getting the namespace name" do
subject{ controller.send :namespace }
context "when admin namespace" do
let(:controller){ Admin::DashboardController.new }
it { should == :admin }
end
context "when root namespace" do
let(:controller){ DashboardController.new }
it { should == :root }
end
end
describe "conditionally displaying sections" do
before { ActiveAdmin::Dashboards.clear_all_sections! }
let(:controller){ Admin::DashboardController.new }
context "when :if not specified" do
before do
@section = ActiveAdmin::Dashboards.add_section('Stats').last
end
it "should include section" do
controller.send(:find_sections).should include(@section)
end
end
context "when :if option specified as a method" do
before do
@section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => :i_am_awesome?).last
end
it "should call the method of the same name" do
controller.should_receive(:i_am_awesome?).and_return(true)
controller.send(:find_sections).should include(@section)
controller.should_receive(:i_am_awesome?).and_return(false)
controller.send(:find_sections).should_not include(@section)
end
end
context "when :if option specified as block" do
before do
@proc = Proc.new { true }
@section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => proc {}).last
end
it "should evaluate the block" do
controller.should_receive(:instance_exec).with(&@proc).and_return(true)
controller.send(:find_sections).should include(@section)
controller.should_receive(:instance_exec).with(&@proc).and_return(false)
controller.send(:find_sections).should_not include(@section)
end
end
end
end