1
votes

I know, that with this topic more questions asket, but i don't found what i need.

Currently i'm updating rails app from 3.2.13 to 4.2.0 and after upgrading rails naturally fails tests. These tests are passed in 3.2.13

So, i have this route:

get '/catalogs/:article_id/get_applicability_by_brand/:brand_id', :to => 'catalogs#get_applicability_by_brand', constrains: { format: 'js' }, as: :catalog_get_applicability_by_brand

Result of rake routes like this:

  catalog_get_applicability_by_brand GET /catalogs/:article_id/get_applicability_by_brand/:brand_id(.:format)                                                   catalogs#get_applicability_by_brand {:constrains=>{:format=>"js"}}

Controller action, it only render js.erb template:

  def get_applicability_by_brand
      @applicability = CatalogAccess::TecDoc.get_applicability_by_brand(params[:article_id], params[:brand_id])
  end

Minitest controller test:

      def test_get_applicability_by_brand_action
    expected_applicability = [
      { 'model_name' => 'Model 1',
        'name' => 'fake name',
        'year_of_construct_from' => '2000',
        'year_of_construct_to' => '2010',
        'construction_type' => 'fake type' },
      { 'model_name' => 'Model 1',
        'name' => 'fake name 2',
        'year_of_construct_from' => '1991',
        'year_of_construct_to' => '2005',
        'construction_type' => 'fake type' }
    ]
    CatalogAccess::TecDoc.expects(:get_applicability_by_brand).with('12', '23').returns expected_applicability
    xhr :get, :get_applicability_by_brand, :article_id => '12', :brand_id => '23', :format => "js"
    assert_response 200
    assert_template 'get_applicability_by_brand'
    assert_template :partial => '_tecdoc2_applicability'
  end

Test error message is:

ActionController::UrlGenerationError:         ActionController::UrlGenerationError: No route matches {:action=>"get_applicability_by_brand", :article_id=>"12", :brand_id=>"23", :controller=>"catalogs", :format=>"js"}

I found that if append to my test option 'use_route', it will be pass, but get warning that seems not good solution

xhr :get, :get_applicability_by_brand, :article_id => '12', :brand_id => '23', :format => "js", :use_route => 'catalogs'

Warning message:

DEPRECATION WARNING: You are trying to generate the URL for a named route called "catalogs" but no such route was found. In the future, this will result in an `ActionController::UrlGenerationError` exception. (called from test_get_applicability_by_brand_action at /home/sdilshod/webapp/ps_base/apps/www/test/controllers/catalogs_controller_test.rb:627)
DEPRECATION WARNING: Passing the `use_route` option in functional tests are deprecated. Support for this option in the `process` method (and the related `get`, `head`, `post`, `patch`, `put` and `delete` helpers) will be removed in the next version without replacement. Functional tests are essentially unit tests for controllers and they should not require knowledge to how the application's routes are configured. Instead, you should explicitly pass the appropiate params to the `process` method. Previously the engines guide also contained an incorrect example that recommended using this option to test an engine's controllers within the dummy application. That recommendation was incorrect and has since been corrected. Instead, you should override the `@routes` variable in the test case with `Foo::Engine.routes`. See the updated engines guide for details. (called from test_get_applicability_by_brand_action at /home/sdilshod/webapp/ps_base/apps/www/test/controllers/catalogs_controller_test.rb:627)
DEPRECATION WARNING: You are trying to generate the URL for a named route called "catalogs" but no such route was found. In the future, this will result in an `ActionController::UrlGenerationError` exception. (called from test_get_applicability_by_brand_action at /home/sdilshod/webapp/ps_base/apps/www/test/controllers/catalogs_controller_test.rb:627)

Advise me please correct solution.

I'll hope your help, thanks!