thevikas
thevikas

Reputation: 1639

rails test calls the wrong controller which shares the same name

Below is 1 unit test which I am running. Calling the file rail test test/functional/api/field_notes_controller_test.rb works perfectly.

class FieldNotesControllerTest < ActionController::TestCase
    include Devise::Test::ControllerHelpers
    tests Api::FieldNotesController

    test "upload file with wrong proj id" do
        post "create",params:{token: "abc",'format'=>'json',"bogus" => "data"}

And the following controller is covered.

module Api
    class FieldNotesController < Api::ParentController
        ...

But when all tests are run rails test something happens to the router and instead of testing the controller shown above, it does a POST of the controller below. They share the same name, but are on different modules.

class FieldNotesController < ApplicationController
    ...

How can I diagnose/solve this issue?

Upvotes: 0

Views: 149

Answers (1)

Hay.P
Hay.P

Reputation: 48

You may need to name your test class and ensure it's in a folder named api (depending on your controller setup - the folder structures in your tests need to match the ones in your app)

class Api::FieldNotesControllerTest < ActionController::TestCase

Upvotes: 2

Related Questions