forked from activeadmin/activeadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreadcrumbs_spec.rb
143 lines (121 loc) · 4.29 KB
/
breadcrumbs_spec.rb
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require 'spec_helper'
describe "Breadcrumbs" do
include ActiveAdmin::ViewHelpers
describe "generating a trail from paths" do
# Mock our params
def params; {}; end
# Mock link to and return a hash
def link_to(name, url); {:name => name, :path => url}; end
let(:trail) { breadcrumb_links(path) }
context "when request '/admin'" do
let(:path){ "/admin" }
it "should not have any items" do
trail.size.should == 0
end
end
context "when path '/admin/posts'" do
let(:path) { "/admin/posts" }
it "should have one item" do
trail.size.should == 1
end
it "should have a link to /admin" do
trail[0][:name].should == "Admin"
trail[0][:path].should == "/admin"
end
end
context "when path '/admin/posts/1'" do
let(:path) { "/admin/posts/1" }
it "should have 2 items" do
trail.size.should == 2
end
it "should have a link to /admin" do
trail[0][:name].should == "Admin"
trail[0][:path].should == "/admin"
end
it "should have a link to /admin/posts" do
trail[1][:name].should == "Posts"
trail[1][:path].should == "/admin/posts"
end
end
context "when path '/admin/posts/1/comments'" do
let(:path) { "/admin/posts/1/comments" }
it "should have 3 items" do
trail.size.should == 3
end
it "should have a link to /admin" do
trail[0][:name].should == "Admin"
trail[0][:path].should == "/admin"
end
it "should have a link to /admin/posts" do
trail[1][:name].should == "Posts"
trail[1][:path].should == "/admin/posts"
end
context "when Post.find(1) doesn't exist" do
it "should have a link to /admin/posts/1" do
trail[2][:name].should == "1"
trail[2][:path].should == "/admin/posts/1"
end
end
context "when Post.find(1) does exist" do
before do
Post.stub!(:find).and_return{ mock(:display_name => "Hello World") }
end
it "should have a link to /admin/posts/1 using display name" do
trail[2][:name].should == "Hello World"
trail[2][:path].should == "/admin/posts/1"
end
end
end
context "when path '/admin/posts/4e24d6249ccf967313000000/comments'" do
let(:path) { "/admin/posts/4e24d6249ccf967313000000/comments" }
it "should have 3 items" do
trail.size.should == 3
end
it "should have a link to /admin" do
trail[0][:name].should == "Admin"
trail[0][:path].should == "/admin"
end
it "should have a link to /admin/posts" do
trail[1][:name].should == "Posts"
trail[1][:path].should == "/admin/posts"
end
context "when Post.find(4e24d6249ccf967313000000) doesn't exist" do
it "should have a link to /admin/posts/4e24d6249ccf967313000000" do
trail[2][:name].should == "4e24d6249ccf967313000000"
trail[2][:path].should == "/admin/posts/4e24d6249ccf967313000000"
end
end
context "when Post.find(4e24d6249ccf967313000000) does exist" do
before do
Post.stub!(:find).with('4e24d6249ccf967313000000').and_return{ mock(:display_name => "Hello World") }
end
it "should have a link to /admin/posts/4e24d6249ccf967313000000 using display name" do
trail[2][:name].should == "Hello World"
trail[2][:path].should == "/admin/posts/4e24d6249ccf967313000000"
end
end
end
context "when path '/admin/posts/1/coments/1'" do
let(:path) { "/admin/posts/1/comments/1" }
it "should have 4 items" do
trail.size.should == 4
end
it "should have a link to /admin" do
trail[0][:name].should == "Admin"
trail[0][:path].should == "/admin"
end
it "should have a link to /admin/posts" do
trail[1][:name].should == "Posts"
trail[1][:path].should == "/admin/posts"
end
it "should have a link to /admin/posts/1" do
trail[2][:name].should == "1"
trail[2][:path].should == "/admin/posts/1"
end
it "should have a link to /admin/posts/1/comments" do
trail[3][:name].should == "Comments"
trail[3][:path].should == "/admin/posts/1/comments"
end
end
end
end