项目中使用的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的变化还是蛮大的。
- 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)。
由于我们项目的代码覆写了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!
分享到:
相关推荐
formtastic 是一个Rails表单构建器插件,提供语义丰富和可访问的标记。 示例代码: <%= semantic_form_for @post do |f| %> <%= f.inputs do %> <%= f.input :title %> <%= f.input :body %> <%= f.input :...
支持JQuery的Edit In Place Rails插件(rakuto),使用简便轻巧,与大家共享。 例子 ======= # 控制器 class BlogController in_place_edit_for :post, :title end # Customize the action that update the ...
版本为:rails-2.3.8.gem 可使用指令安装:gem install rails-2.3.8.gem
rails-2.2.2.zip 安装包
Rails的设置 Ruby gem通过将...class User < ActiveRecord xss=removed> { :theme => 'blue' , :view => 'monthly' , :filter => false } s . key :calendar , :defaults => { :scope => 'company' } end end
Rails2.3.8开发安装环境整包,包含ruby1.8.7,rails2.3.8,以及9个相关依赖的gems,一次下载基本上就可以把ROR环境建成。
在这个Rails 5.1示例应用程序中,我们可以使用一个带有复选框的表单来管理组及其成员。 设置 $ bin/setup $ bin/rails server 描述 我们正在使用Group.accepts_nested_attributes_for :memberships, allow_destroy: ...
Rails-flog rails-flog提供了在Rails日志文件... Parameters: {"utf8"=>"✓", "authenticity_token"=>"VYCWAsE+aAN+zSZq2H3ONNqaU8rlyfbnXLfbwDY1i10=", "issue"=>{"is_private"=>"0", "tracker_id"=>"1", "subject"=>
现在我们将这个插件从Rails2.x的版本升级到了3.x版本,并且抽取成了一个通用插件,开始应用于新的Rails3.2的项目之上。有志于AR对象缓存优化的ruby程序员不容错过。 使用方法: class User acts_as_cached(:...
、“自述”、“路由”、“saas”、“设置”、“测试”、“视图”] 首选项:{:git=>true, :apps4=>"rails-bootstrap", :database=>"default", :unit_test=>false, :integration=>false, :fixtures=>false, :frontend=...
以下内容将不会安装演示中使用的所有第三方支持。 它必须稍后手动安装。 安装 将此行添加到您的应用程序的Gemfile中: gem 'pages-rails' , '2.1.5' , :git => 'https://github.com/revoxltd/pages-rails.git' 从...
您可能要讲的内容: Ruby版本=> ruby 2.6.5p114 rails(6.0.3.4) 第三方API =>开放天气地图如何运行Server => rails Database => No Database,因为它充当集成API。 请求速率限制限制=> Rack :: Attack 如何为...
RailsParseHead RailsParseHead是一个简单... metas # => [{:charset=>"utf-8"}, {:name=>"viewport", :content=>"width=device-width"}]rph . links # => [{:rel=>"dns-prefetch", :href=>"https://github.githubasse
设定说明您可能要讲的内容: Ruby版本2.6.6 Rails 6.0版系统依赖性无配置确保在database.yml中设置postgres密码数据库创建轨道db:create 数据库初始化轨道db:migrate如何运行测试套件rspec 控制器和模型的测试用例...
= link_to “Issues”, {:controller => “issue”, :action => “index”}, {:onclick => “alert(1)”} %> 但是值得注意的就是,link_to 的第二个参数,必须是以 map 的形式给出,才能达到这样的效果。...
rails 2.2.2 API 英文的
ROR开发安装环境整包,包含ruby1.8.7,rails2.3.8,以及9个相关依赖的gems,一次下载基本上就可以把ROR环境建成。
1.rails new blog --skip-bundle //创建项目 2.cd blog //进入项目根目录 3.subl . //打开项目开发环境 4.Bundle install //安装gem包环境 5.rails generate model post title:string content:text author:string ...
你可以方便的在migration通过 :array => true里创建数组类型的字段. 创建数组类型的字段的时候还可以添加其它的选项(length,default,等等) create_table :table_with_arrays do |t| t.integer :int_array, :...
使用Aptana+Rails开发Rails Web应用<br>有Aptana的安装配置等等,中文