5.0から5.2にアップデートさせてみる
まだメジャーバージョンでのアップグレードじゃないから大丈夫??
やること
code:bash
toy_app $ git diff
diff --git a/Gemfile b/Gemfile
index 2d880f8..1403d1f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,7 +7,7 @@ end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
-gem 'rails', '~> 5.0.2'
+gem 'rails', '~> 5.2.1'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
code:bash
toy_app $ bundle update
toy_app $ bundle exec rails app:update
...
... conflict config/boot.rb
Overwrite /Users/akiko/work/rails5/toy_app/config/boot.rb? (enter "h" for help) Ynaqdh アップデート完了後
code:bash
toy_app $ rails about
/Users/akiko/work/rails5/toy_app/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
from /Users/akiko/work/rails5/toy_app/config/boot.rb:4:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>'
toy_app $ bundle exec rails app:update
/Users/akiko/work/rails5/toy_app/config/boot.rb:4:in `require': cannot load such file -- bootsnap/setup (LoadError)
from /Users/akiko/work/rails5/toy_app/config/boot.rb:4:in `<top (required)>'
from bin/rails:3:in `require_relative'
from bin/rails:3:in `<main>
怒られてしまう。
bootsnap が無い、とのこと。
2.1 Bootsnap
Rails 5.2 では新規作成したアプリケーションのGemfileに bootsnap gem が追加されました。boot.rbのapp:updateタスクを実行するとセットアップが行われます。使いたい場合は、Gemfileにbootsnap gemを追加してください。boot.rbを変更し、bootsnapを使わないようにすることもできます。
とのことなので、この影響のよう。
bootsnapってなに?
これでした。
こちらの記事に、とても詳しく書かれてありました。ありがとうございます!!
差分を確認
code:bash
--- a/config/boot.rb
+++ b/config/boot.rb
@@ -1,3 +1,4 @@
require 'bundler/setup' # Set up gems listed in the Gemfile.
+require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
config/boot.rbで変更がある。
Railsのアップグレードガイドに従って、Gemfileに追加。
gem 'bootsnap', require: false
code:bash
toy_app $ bundle
.....
Using binding_of_caller 0.8.0
Fetching msgpack 1.2.4
Installing msgpack 1.2.4 with native extensions
Fetching bootsnap 1.3.1
Installing bootsnap 1.3.1 with native extensions
Using bundler 1.16.0
Using byebug 10.0.2
......
完了したので、改めてrails about。
そうしたら、またエラーになったよ....!!!
code:bash
toy_app $ bundle exec rails about
rails aborted!
NoMethodError: undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module
/Users/akiko/work/rails5/toy_app/config/initializers/new_framework_defaults.rb:21:in `<main>'
.....
bin/rails:4:in `<main>'
Tasks: TOP => about => environment
(See full trace by running task with --trace)
halt_callback_chains_on_return_false というのでエラーになっている。
該当箇所はここ。
code:bash
toy_app $ grep "halt_callback_chains_on_return_false" config/**/*.rb
config/initializers/new_framework_defaults.rb:ActiveSupport.halt_callback_chains_on_return_false = false
Gitのアップデート後のdiffには該当しなかったので、Rails5.0 -> Rails5.2の間での取り外しがあったのかな?
上記に書いてあるとおり、deprecatedになったよう
該当箇所をコメントアウトしてみる
code:ruby
# Do not halt callback chains when a callback returns false. Previous versions had true.
-ActiveSupport.halt_callback_chains_on_return_false = false
+# ActiveSupport.halt_callback_chains_on_return_false = false
再度実行!!
今度はうまく行きました!
アップデートの場合はちゃんとChangelogにも目を通さねば....
railsのバージョンが 5.2.1 になっていただきます
code:bash
toy_app $ bundle exec rails about
DEPRECATION WARNING: The factory_girl gem is deprecated.
......
About your application's environment
Rails version 5.2.1
Ruby version 2.3.2-p217 (x86_64-darwin16)
RubyGems version 2.6.10
Rack version 2.0.5
JavaScript Runtime Node.js (V8)
Middleware Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ContentSecurityPolicy::Middleware, Rack::Head, Rack::ConditionalGet, Rack::ETag, Rack::TempfileReaper
Application root /Users/akiko/work/rails5/toy_app
Environment development
Database adapter sqlite3
Database schema version 20170613220826
FactoryGirlをFactoryBotにする
2017年にgemの名称が変わったので、このあたりも調整しないとwarningが出てしまいます。
code:bash
toy_app $ git diff | grep -i Factory
- gem 'factory_girl_rails'
+ gem 'factory_bot_rails'
- factory_girl (4.8.0)
+ factory_bot (4.11.0)
- factory_girl_rails (4.8.0)
- factory_girl (~> 4.8.0)
+ factory_bot_rails (4.11.0)
+ factory_bot (~> 4.11.0)
- factory_girl_rails
+ factory_bot_rails
-FactoryGirl.define do
+FactoryBot.define do
factory :user do
test用のDBをsetupする
db:setup をしようとすると、これまたdeprecation warningが出ます.....
これも2017年時点ではこうしたメッセージは出ていなかった
5.2での変更っぽい
これかな?
code:bash
toy_app $ bundle exec rake db:setup
DEPRECATION WARNING: Leaving ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer
set to false is deprecated. SQLite databases have used 't' and 'f' to serialize
boolean values and must have old data converted to 1 and 0 (its native boolean
serialization) before setting this flag to true. Conversion can be accomplished
by setting up a rake task which runs
ExampleModel.where("boolean_column = 't'").update_all(boolean_column: 1)
ExampleModel.where("boolean_column = 'f'").update_all(boolean_column: 0)
for all models and all boolean columns, after which the flag must be set to
true by adding the following to your application.rb file:
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
(called from load at /Users/akiko/work/rails5/toy_app/vendor/bundle/ruby/2.3.0/bin/rake:22)
Database 'db/test.sqlite3' already exists
-- create_table("microposts", {:force=>:cascade})
-> 0.0080s
-- create_table("users", {:force=>:cascade})
-> 0.0048s