Hello all,
I’m trying to perform a pretty simple routing constraint
Here are my routes, my constraint, and my spec.
routes.rb
require 'lib/root_constraints'
Tuhmayta::Application.routes.draw do
get "pages/home"
constraints(RootConstraints) do
root :controller => "lists", :action => "show", :id => "master"
end
This file has been truncated. show original
root_constraints.rb
class RootConstraints
def self.matches?(request)
if request.env['warden'].authenticated?(:user)
return true
else
return false
end
end
end
pages_controller_spec.rb
require "spec_helper"
describe PagesController do
describe "routing" do
it "recognizes and generates #home" do
{ :get => "/pages/home" }.should route_to(:controller => "pages", :action => "home")
end
context "when no user is signed in" do
This file has been truncated. show original
As you can see, I’ve attempted to stub my RootConstraints.matches?
method to just return true or false. However, this doesn’t seem to
work correctly. Even when I stub RootConstraints.matches? to return
false, it still always routes root to :controller => “lists”, :action
=> “show”, :id => “name”.
Here is the error that I receive: gist:649432 · GitHub
Can anybody enlighten me as to why this happens?
Thanks,
Joe
On Oct 27, 2010, at 2:49 PM, Joseph DelCioppio wrote:
=> “show”, :id => “name”.
Here is the error that I receive: gist:649432 · GitHub
Can anybody enlighten me as to why this happens?
The issue is within assert_recognizes in Rails (to which route_to
delegates).
See Issues · rspec/rspec-rails · GitHub and
#5805 [PATCH] assert_recognizes does not support constraints - Ruby on Rails - rails
for more info.
HTH,
David