Luc
Luc

Reputation: 17072

Functional tests with specific route in rails

In my config/routes.rb, I have created a specific route targeting the data controller:

match '/things/:id/data' => 'data#get', :via => :get

When I set up a functional test, I got the following error:

ActionController::RoutingError: No route matches {:controller=>"data", :action=>"get"}

My test is:

require 'test_helper'

class ActionController::TestCase
  include Devise::TestHelpers
end

class DataControllerTest < ActionController::TestCase
  setup do
    sign_in users(:one)
  end

  test "should get last data of thing" do
    get :get
    assert_response :success
  end

end

How can I specify in the test that /things/:id/data needs to be used to match data#get ?

Upvotes: 0

Views: 152

Answers (2)

Naveed
Naveed

Reputation: 11167

Try this

test "should get last data of thing" do
  get :get, id => "ID OF YOUR THING"
  assert_response :success
end

data is a member_action so you need to provide ID of your resource( thing in your case)

Upvotes: 2

pjammer
pjammer

Reputation: 9577

Wondering aloud, if you changed get to show, does it work? If so, I fear that overwriting method names for the similar verb names is messing things up. Barring that, what does your route test say?

Upvotes: 0

Related Questions