Hi, I expected to be able to do something like this in a routing spec: { :get => ''/legacy/route'' }.should redirect_to(''/shiny/new/route'') However there doesn''t appear to be a redirect_to matcher, and digging deeper I can''t even see an underlying Rails assertion method that will assert for redirect routing configuration. Did I miss it? Do I need to spec this with a request spec instead? cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne
On Aug 8, 2011, at 6:00 PM, Matt Wynne wrote:> Hi, > > I expected to be able to do something like this in a routing spec: > > { :get => ''/legacy/route'' }.should redirect_to(''/shiny/new/route'')Routes resolve to paths to controller actions, they don''t do any http redirection.> However there doesn''t appear to be a redirect_to matcher, and digging deeper I can''t even see an underlying Rails assertion method that will assert for redirect routing configuration. Did I miss it? > > Do I need to spec this with a request spec instead?Or a controller spec. Either way, it''s the controller that''s redirecting Cheers, David
On 9 Aug 2011, at 01:02, David Chelimsky wrote:> On Aug 8, 2011, at 6:00 PM, Matt Wynne wrote: > >> I expected to be able to do something like this in a routing spec: >> >> { :get => ''/legacy/route'' }.should redirect_to(''/shiny/new/route'') > > Routes resolve to paths to controller actions, they don''t do any http redirection.A ''redirect'' helper was added to ActionDispatch::Mapper for Rails 3, to allow redirection without hitting a controller: https://github.com/rails/rails/commit/a1ce52e#L2R294 http://guides.rubyonrails.org/routing.html#redirection Chris
On Aug 9, 2011, at 2:00 AM, Chris Mear wrote:> On 9 Aug 2011, at 01:02, David Chelimsky wrote: > >> On Aug 8, 2011, at 6:00 PM, Matt Wynne wrote: >> >>> I expected to be able to do something like this in a routing spec: >>> >>> { :get => ''/legacy/route'' }.should redirect_to(''/shiny/new/route'') >> >> Routes resolve to paths to controller actions, they don''t do any http redirection. > > A ''redirect'' helper was added to ActionDispatch::Mapper for Rails 3, to allow redirection without hitting a controller: > > https://github.com/rails/rails/commit/a1ce52e#L2R294 > > http://guides.rubyonrails.org/routing.html#redirection > > ChrisGlad to know that! I think this needs to be in Rails before it''s in RSpec. Would either of you (Matt/Chris) care to open up a feature request for a new Rails assertion? Something like assert_route_redirects? If you do, please reference it in this thread. Cheers, David
On 9 Aug 2011, at 13:11, David Chelimsky wrote:> On Aug 9, 2011, at 2:00 AM, Chris Mear wrote: > >> On 9 Aug 2011, at 01:02, David Chelimsky wrote: >> >>> On Aug 8, 2011, at 6:00 PM, Matt Wynne wrote: >>> >>>> I expected to be able to do something like this in a routing spec: >>>> >>>> { :get => ''/legacy/route'' }.should redirect_to(''/shiny/new/route'') >>> >>> Routes resolve to paths to controller actions, they don''t do any http redirection. >> >> A ''redirect'' helper was added to ActionDispatch::Mapper for Rails 3, to allow redirection without hitting a controller: >> >> https://github.com/rails/rails/commit/a1ce52e#L2R294 >> >> http://guides.rubyonrails.org/routing.html#redirection >> >> Chris > > > Glad to know that! > > I think this needs to be in Rails before it''s in RSpec. Would either of you (Matt/Chris) care to open up a feature request for a new Rails assertion? Something like assert_route_redirects? If you do, please reference it in this thread.Done: https://github.com/rails/rails/issues/2488 cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Helles?y) Founder, http://relishapp.com +44(0)7974430184 | http://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20110810/bf2c2403/attachment.html>