0

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 ?

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

5 Comments

it went one step further with your approach, but I now have the following error: Expected response to be a <:success>, but was <406>
can you post result of rake routes | grep "data"
btw routing issue is resolved, its your spec which is not getting expected results :)
The result of the grep is: GET /things/:id/data(.:format) data#get
The error 406 was indeed a problem with the fixture not having the correct id. Thanks.
0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.