2011-07-12 5 views
2

私は、クエリパラメータでルートをテストするための順列をカバーしてきたと思うが、アプローチのいずれを通過しません。クエリパラメータとassert_generates/assert_routing - 私は何をしないのですか?

私は、次のしている私のroutes.rbをで

:私は* _using_params_and_extrasのテストに合格すると予想しているでしょう

require 'ruby-debug' 
require 'test_helper' 

class ItemsControllerTest < ActionController::TestCase 
    # Failure: test_assert_generates_using_params_and_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:7]: The generated path <"/items/1/edit"> did not match <"/items/1/edit?q=abc"> 
    test "assert_generates using params and extras" do 
    assert_generates '/items/1/edit?q=abc', 
        { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' }, 
        {}, 
        { :q => 'abc' } 
    end 

    # Failure: test_assert_generates_using_only_params(ItemsControllerTest) [test/functional/items_controller_test.rb:15]: found extras <{:q=>"abc"}>, not <{}> 
    test "assert_generates using only params" do 
    assert_generates '/items/1/edit?q=abc', 
        { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' } 
    end 

    # Failure: test_assert_generates_using_using_only_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:21]: found extras <{}>, not <{:q=>"abc"}> 
    test "assert_generates using using only extras" do 
    assert_generates '/items/1/edit?q=abc', 
        { :controller => 'items', :action => 'edit', :id => '1' }, 
        {}, 
        { :q => 'abc' } 
    end 

    # Failure: test_assert_routing_using_params_and_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:29]: The generated path <"/items/1/edit"> did not match <"/items/1/edit?q=abc"> 
    test "assert_routing using params and extras" do 
    assert_routing '/items/1/edit?q=abc', 
        { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' }, 
        {}, 
        { :q => 'abc' } 
    end 

    # Failure: test_assert_routing_using_only_params(ItemsControllerTest) [test/functional/items_controller_test.rb:37]: found extras <{:q=>"abc"}>, not <{}> 
    test "assert_routing using only params" do 
    assert_routing '/items/1/edit?q=abc', 
        { :controller => 'items', :action => 'edit', :id => '1', :q => 'abc' } 
    end 

    # Failure: test_assert_routing_using_using_only_extras(ItemsControllerTest) [test/functional/items_controller_test.rb:43]: found extras <{}>, not <{:q=>"abc"}> 
    test "assert_routing using using only extras" do 
    assert_routing '/items/1/edit?q=abc', 
        { :controller => 'items', :action => 'edit', :id => '1' }, 
        {}, 
        { :q => 'abc' } 
    end 
end 

- 私は何をしています:

resources :items 

その後、私は持っている私の機能テストのために行方不明?

答えて

4

たぶん、あなたはすでにこれを見つけ出します。私はこの問題を発見して、余分なオプションがあることに気づき、最後にassert_routingのドキュメントをもう一度読むまで、同じ問題を抱えていました。あなたは、URLからq = abcを削除して、エクストラハッシュとオプションハッシュの両方に入れなければなりません。

assert_routing(
    'items/1/edit', 
    {:controller => 'items', :action => 'edit', :id => '1', :q => 'abc'}, 
    {}, 
    {:q => 'abc'} 
) 

だから、のようなものを試してみてください

関連する問題