Route_to for ambiguous generation?

I like the new route_to matcher, but I can’t use it for my root route,
since the route that is generated isn’t the route that I pass in.
Specifically, my routes.rb has:


map.resources :skills, :only => [:index, :show]

map.root :controller => :skills, :action => :index, :conditions => {
:method => :get }

So, ‘/’ routes to SkillsController#index,
but { :controller => :skills, :action => :index }
generates ‘/skills’, an acceptable synonym.

So instead of being able to write:

{ :get, ‘/’ }.should route_to(:controller => ‘skills’, :action =>
‘index’)

I had to write the old style

params_from(:get, ‘/’).should == { :controller => ‘skills’, :action =>
‘index’ }

That works, but is inelegant.

I think I can code things up so that I could write:

{ :get, ‘/’ }.should route_to(:controller => ‘skills’, :action =>
‘index’).which_generates(’/skills’)

If I understand how things work, I’d just need to add a
#which_generates method Spec::Rails::Matchers::RouteTo, and have it
set up an ivar that is used in the @example.assert_routing invocation.
I’m having some trouble accessing GitHub right now. Once it’s back,
I’ll
try doing what I’ve described.

Anyone see a better solution that I’m overlooking?

Hi Cliff,

Hey, that’s a good use case - one I hadn’t considered. Just goes to
show you, the real world has a way of intruding on happy theories. :slight_smile:
It’s nice to hear feedback about the matcher.

which_generates() as a method on the route_to() matcher seems like it
should work to me, once it’s written. I don’t generally wish to have
two separate paths to the same content for publicly-accessible sites,
because it’s not as good for SEO, but there are certainly cases I can
think of where that’s irrelevant.

I’ve had difficulty with my rspec-rails testing environment lately so
it’d be difficult for me to quickly make the adjustment, but it does
seem like it would be a simple change for someone who had strong
motivation or easy access.

Randy

Hi Cliff,

Hey, that’s a good use case - one I hadn’t considered. Just goes to
show you, the real world has a way of intruding on happy theories. :slight_smile:
It’s nice to hear feedback about the matcher.

which_generates() as a method on the route_to() matcher seems like it
should work to me, once it’s written. I don’t generally wish to have
two separate paths to the same content for publicly-accessible sites,
because it’s not as good for SEO, but there are certainly cases I can
think of where that’s irrelevant.

I’ve had difficulty with my rspec-rails testing environment lately so
it’d be difficult for me to quickly make the adjustment, but it does
seem like it would be a simple change for someone who had strong
motivation or easy access.

Randy

“Randy” == Randy H. [email protected] writes:

Randy> Hi Cliff, Hey, that's a good use case - one I hadn't
Randy> considered.  Just goes to show you, the real world has a
Randy> way of intruding on happy theories.  :) It's nice to hear
Randy> feedback about the matcher.

It’s so good that it makes my params_from hack too ugly!

Randy> which_generates() as a method on the route_to() matcher
Randy> seems like it should work to me, once it's written.  I
Randy> don't generally wish to have two separate paths to the same
Randy> content for publicly-accessible sites, because it's not as
Randy> good for SEO, but there are certainly cases I can think of
Randy> where that's irrelevant.

I thought about making it so that the only path to
SkillsController#index was through my root path, but that just struck
me as a bad compromise. As for SEO, I try to do things the way I
think they should be done architecturally and then I just cross my
fingers and hope the search engine folks agree with me (eventually).

Randy> I've had difficulty with my rspec-rails testing environment
Randy> lately so it'd be difficult for me to quickly make the
Randy> adjustment, but it does seem like it would be a simple
Randy> change for someone who had strong motivation or easy
Randy> access.

I added a which_generates call to my current test, cloned Rspec-rails,
added support for which_generates and pushed my results as a
proof-of-concept. Unfortunately, the RSpec-rails testing isn’t
working for me either right now and I have a huge queue of other
things to do before I can look at it. I don’t mind coming back and
making sure that I have a test for my new code, but it won’t be for a
several hours at minimum and maybe a couple of days.