Skip to content

Commit

Permalink
Add Rails 5.2 and 6.0 to build, fixing up issues
Browse files Browse the repository at this point in the history
In addition to adding scenarios for 5.2 and 6.0, I had to do some
cleanup to get everything working well:

* Replace string-based version checks with numeric ones, and update all
  version checks to treat 6+ the same as 5 (except where necessary).

* Avoid touching `ActiveSupport::Deprecation::DeprecationProxy`
  instances to fix a couple of warnings in Rails 6.

* Update Bundler as part of container setup, because Rails 6's config
  seems to rely on a newer version of Bundler than the one that comes
  with the Ruby image.

* Update the regexes in the `show-routes` spec to be compatible with 5.2
  and up.

* Add a new code path to `show-routes` for Rails 6.

* Upgrade all bundles, just for hygiene.
  • Loading branch information
rf- committed Dec 29, 2018
1 parent 3fad595 commit 035d5c8
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ end

desc 'Start the Rails console'
task :console => :development_env do
if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1)
if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1) ||
Rails::VERSION::MAJOR >= 6
require 'rails/command'
require 'rails/commands/console/console_command'
else
Expand Down
4 changes: 4 additions & 0 deletions lib/pry-rails/commands/show_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def display_mongoid_models
models = []

ObjectSpace.each_object do |o|
# If this is deprecated, calling any methods on it will emit a warning,
# so just back away slowly.
next if ActiveSupport::Deprecation::DeprecationProxy === o

is_model = false

begin
Expand Down
24 changes: 20 additions & 4 deletions lib/pry-rails/commands/show_routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ def process
Rails.application.reload_routes!
all_routes = Rails.application.routes.routes

formatted = case Rails.version.to_s
when /^[45]/
formatted =
if Rails::VERSION::MAJOR >= 6
process_rails_6_and_higher(all_routes)
elsif Rails::VERSION::MAJOR == 4 || Rails::VERSION::MAJOR == 5
process_rails_4_and_5(all_routes)
when /^3\.2/
elsif Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR >= 2
process_rails_3_2(all_routes)
else
process_rails_3_0_and_3_1(all_routes)
Expand Down Expand Up @@ -64,12 +66,26 @@ def process_rails_3_0_and_3_1(all_routes)

def process_rails_3_2(all_routes)
require 'rails/application/route_inspector'

Rails::Application::RouteInspector.new.format(all_routes)
end

def process_rails_4_and_5(all_routes)
require 'action_dispatch/routing/inspector'
ActionDispatch::Routing::RoutesInspector.new(all_routes).format(ActionDispatch::Routing::ConsoleFormatter.new).split(/\n/)

ActionDispatch::Routing::RoutesInspector.
new(all_routes).
format(ActionDispatch::Routing::ConsoleFormatter.new).
split(/\n/)
end

def process_rails_6_and_higher(all_routes)
require 'action_dispatch/routing/inspector'

ActionDispatch::Routing::RoutesInspector.
new(all_routes).
format(ActionDispatch::Routing::ConsoleFormatter::Sheet.new).
split(/\n/)
end

PryRails::Commands.add_command(self)
Expand Down
2 changes: 1 addition & 1 deletion lib/pry-rails/prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def formatted_env
end

def project_name
if Rails::VERSION::MAJOR == 6
if Rails::VERSION::MAJOR >= 6
Rails.application.class.module_parent_name.underscore
else
Rails.application.class.parent_name.underscore
Expand Down
6 changes: 2 additions & 4 deletions lib/pry-rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ class Railtie < Rails::Railtie
end
end

if Rails::VERSION::MAJOR == 4 || Rails::VERSION::MAJOR == 5 ||
Rails::VERSION::MAJOR == 6
if Rails::VERSION::MAJOR >= 4
Rails.application.config.console = Pry
end

if (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 2) ||
Rails::VERSION::MAJOR == 4 || Rails::VERSION::MAJOR == 5 ||
Rails::VERSION::MAJOR == 6
Rails::VERSION::MAJOR >= 4
require "rails/console/app"
require "rails/console/helpers"
TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods
Expand Down
5 changes: 4 additions & 1 deletion scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project: pryrails

