@@ -11,16 +11,20 @@ def params; {}; end
1111 # Mock link to and return a hash
1212 def link_to ( name , url ) ; { :name => name , :path => url } ; end
1313
14+ let ( :post ) { mock ( :display_name => 'Hello World' ) }
15+
16+ let ( :post_config ) { stub ( find_resource : post ) }
17+
1418 let :active_admin_config do
15- m = mock
16- m . stub_chain ( :belongs_to_config , :target , :resource_class ) . and_return Post
17- m
19+ active_admin_config = stub
20+ active_admin_config . stub_chain ( :belongs_to_config , :target ) . and_return post_config
21+ active_admin_config
1822 end
1923
2024 let ( :trail ) { breadcrumb_links ( path ) }
2125
2226 context "when request '/admin'" do
23- let ( :path ) { "/admin" }
27+ let ( :path ) { "/admin" }
2428
2529 it "should not have any items" do
2630 trail . size . should == 0
@@ -71,16 +75,14 @@ def link_to(name, url); {:name => name, :path => url}; end
7175 end
7276
7377 context "when Post.find(1) doesn't exist" do
78+ before { post_config . stub ( find_resource : nil ) }
7479 it "should have a link to /admin/posts/1" do
7580 trail [ 2 ] [ :name ] . should == "1"
7681 trail [ 2 ] [ :path ] . should == "/admin/posts/1"
7782 end
7883 end
7984
8085 context "when Post.find(1) does exist" do
81- before do
82- Post . stub ( :where ) . with ( 'id' => '1' ) . and_return { [ mock ( :display_name => 'Hello World' ) ] }
83- end
8486 it "should have a link to /admin/posts/1 using display name" do
8587 trail [ 2 ] [ :name ] . should == "Hello World"
8688 trail [ 2 ] [ :path ] . should == "/admin/posts/1"
@@ -104,6 +106,7 @@ def link_to(name, url); {:name => name, :path => url}; end
104106 end
105107
106108 context "when Post.find(4e24d6249ccf967313000000) doesn't exist" do
109+ before { post_config . stub ( find_resource : nil ) }
107110 it "should have a link to /admin/posts/4e24d6249ccf967313000000" do
108111 trail [ 2 ] [ :name ] . should == "4e24d6249ccf967313000000"
109112 trail [ 2 ] [ :path ] . should == "/admin/posts/4e24d6249ccf967313000000"
@@ -112,7 +115,7 @@ def link_to(name, url); {:name => name, :path => url}; end
112115
113116 context "when Post.find(4e24d6249ccf967313000000) does exist" do
114117 before do
115- Post . stub ( :where ) . with ( 'id' => '4e24d6249ccf967313000000' ) . and_return { [ mock ( :display_name => 'Hello :)' ) ] }
118+ post_config . stub ( :find_resource => mock ( :display_name => 'Hello :)' ) )
116119 end
117120 it "should have a link to /admin/posts/4e24d6249ccf967313000000 using display name" do
118121 trail [ 2 ] [ :name ] . should == "Hello :)"
@@ -136,7 +139,7 @@ def link_to(name, url); {:name => name, :path => url}; end
136139 trail [ 1 ] [ :path ] . should == "/admin/posts"
137140 end
138141 it "should have a link to /admin/posts/1" do
139- trail [ 2 ] [ :name ] . should == "1 "
142+ trail [ 2 ] [ :name ] . should == "Hello World "
140143 trail [ 2 ] [ :path ] . should == "/admin/posts/1"
141144 end
142145 it "should have a link to /admin/posts/1/comments" do
@@ -145,17 +148,5 @@ def link_to(name, url); {:name => name, :path => url}; end
145148 end
146149 end
147150
148- context 'when using a nonstandard primary key' do
149- let ( :path ) { '/admin/posts/55555/comments' }
150- before do
151- Post . stub ( :primary_key ) . and_return 'something_else'
152- Post . stub ( :where ) . with ( 'something_else' => '55555' ) . and_return { [ mock ( :display_name => 'Hello Hello!' ) ] }
153- end
154- it 'should link to /admin/posts/55555 using display name' do
155- trail [ 2 ] [ :name ] . should == 'Hello Hello!'
156- trail [ 2 ] [ :path ] . should == '/admin/posts/55555'
157- end
158- end
159-
160151 end
161152end
0 commit comments