Skip to content

Instantly share code, notes, and snippets.

@grantspeelman
Last active December 16, 2020 13:11
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save grantspeelman/235f4cf83fdc4fab94fc to your computer and use it in GitHub Desktop.
Save grantspeelman/235f4cf83fdc4fab94fc to your computer and use it in GitHub Desktop.
Example Gemfile files preparing for the next rails upgrade (https://grant-ps.blog/2017/07/03/upgrading-ruby-on-rails-in-smallish-steps/)

Preparing for rails 6

These files are examples of how you can start running your code against rails 6 in parallel while not affecting your ability to continue developing.

You will be able to:

  • run rails 6 server
  • run your specs against rails 6
  • mark specs broken rails 6 specs
  • find gems that don't have a upgrade path (yet)
  • make decision with rails 6 in mind
@next_upgrade ||= false
source 'https://rubygems.org'
if @next_upgrade
gem 'rails', '6.0.0.rc2'
else
gem 'rails', '~> 5.2.0'
end
# rest of gems below ....
# examples of wrapping other gems
if @next_upgrade
gem 'paranoia', :github => "radar/paranoia", branch: 'core'
else
gem 'paranoia', '~> 2.0'
end
# BUNDLE_GEMFILE=Gemfile-next bundle install
@next_upgrade = true
main_gemfile = File.expand_path(File.dirname(__FILE__) + '/Gemfile')
eval File.read(main_gemfile), nil, main_gemfile
# do this only once so you have a starting lock file for the upgrade
cp Gemfile.lock Gemfile-next.lock
# update your Gemfile-next.lock to rails 6
# * resolved conflicts.
# * choose compatible rails 6 gems
# * notify gem authors if incompatible
# * fork the gem if you have to and create pull request for gem authors
BUNDLE_GEMFILE=Gemfile-next bundle update
#!/usr/bin/env bash
# a little helper script to use when installing new gems to keep both lock files up to date
bundle install # install gems for rails 5, creates Gemfile.lock
BUNDLE_GEMFILE=Gemfile-next bundle install # install gems for rails 6, creates Gemfile-next.lock
## now you can run commands between rails 5 and 6
bundle install # install gems for rails 5, creates Gemfile.lock
BUNDLE_GEMFILE=Gemfile-next bundle install # install gems for rails 6, creates Gemfile-next.lock
bundle update # update gems for rails 5, creates Gemfile.lock
BUNDLE_GEMFILE=Gemfile-next bundle update # update gems for rails 6, creates Gemfile-next.lock
bundle exec rails s # runs code with rails 5
BUNDLE_GEMFILE=Gemfile-next bundle exec rails s # runs code with rails 6
bundle exec rspec # runs tests against rails 5
BUNDLE_GEMFILE=Gemfile-next bundle exec rspec # runs tests against rails 6
# etc
def pending_on_upgrade
pending "fix for rails upgrade" if Rails.version > "6"
end
## example of marking
it "does another thing" do
pending_on_upgrade
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment