次のアップグレード手順に従いました: http://railscasts.com/episodes/318-upgrading-to-rails-3-2
3 つの小さなアップグレードの変更点を次に示します。
(1) Gemfile
-gem 'rails', '3.1.0'
+gem 'rails', '3.2.0'
-gem 'rack', '1.3.3'
+#gem 'rack', '1.3.3'
group :assets do
- gem 'sass-rails', ' ~> 3.1.0'
- gem 'coffee-rails', '~> 3.1.0'
- gem 'uglifier'
+ gem 'sass-rails', ' ~> 3.2.3'
+ gem 'coffee-rails', '~> 3.2.1'
+ gem 'uglifier', ' >=1.0.3'
gem 'asset_sync'
end
(2) config/environments/development.rb
+ config.active_record.mass_assignment_sanitizer = :strict
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
(3) config/environments/test.rb
- config.assets.allow_debugging = true
+ config.active_record.mass_assignment_sanitizer = :strict
アップグレード前の私のテストは次のようでした (それぞれ 1 秒未満)。
...
StockroomTest:
PASS stockroom must have a name (0.03s)
PASS stockroom name must be unique (0.01s)
PASS stockroom with name is valid (0.00s)
...
Finished in 1.604118 seconds.
29 tests, 90 assertions, 0 failures, 0 errors, 0 skips
...
StockroomsControllerTest:
PASS should create stockroom (0.04s)
PASS should destroy stockroom (0.02s)
PASS should get edit (0.14s)
PASS should get index (0.11s)
PASS should get new (0.03s)
PASS should not destroy stockroom (0.04s)
PASS should show stockroom (0.13s)
PASS should update stockroom (0.02s)
...
Finished in 12.572911 seconds.
115 tests, 166 assertions, 0 failures, 0 errors, 0 skips
...
MiscellaneousTest:
PASS get campaigns#index should redirect to newsletters#index (1.83s)
PASS get /campaigns should redirect to / when logged out (0.06s)
Finished in 1.793070 seconds.
2 tests, 3 assertions, 0 failures, 0 errors, 0 skips
後 (各テストには 1 秒以上かかります):
StockroomTest:
PASS stockroom must have a name (1.29s)
PASS stockroom name must be unique (1.30s)
PASS stockroom with name is valid (1.27s)
...
Finished in 41.135808 seconds.
29 tests, 90 assertions, 0 failures, 0 errors, 0 skips
...
StockroomsControllerTest:
PASS should create stockroom (1.30s)
PASS should destroy stockroom (1.29s)
PASS should get edit (1.33s)
PASS should get index (1.43s)
PASS should get new (1.41s)
PASS should not destroy stockroom (1.31s)
PASS should show stockroom (1.36s)
PASS should update stockroom (1.31s)
...
Finished in 161.803235 seconds.
115 tests, 166 assertions, 0 failures, 0 errors, 0 skips
...
MiscellaneousTest:
PASS get /campaigns should redirect to /newsletters when logged in (5.27s)
PASS get /campaigns should redirect to / when logged out (1.67s)
Finished in 7.034593 seconds.
2 tests, 3 assertions, 0 failures, 0 errors, 0 skips
以下は、上記の単体テストの 1 つの例です。以前は 0.01 秒未満でしたが、現在 (アップグレード後) の実行には約 1.3 秒かかります。
テスト/ユニット/stockroom_test.rb
require 'test_helper'
class StockroomTest < ActiveSupport::TestCase
fixtures :stockrooms
test "stockroom with name is valid" do
assert stockrooms(:wine_cellar).valid?, 'tried new wine_cellar'
end
什器が嫌われているのは承知しており、工場を真剣に検討するつもりですが、当面はこれが私の苦境です。関連するフィクスチャは次のとおりです。
テスト/備品/stockrooms.yml
wine_cellar:
id: 1
name: wine cellar
の検証Stockroom
はpresence
との 2 つだけuniqueness
です。
注: 同じマシンで別の rails アプリを実行していますが、それは rails を実行して3.2.5
おり、ほぼ同一の単体テスト (同じ 2 つの検証で同じアサーション) が 0.465489 秒 (0.5 秒未満) で終了します。
上記の「stockroom with name is valid」テストのテスト ログの関連部分は次のようになります。
(0.9ms) SET FOREIGN_KEY_CHECKS = 1
(0.2ms) BEGIN
(84.8ms) BEGIN
(82.3ms) BEGIN
(83.4ms) BEGIN
(79.2ms) BEGIN
(82.1ms) BEGIN
Stockroom Load (0.4ms) SELECT `stockrooms`.* FROM `stockrooms` WHERE `stockrooms`.`id` = 1 LIMIT 1
Stockroom Exists (0.6ms) SELECT 1 AS one FROM `stockrooms` WHERE (`stockrooms`.`name` = BINARY 'wine cellar' AND `stockrooms`.`id` != 1) LIMIT 1
(0.1ms) ROLLBACK
(90.9ms) ROLLBACK
(85.7ms) ROLLBACK
(90.7ms) ROLLBACK
(81.4ms) ROLLBACK
(85.4ms) ROLLBACK
比較のために、私の Rails3.2.5
アプリでの「同等の」テストを次に示します。
(0.2ms) SET FOREIGN_KEY_CHECKS = 1
(0.1ms) BEGIN
Email Load (0.4ms) SELECT `emails`.* FROM `emails` WHERE `emails`.`id` = 980190962 LIMIT 1
Email Exists (2.8ms) SELECT 1 FROM `emails` WHERE (`emails`.`email` = BINARY 'MyString' AND `emails`.`id` != 980190962) LIMIT 1
(0.2ms) ROLLBACK