shared:
from: ruby:2.4
cmd: "(bundle check || bundle install) && bundle exec rake"
cmd: "(bundle check || (gem install bundler && bundle install)) && bundle exec rake"
service:
volumes:
- bundle_{{scenario_name}}:/usr/local/bundle
Expand All @@ -25,3 +25,6 @@ scenarios:
rails42: {}
rails50: {}
rails51: {}
rails52: {}
rails60:
from: ruby:2.5
2 changes: 1 addition & 1 deletion scenarios/rails30.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.0
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails31.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.0
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails32.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.0
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails40.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.3
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails41.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.3
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails42.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.4
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails50.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.4
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
2 changes: 1 addition & 1 deletion scenarios/rails51.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ FROM ruby:2.4
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || bundle install) && bundle exec rake
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
15 changes: 15 additions & 0 deletions scenarios/rails52.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
version: "2"
services:
scenario:
build:
context: ..
dockerfile: scenarios/rails52.dockerfile
image: pryrails_scenario_rails52
volumes:
- "..:/scenario"
- "bundle_rails52:/usr/local/bundle"
environment:
BUNDLE_GEMFILE: scenarios/rails52.gemfile
volumes:
bundle_rails52: {}
5 changes: 5 additions & 0 deletions scenarios/rails52.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ruby:2.4
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
7 changes: 7 additions & 0 deletions scenarios/rails52.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"

gem "rails", "~> 5.2.0"
gem "mongoid"
gem "sqlite3"

gemspec :path => "../"
15 changes: 15 additions & 0 deletions scenarios/rails60.docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
version: "2"
services:
scenario:
build:
context: ..
dockerfile: scenarios/rails60.dockerfile
image: pryrails_scenario_rails60
volumes:
- "..:/scenario"
- "bundle_rails60:/usr/local/bundle"
environment:
BUNDLE_GEMFILE: scenarios/rails60.gemfile
volumes:
bundle_rails60: {}
5 changes: 5 additions & 0 deletions scenarios/rails60.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ruby:2.5
RUN mkdir -p /scenario
WORKDIR /scenario
ENV LANG=C.UTF-8
CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake
7 changes: 7 additions & 0 deletions scenarios/rails60.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source "https://rubygems.org"

gem "rails", github: "rails/rails"
gem "mongoid"
gem "sqlite3"

gemspec :path => "../"
3 changes: 2 additions & 1 deletion spec/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

require 'spec_helper'

if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1)
if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1) ||
Rails::VERSION::MAJOR >= 6
require 'rails/command'
require 'rails/commands/console/console_command'
else
Expand Down
2 changes: 1 addition & 1 deletion spec/show_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
expected_output += mongoid_models
end

if Rails.version.to_s =~ /^5/
if Rails::VERSION::MAJOR >= 5
expected_output = internal_models + expected_output
end

Expand Down
8 changes: 4 additions & 4 deletions spec/show_routes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
it "should print a list of routes" do
output = mock_pry('show-routes', 'exit-all')

output.must_match %r{^edit_pokemon GET /pokemon/edit}
output.must_match %r{edit_pokemon GET /pokemon/edit}
end

it "should print a list of routes which include grep option" do
output = mock_pry('show-routes -G edit', 'exit-all')

output.must_match %r{^edit_pokemon GET /pokemon/edit}
output.must_match %r{^ edit_beer GET /beer/edit}
output.must_match %r{edit_pokemon GET /pokemon/edit}
output.must_match %r{ edit_beer GET /beer/edit}
end

it "should filter list based on multiple grep options" do
output = mock_pry('show-routes -G edit -G pokemon', 'exit-all')

output.must_match %r{^edit_pokemon GET /pokemon/edit}
output.must_match %r{edit_pokemon GET /pokemon/edit}
output.wont_match %r{edit_beer}
end
end

0 comments on commit 035d5c8

Please sign in to comment.