プロジェクトで使用されるRailsバージョンのアップグレード2.2.2=>2.3.8


詳細
プロジェクトで使用しているRailsバージョンは2.2.2で、最新の2.3.8にアップグレードしたいということで、関連調査を行いました.調査は2つの方面に分けて行います:一方でRailsの変更履歴を調査します(ネット上で多く調べることができて、JavaEyeニュースはあって、紹介しません);一方、Rails 2.3.8をインストールした後、Rakeテストを実行します(私たちのテストCaseはまだ十分で、コードのカバー率は90%以上です).
まず、environmentを変更します.rb
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
  ...
  config.action_controller.session = {
    :key => '_quanp_auth_session_id',   # session_key     
    :secret => secret
  }
end

rakeで次のエラーが発生しました
参照
./test/unit/../test_helper.rb:19: undefined method `use_transactional_fixtures='
for Test::Unit::TestCase:Class (NoMethodError)
Test::Unit::TestCaseはActiveSupport::TestCaseに切り替えるように要求されています.
xxx_controller_testで、またエラーが爆発しました.
参照
NoMethodError: undefined method `get' for #<0x47cc7e4>
class XXXXControllerTestActionControllerの変化は大きいです.
  • 2.2.2ではResponseがAbstractResponseを継承し、RequestがAbstractRequestを継承し、2.3.8ではResponseがRack::Responseを継承し、RequestがRack::Requestを継承する.
  • 2.3.8でTestResponseでヘッダ情報を設定する場合は@header,headers,headerの3つの形式でRack::Responseにalias:headers,:headerの定義があります.2.2.2で利用できる@headersはもう使えません.
  • ActionControl::Baseのassign_default_content_type_and_charsetも消え、responseを呼び出すように変更する必要があります.assign_default_content_type_and_charset!
  • 2.2.2.2 actionでRuntimeErrorが発生した場合、responseのステータスコードは0(初期値はnil)である.2.3.8では、200(初期値は200)が返されます.

  • 私たちのプロジェクトのコードはActionControllerのいくつかの方法を上書きしたので、本当に苦労しました.しかしtest実行時のメソッド呼び出し順序が分かったことは,どうやら収穫があった.
    testでget:actionを実行すると、呼び出し順序は次のようになります.
    参照
    ActionController::TestProcess::get
    |- ActionController::TestProcess::process
    |  |- ActionController::ProcessWithTest::process_with_test
    |  |  |- ActionController::Base::process
    |  |  |  |- ActionController::Base::initialize_template_class
    |  |  |  |- ActionController::Base::assign_shortcuts
    |  |  |  |- ActionController::Base::initialize_current_url
    |  |  |  |- ActionController::Base::assign_names
    |  |  |  |- ActionController::Base::log_processing
    |  |  |  |- send(method, *arguments)
    |  |  |  |- ActionController::Base::send_response
    |  |  |  |  |- ActionController::Response::prepare!
    |  |  |  |  |  |- ActionController::Response::assign_default_content_type_and_charset!
    |  |  |  |  |  |- ActionController::Response::handle_conditional_get!
    |  |  |  |  |  |- ActionController::Response::set_content_length!
    |  |  |  |  |  |- ActionController::Response::convert_content_type!
    |  |  |  |  |  |- ActionController::Response::convert_language!
    |  |  |  |  |  |- ActionController::Response::convert_cookies!