Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Accept custom :as argument for path strategy #19

Closed
wants to merge 4 commits into from

2 participants

@phallguy

One of the reasons I considered using versionist is to clean up the helper method namespace. By default only the path strategy passes an :as parameter to the routing namespace. I'd like to have the 'default' route not have a prefix on the url helper methods.

@bploetz
Owner
  1. Please add a snippet to the README exhibiting this new feature and how to use it. It's not clear to me based on the code what you're trying to achieve here.
  2. This change breaks several tests (see below), and is missing tests of it's own. These need to be rectified before I will consider pulling this in.
  3. In the future, please rebase feature branches to squash commits and clean up history before submitting the pull request.
Failures:

  1) Versionist::Routing#api_version v1 :path :default => true should route to the default when no version given
     Failure/Error: match '/foos.(:format)' => 'foos#index', :via => :get
     ArgumentError:
       Invalid route name: '/v1'
     # ./spec/api_routing_spec.rb:465:in `block (9 levels) in <top (required)>'
     # ./lib/versionist/routing.rb:42:in `configure_path'
     # ./lib/versionist/routing.rb:19:in `api_version'
     # ./spec/api_routing_spec.rb:464:in `block (8 levels) in <top (required)>'
     # ./spec/api_routing_spec.rb:463:in `block (7 levels) in <top (required)>'

  2) Versionist::Routing#api_version v1 :path :default => true should not route to the default when another configured version is given
     Failure/Error: match '/foos.(:format)' => 'foos#index', :via => :get
     ArgumentError:
       Invalid route name: '/v1'
     # ./spec/api_routing_spec.rb:465:in `block (9 levels) in <top (required)>'
     # ./lib/versionist/routing.rb:42:in `configure_path'
     # ./lib/versionist/routing.rb:19:in `api_version'
     # ./spec/api_routing_spec.rb:464:in `block (8 levels) in <top (required)>'
     # ./spec/api_routing_spec.rb:463:in `block (7 levels) in <top (required)>'

  3) Versionist::Routing#api_version v2 :path :default => true should route to the default when no version given
     Failure/Error: match '/foos.(:format)' => 'foos#index', :via => :get
     ArgumentError:
       Invalid route name: '/v2'
     # ./spec/api_routing_spec.rb:465:in `block (9 levels) in <top (required)>'
     # ./lib/versionist/routing.rb:42:in `configure_path'
     # ./lib/versionist/routing.rb:19:in `api_version'
     # ./spec/api_routing_spec.rb:464:in `block (8 levels) in <top (required)>'
     # ./spec/api_routing_spec.rb:463:in `block (7 levels) in <top (required)>'

  4) Versionist::Routing#api_version v2 :path :default => true should not route to the default when another configured version is given
     Failure/Error: match '/foos.(:format)' => 'foos#index', :via => :get
     ArgumentError:
       Invalid route name: '/v2'
     # ./spec/api_routing_spec.rb:465:in `block (9 levels) in <top (required)>'
     # ./lib/versionist/routing.rb:42:in `configure_path'
     # ./lib/versionist/routing.rb:19:in `api_version'
     # ./spec/api_routing_spec.rb:464:in `block (8 levels) in <top (required)>'
     # ./spec/api_routing_spec.rb:463:in `block (7 levels) in <top (required)>'

  5) Versionist::Routing#api_version v2.1 :path :default => true should route to the default when no version given
     Failure/Error: match '/foos.(:format)' => 'foos#index', :via => :get
     ArgumentError:
       Invalid route name: '/v2.1'
     # ./spec/api_routing_spec.rb:465:in `block (9 levels) in <top (required)>'
     # ./lib/versionist/routing.rb:42:in `configure_path'
     # ./lib/versionist/routing.rb:19:in `api_version'
     # ./spec/api_routing_spec.rb:464:in `block (8 levels) in <top (required)>'
     # ./spec/api_routing_spec.rb:463:in `block (7 levels) in <top (required)>'

  6) Versionist::Routing#api_version v2.1 :path :default => true should not route to the default when another configured version is given
     Failure/Error: match '/foos.(:format)' => 'foos#index', :via => :get
     ArgumentError:
       Invalid route name: '/v2.1'
     # ./spec/api_routing_spec.rb:465:in `block (9 levels) in <top (required)>'
     # ./lib/versionist/routing.rb:42:in `configure_path'
     # ./lib/versionist/routing.rb:19:in `api_version'
     # ./spec/api_routing_spec.rb:464:in `block (8 levels) in <top (required)>'
     # ./spec/api_routing_spec.rb:463:in `block (7 levels) in <top (required)>'

Finished in 11.75 seconds
625 examples, 6 failures

Failed examples:

rspec ./spec/api_routing_spec.rb:473 # Versionist::Routing#api_version v1 :path :default => true should route to the default when no version given
rspec ./spec/api_routing_spec.rb:485 # Versionist::Routing#api_version v1 :path :default => true should not route to the default when another configured version is given
rspec ./spec/api_routing_spec.rb:473 # Versionist::Routing#api_version v2 :path :default => true should route to the default when no version given
rspec ./spec/api_routing_spec.rb:485 # Versionist::Routing#api_version v2 :path :default => true should not route to the default when another configured version is given
rspec ./spec/api_routing_spec.rb:473 # Versionist::Routing#api_version v2.1 :path :default => true should route to the default when no version given
rspec ./spec/api_routing_spec.rb:485 # Versionist::Routing#api_version v2.1 :path :default => true should not route to the default when another configured version is given
@phallguy phallguy closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/versionist/routing.rb
View
4 lib/versionist/routing.rb
@@ -36,10 +36,12 @@ def configure_path(config, &block)
path = Versionist::VersioningStrategy::Path.new(config)
# Use the :as option and strip out non-word characters from the path to avoid this:
# https://github.com/rails/rails/issues/3224
- route_hash = {:module => config[:module], :as => config[:path].gsub(/\W/, '_')}
+ route_hash = {:module => config[:module], :as => config[:path].gsub(/\W/, '_') }
route_hash.merge!({:defaults => config[:defaults]}) if config.has_key?(:defaults)
+ as = route_hash.delete :as if path.default?
namespace(config[:path], route_hash, &block)
if path.default?
+ route_hash[:name_prefix] = as
scope(route_hash, &block)
end
end
Something went wrong with that request. Please try again.