Skip to content
This repository

routing specs with advanced constraints #5

Closed
skiz opened this Issue June 08, 2011 · 2 comments

2 participants

Josh Martin David Chelimsky
Josh Martin
skiz commented June 08, 2011

When trying to generate some routing specs that incorporate a custom model based matcher, I was unable to get the specs to pass without also having the constraint return a hash which matches one of the request parameters.

http://guides.rubyonrails.org/routing.html#advanced-constraints describes a way to handle custom constraints, which I have also tried. Even though all of these work properly in rails, I was only able to get the specs to pass by doing something like the following (notice the hash with a key that exists in the request);

routes

 def organization_exists?(req)
    {:organization_id => Organization.where(:slug => req[:organization_id]).exists?}
 end

 scope '/:organization_id', :constraints => lambda{|req| organization_exists?(req) } do
     match '/',             :to => 'organizations#show',             :as => 'organization',             :via => :get
 end

spec

describe "Routing" do
  before do
    @org = Factory.create(:organization)
    MyApp::Application.reload_routes!
  end

  it "routes GET /:organization_id to organizations#show" do
    {:get => "/#{@org.slug}"}.should route_to(:controller => 'organizations', :action => 'show', :organization_id => @org.slug)
  end 
David Chelimsky
Owner

This tracker is for rspec-rails-1.x. For rspec-rails-2 (rails-3), please use https://github.com/rspec/rspec-rails/issues.

This particular issue has been reported a few times already in that tracker, but it is really a rails issue, and has also been raised in the rails tracker (more than once): https://github.com/rails/rails/issues/search?q=test%20route - please either comment on the appropriate issue there or raise a new one. Thx.

David Chelimsky dchelimsky closed this June 08, 2011
Josh Martin
skiz commented June 08, 2011

Oh awesome then. I'll proceed to investigate both ends then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.