-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ActiveAdmin::Resource loads a resource for breadcrumbs #2315
ActiveAdmin::Resource loads a resource for breadcrumbs #2315
Conversation
Oh, by the way, I'm just spiking here. I can write tests once a direction is decided... |
This is the direction I was imagining, except you still need to add the decorator wrapping :) Instead of |
The decorator wrapping is already in there, I just need to fix all the tests and add a test for the decorated breadcrumb case.
|
Ah, my apologies. Cool. Any idea when you'll have time to update this? |
I definitely won't have time before next week. I'll try to get it in on the early side of next week. Thanks for your input :) |
Not at all; thank you for going to the trouble to do this! |
@daxter I just rebased this branch onto master. I'm still getting a lot of test failures on master. Should master be all green right now and I have an environment problem? Or are there known failures on master? BTW, I made sure to |
No, master is passing just fine. I'll take a look into what's.causing the failures. |
I've been looking into the failures. It looks like the database isn't set up (the failures are mostly Here's what I've tried so far (to no avail): cd spec/rails/rails-3.2.13
rake db:migrate
rake db:test:prepare
TEST_ENV_NUMBER=2 rake db:test:prepare
cd ../../..
rake # still fails |
Anyway, it's helpful to know that it's working for you. Given my last post, do you have any ideas? |
Are you not able to run even master? This should work just fine: rm -rf spec/rails
rspec spec/unit |
running
passes.
fails on I'll start writing some tests using |
What about |
Well that's embarrassing, It looks like plain old Sorry to have bothered you with this, and thanks for helping troubleshoot. |
No problem. IMO that's probably something that should be changed. Or more, the parallel_tests rake task shouldn't try to spin up X number of runners that each try to build the very same Rails app to use for testing. BTW there are a couple other useful things in the CONTRIBUTING file |
Yeah, thanks. I actually did read CONTRIBUTING, but I sort of assumed that the default |
@@ -136,7 +139,7 @@ def link_to(name, url); {:name => name, :path => url}; end | |||
trail[1][:path].should == "/admin/posts" | |||
end | |||
it "should have a link to /admin/posts/1" do | |||
trail[2][:name].should == "1" | |||
trail[2][:name].should == "Hello World" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a slight change in functionality, but I think for the better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I lied, it's just a change in the stub used by the whole test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What part of your changes caused this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. It was https://github.com/gregbell/active_admin/pull/2315/files#L3R14
@daxter Ok, I think I'm all done here. Do you want me to squash this in to one commit? I've been asked to do that before in ActiveAdmin pull requests. |
Hmmm, there are travis failures. I'm out of open-source time today. I can take a look in a couple of days if you haven't figured it out. For reference, same failure is happening in #2350, and it is unrelated to this pull-request. |
Coverage decreased (-0%) when pulling c88fa7c671e4cd086f303789bfa3c5ced93ec60c on carnesmedia:config_loads_resource into ec99964 on gregbell:master. |
Ok, rebased, and tests pass for me locally. Hopefully Travis is happy now... |
@daxter this should be good to go |
@@ -13,7 +13,7 @@ def breadcrumb_links(path = request.path) | |||
# 3. default to calling `titlecase` on the URL fragment | |||
if part =~ /\A(\d+|[a-f0-9]{24})\z/ && parts[index-1] | |||
config = active_admin_config.belongs_to_config.try(:target) || active_admin_config | |||
obj = config.resource_class.where( config.resource_class.primary_key => part ).first | |||
obj = config.find_resource(part) | |||
name = display_name obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you collapse the last two lines?
name = display_name config.find_resource(part)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, will do
Would you like me to squash this in to one commit? |
Yes, please. Feel free to add as much as you want to the commit message when you squash them. |
Closes #2266 Add `ActiveAdmin::Resource#find_resource`. This is now a centralized place to load a resource, with correct handling of primary key, decoration, etc. Then, use this new way of loading resources in the Breadcrumbs logic. This was the original impetus for for defining `ActiveAdmin::Resource#find_resource`. Previously, the `BreadcrumbsHelper` did a one-off load of the resource, which has historically been a source of bugs and/or inconsistencies. Please note that this is duplication with InheritedResources. Normally, the resource is loaded by InheritedResources, but there are situations in which ActiveAdmin needs to load resources as well (ie Breadcrumbs). It was not reasonable to use InheritedResources to load the resource (see the discussion at #2315).
ActiveAdmin::Resource loads a resource for breadcrumbs
Thanks for the contribution! 🐙 |
Closes activeadmin#2266 Add `ActiveAdmin::Resource#find_resource`. This is now a centralized place to load a resource, with correct handling of primary key, decoration, etc. Then, use this new way of loading resources in the Breadcrumbs logic. This was the original impetus for for defining `ActiveAdmin::Resource#find_resource`. Previously, the `BreadcrumbsHelper` did a one-off load of the resource, which has historically been a source of bugs and/or inconsistencies. Please note that this is duplication with InheritedResources. Normally, the resource is loaded by InheritedResources, but there are situations in which ActiveAdmin needs to load resources as well (ie Breadcrumbs). It was not reasonable to use InheritedResources to load the resource (see the discussion at activeadmin#2315).
Here is an proof-of-concept attempt at #2266.
A couple of notes/thoughts:
I think this is better than having the loading logic in the breadcrumbs helper, but it still doesn't seem idea. All of the resource loading logic is already in the controller (through inherited resources, so not easy to refactor out).
Another possible direction would be to use
ActiveAdmin::Resource#controller
to load the resource. I started trying this, but it gets ugly pretty quick. Here's what it would look like:So, yeah, not great, but at least the resource loading logic isn't duplicated.
@daxter, any thoughts?