namespaced resources
Reported by Nicholas Rutherford | January 11th, 2010 @ 12:41 PM
There are 2 things to consider here, first is a conflict between desired functionality and the implementation, and a spec and another bit of implementation.
When I pickle_path something like 'store', 'the book' I would expect it to use store_book_path(model!('the book)).
path.rb line 16 suggests this should work (syms are treated differently in the later code, too)
resources = pickle_names.map{|n| model(n) || n.to_sym}
but pickle_path_spec.rb has a counter-example (and no positive examples):
it "('that user', :extra => 'new comment') should raise the error raised by model!" do
lambda { path_to_pickle "that user", "new comment" }.should raise_error(RuntimeError, 'Could not figure out a path for ["that user", "new comment"] {}')
end
Comments and changes to this ticket
-
Nicholas Rutherford January 11th, 2010 @ 12:50 PM
Second is something I believe would be useful for the case where a group of resources are moved into a namespace and pickle has been used to resolve their paths.
For example if I have two resources books and dvds, and am told they have to be moved under a store/ namespace, then I would change the application code as appropriate, but to update my features I would add
Pickle.config.namespaces[:store] = [:books, :dvds]
and this would point "books path" and "dvds path" at the new routes.
It may have hairy edge cases though. Take these paths for example
reviews/ volume/n/reviews
introduce namespace bulletin/
bulletin/reviews bulletin/volume/n/bulletin/reviews (which is wrong, it should be bulletin/volume/n/reviews)
-
Nicholas Rutherford January 11th, 2010 @ 01:21 PM
- Assigned user changed from Ian White to Nicholas Rutherford
Actually the namespacing (in the features) does seem to work. I'll try adding some specs for this.
It would still be nice to have a config option, rather than needing to go through many scenarios explicitly adding the namespace to path_to / pickle paths.
-
Nicholas Rutherford January 11th, 2010 @ 05:27 PM
- State changed from new to open
- Assigned user changed from Nicholas Rutherford to Ian White
This is pretty confusing stuff. It works for some routes and not others.
"Then I should be on the bulletin volume's new article page" works
"When I go to the bulletin volume's page" => undefined method
bulletin_volume's_path' "When I go to the bulletin review's volume's page" => undefined method
bulletin_review's_volume's_path'Having learned more about pickle's path resolution & specced and fiddled a bit I decided to change my app's path_to to know about the namespaces.
#namespacing pickle paths when /^the bulletin #{capture_model}(?:'s)? page$/ # eg. the forum's page path_to_pickle 'bulletin', $1 when /^the bulletin #{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page path_to_pickle 'bulletin', $1, $2 when /^the bulletin #{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page path_to_pickle 'bulletin', $1, $2, :extra => $3 # or the forum's post's edit page when /^the bulletin #{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page path_to_pickle 'bulletin', $1, :extra => $2 # or the forum's edit page
It now resolves the urls correctly.
Abstraction would be a timesaver but seems pretty complex, this at least lets me make my features pass again.Thoughts?
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Assign tickets to <b>Ian White</b>, so I get notified