简体   繁体   中英

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 ?

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)

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM