2013-10-04 1 views
0

을 도우미레일 경로로 라우팅을 네임 스페이스는 나는 다음과 같은 경로 규칙이

올바른 보이는
reports_stats_by_date GET /reports/stats_by_date(.:format)   reports#stats_by_date 

. 그래서이 함수를 사용하여 레이크 내 컨트롤러를 테스트하려고합니다.

def test_reports_should_load  
    get :reports_stats_by_date, :start_date => '2013-10-01', :end_date => '2013-10-05', :format => :json 
    assert_response :success 
end 

아주 간단합니다. 내가 레이크 테스트를 실행할 때, 나는 다음과 같은 오류 얻을 : 어떤 이유

ReportsControllerTest#test_reports_should_load: 
ActionController::UrlGenerationError: No route matches {:start_date=>"2013-10-01", :end_date=>"2013-10-05", :format=>:json, :controller=>"reports", :action=>"reports_stats_by_date"} 
test/controllers/reports_controller_test.rb:6:in `test_reports_should_load' 

을, 레일은 작업을로드하려고 : reports_stats_by_date를 경로가 명확 보고서 번호의 stats_by_date를 가리키는 경우. 여기서 내가 뭘 잘못 했니?

+0

의 stats_by_date : START_DATE => '2013년 10월 1일': 종료일 => '2013년 10월 5일': 형식 => : json. get은 일반적으로 헬퍼 메소드가 아닌 액션 이름을 심볼로 기대합니다. 이게 작동하는지 알려주세요 – Raghu

+0

아니요. 이제 경로 일치 없음을 얻습니다. : action => "reports/stats_by_date" –

+0

다음은 확실히 작동해야합니다 : stats_by_date, : start_date => '2013-10-01', : end_date => '2013-10 -05 ', : 형식 => : json. 이제는 – Raghu

답변

1

경로 이름이 아닌 작업 이름 만 참조하면되기 때문입니다. 얻을 '/ 보고서/stats_by_date'를 시도 test_reports_should_load 당신 대신 reports_stats_by_date

def test_reports_should_load  
    get :stats_by_date, :start_date => '2013-10-01', :end_date => '2013-10-05', :format => :json 
    assert_response :success 
end 
+0

경로가 아닌 작업 이름을 지정 했으므로 작동 중입니다. 레일스가 서로 다른 네임 스페이스에서 충돌하는 두 경로를 처리하는 방법을 설명 할 수 있습니까? 예 :/reports/stats_by_date vs/charts/stats_by_date. –

관련 문제