mirror of
https://github.com/pry/pry-rails.git
synced 2022-11-09 12:36:03 -05:00
Add Rails 5.2 and 6.0 to build, fixing up issues
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.
This commit is contained in:
parent
3fad595b6c
commit
035d5c8203
23 changed files with 102 additions and 25 deletions
3
Rakefile
3
Rakefile
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ class PryRails::ShowModels < Pry::ClassCommand
|
|||
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
|
||||
|
|
|
|||
|
|
@ -17,10 +17,12 @@ class PryRails::ShowRoutes < Pry::ClassCommand
|
|||
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)
|
||||
|
|
@ -64,12 +66,26 @@ class PryRails::ShowRoutes < Pry::ClassCommand
|
|||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ module PryRails
|
|||
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
|
||||
|
|
|
|||
|
|
@ -14,14 +14,12 @@ module PryRails
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -25,3 +25,6 @@ scenarios:
|
|||
rails42: {}
|
||||
rails50: {}
|
||||
rails51: {}
|
||||
rails52: {}
|
||||
rails60:
|
||||
from: ruby:2.5
|
||||
|
|
|
|||
|
|
@ -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,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,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,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,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,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,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,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
scenarios/rails52.docker-compose.yml
Normal file
15
scenarios/rails52.docker-compose.yml
Normal file
|
|
@ -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
scenarios/rails52.dockerfile
Normal file
5
scenarios/rails52.dockerfile
Normal file
|
|
@ -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
scenarios/rails52.gemfile
Normal file
7
scenarios/rails52.gemfile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", "~> 5.2.0"
|
||||
gem "mongoid"
|
||||
gem "sqlite3"
|
||||
|
||||
gemspec :path => "../"
|
||||
15
scenarios/rails60.docker-compose.yml
Normal file
15
scenarios/rails60.docker-compose.yml
Normal file
|
|
@ -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
scenarios/rails60.dockerfile
Normal file
5
scenarios/rails60.dockerfile
Normal file
|
|
@ -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
scenarios/rails60.gemfile
Normal file
7
scenarios/rails60.gemfile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
gem "rails", github: "rails/rails"
|
||||
gem "mongoid"
|
||||
gem "sqlite3"
|
||||
|
||||
gemspec :path => "../"
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ MODELS
|
|||
expected_output += mongoid_models
|
||||
end
|
||||
|
||||
if Rails.version.to_s =~ /^5/
|
||||
if Rails::VERSION::MAJOR >= 5
|
||||
expected_output = internal_models + expected_output
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,20 +10,20 @@ describe "show-routes" do
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue