Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

undefined local variable or method `api_v1_airlines' for #<AirlinesControllerTest:0x000000565ff5a928>

I am not sure why minitest is not recognising my route:

# airlines_controller_test.rb
class AirlinesControllerTest < ActionDispatch::IntegrationTest
    test "should get index" do
      get api_v1_airlines
      assert_response :success
    end
  end

` api_v1_airlines GET    /api/v1/airlines(.:format)                                                                        api/v1/airlines#index {:params=>:slug}

`

I ran the test and it gave me

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

`Error:
AirlinesControllerTest#test_should_get_index:
NameError: undefined local variable or method `api_v1_airlines' for #<AirlinesControllerTest:0x0000006532df84b8>
    test/controllers/airlines_controller_test.rb:5:in `block in <class:AirlinesControllerTest>'`

what am I doing wrong? It is not recognizing the route but it is defined in rails routes. What am I not including in my test file?

>Solution :

According to the docs, you should use the *_url form of the route helper.

class AirlinesControllerTest < ActionDispatch::IntegrationTest
    test "should get index" do
      get api_v1_airlines_url
      assert_response :success
    end
  end
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading