This project is archived and is in readonly mode.

#5651 ✓resolved
EmmanuelOga

cannot test a controller action for a route defined with match

Reported by EmmanuelOga | September 18th, 2010 @ 01:14 AM | in 3.0.2

Apparently, there is no easy way to test a route defined using the router's match helper.

Using rails 3.0, I define a route using match to catch several different feeds

/feed/google_base.xml /feed/custom.xml

etc.. Here is the code.

# route
B0rken::Application.routes.draw do
  match 'feed/:service(.xml)' => "/public/listings#feed", :format => :xml, :as => :feed
end

# controller
class Public::ListingsController < ApplicationController
  def feed
    render :xml => ["You just requested feed #{ params[:service] }"]
  end
end

# test
class Public::ListingsControllerTest < ActionController::TestCase
  test "should get a feed" do
    get "feed", :service => "google_base", :format => "xml"
    assert_response :success
  end
end

Even though I can rackup this rails3 controller and retrieve the feed w/o problem,
I cannot find a way to make the test retrieve the route.

I understand there might be better ways to define the route in this specific case, but,
If a route is valid, and I'm able to match it in the live rails app, and it returns the expected result,
then I think there should be away to test that controller action in my app test suite.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages