2

2.3.18アプリケーションをに移行しています3.2.x。テストの実行中に、ルート ヘルパーを使用してルートを見つけることができないという問題に直面しています。

これが問題に直面しているアサーションです

#test/unit/application_helper_test.rb
def test_calendar_link_to_with_named_route
  . . .
  calendar_link_to(31, date, {:named_route => 'edit_detailed_reservation_path', :method => :post})
  . . .
end

メソッドの定義方法は次のとおりですApplicationHelper

def calendar_link_to(anchor_text, date, *args)
  options = args.first.is_a?(Hash) ? args.pop : {}
  method = options[:method]
  named_route = options[:named_route]

  url_hash = { :day => date.day, :month => date.month, :year => date.year }
  url = named_route ? self.send(named_route, url_hash) : url_hash

  link_options = { :id => "date-#{date.year}-#{date.month}-#{date.day}" }
  if date > Parameter.event_horizon
    link_options[:title] = 'This date is beyond the event horizon.'
  end
  link_options[:method] = method if method
  link_to(anchor_text, url, link_options)
end

テストの実行中に次のエラーが発生します

NoMethodError: undefined method `edit_detailed_reservation_path'

このエラーを解決するために、以下の行を application_helper.rb 内に配置しようとしました。

include Rails.application.routes.url_helpers

以下のコマンドを使用してテストを実行します

rake test TEST=test/unit/application_helper_test.rb

Rails 2 ではedit_detailed_reservation_path、pry セッションで検査中に絶対 URL を提供しますが、Rails 3 では同じことが機能しません。

何が問題なのか、それを修正する方法を教えてください。

4

0 に答える 0