您的位置:首页 > 大数据 > 人工智能

项目中使用的Rails版本升级 2.2.2=>2.3.8

2010-06-25 15:40 423 查看
项目中使用的Rails版本是2.2.2,想升级到到最新的2.3.8,因此做了相关的调查。调查分两方面进行:一方面是调查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 #<ServerControllerTest:0x47cc7e4>
需要把 class XXXControllerTest < ActiveSupport::TestCase 改成 class XXXControllerTest < ActionController::TestCase。

ActionController的变化还是蛮大的。
[list]
[*]2.2.2中Response继承的是AbstractResponse,Request继承的是AbstractRequest,而2.3.8中Response继承的是Rack::Response,Request继承的是Rack::Request。
[*]2.3.8中,如果要在TestResponse中设定header信息,可以用 @header、headers、header 三种形式,Rack::Response中有 alias :headers, :header 的定义。而2.2.2中可用的 @headers 已经不能用了。
[*]ActionController::Base中的assign_default_content_type_and_charset也已经消失,需要改为调用response.assign_default_content_type_and_charset!
[*]2.2.2中如果在action中发生了RuntimeError,response的状态码是0(初始值为nil);而2.3.8中,返回的是200(初始值为200)。
[/list]
由于我们项目的代码覆写了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!
阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: