Skip to content
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

Feature: routes path specs #123

Closed

Conversation

olance
Copy link

@olance olance commented Sep 3, 2014

Closes #122

As discussed in #122, here's a PR to add a spec() function to route helpers.
It is computed in the build_path_spec method from the route's binary tree, with bonus codesize-per-route reduction ;)

I had to change one test and remove two because of the way routes are now built:

it "should have correct function without arguments signature" => it "should call route function for each route"
it "should have correct function with arguments signature" => pending
it "should have correct function signature with unordered hash" => pending

The reason is that we do not create one function per route with arguments names anymore. (the arguments names were not used anyway, as build_path was given arguments directly)
Maybe we should find a way to keep the information about the arguments names somewhere?

I have added tests in the path_specs_generation_spec.rb spec file. All routes are loaded and two examples are dynamically created for each route, so that if one example fails, we directly know for which route (I have included the name of the route in the examples names).

Tests have been successful on my machine for all Rails versions included in Appraisal.

@olance
Copy link
Author

olance commented Sep 3, 2014

Oh, however Travis CI already shows me some errors with older versions of Ruby. I'll check that out and push fixes to the PR. (I used Array#to_h which only came in Ruby 2.1.0....)

build_path_spec: (route) ->
spec = ''

visit_spec = (r, wildcard=false) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use nested function here? I think better to use a recursive call of build_path_spec by itself and construct result as returing value but not as spec closure variable. Just like it is done in route formatter.

@le0pard
Copy link
Member

le0pard commented Sep 4, 2014

@olance Please, rebase your pull request from new HEAD :)

…ven route, from its binary tree.

Each route helper now has an extra `spec` function attached to it that will return the path spec.

Using the `route` private function to build each route helper

Adapting existing tests to the new code for JS route calls

Testing the path spec generation.
Still failing on wildcard routes in Rails 3.2

Fix for 3.2 globbing

Readme update to document the path spec function

`Array#to_h` is too recent
@le0pard
Copy link
Member

le0pard commented Oct 10, 2014

So, what is need to fix to accept this pull request? /cc @bogdan @olance

@olance
Copy link
Author

olance commented Oct 10, 2014

sorry guys, I'm a bit out of free time currently, but I haven't forgotten you

@le0pard le0pard mentioned this pull request Dec 8, 2014
@bogdan
Copy link
Collaborator

bogdan commented Dec 17, 2014

Merged #135 as alternative implementation. @olance thanks for your help.

@bogdan bogdan closed this Dec 17, 2014
@olance
Copy link
Author

olance commented Dec 18, 2014

Glad to help!

On Wed, Dec 17, 2014 at 8:20 PM, Bogdan Gusiev notifications@github.com
wrote:

Merged #135 as alternative implementation. @olance thanks for your help.

Reply to this email directly or view it on GitHub:
#123 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get the path "spec" for a route?
3 participants