Skip to content

Commit

Permalink
Merge pull request activeadmin#1387 from jpmckinney/mongoid_fixes
Browse files Browse the repository at this point in the history
Fix breadcrumb for Mongoid
  • Loading branch information
pcreux committed Jul 6, 2012
2 parents 5a4c121 + 5420fe2 commit ffef502
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/active_admin/view_helpers/breadcrumb_helper.rb
Expand Up @@ -10,10 +10,10 @@ def breadcrumb_links(path = nil)
crumbs = []
parts.each_with_index do |part, index|
name = ""
if part =~ /^\d/ && parent = parts[index - 1]
if part =~ /^\d|^[a-f0-9]{24}$/ && parent = parts[index - 1]
begin
parent_class = parent.singularize.camelcase.constantize
obj = parent_class.find(part.to_i)
obj = parent_class.find(part[/^[a-f0-9]{24}$/] ? part : part.to_i)
name = display_name(obj)
rescue
end
Expand Down
33 changes: 33 additions & 0 deletions spec/unit/breadcrumbs_spec.rb
Expand Up @@ -82,6 +82,39 @@ def link_to(name, url); {:name => name, :path => url}; 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" }

Expand Down

0 comments on commit ffef502

Please sign in to comment.