diff --git a/lib/pry-rails/railtie.rb b/lib/pry-rails/railtie.rb index 0d8e72a..c9839e8 100644 --- a/lib/pry-rails/railtie.rb +++ b/lib/pry-rails/railtie.rb @@ -27,6 +27,10 @@ class Railtie < Rails::Railtie TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods end + if major == 7 && minor >= 2 + require "rails/console/methods" + end + if major > 7 || (major == 7 && minor >= 2) require "rails/commands/console/irb_console" diff --git a/scenarios/rails60.dockerfile b/scenarios/rails60.dockerfile index e47cf03..f3d38e4 100644 --- a/scenarios/rails60.dockerfile +++ b/scenarios/rails60.dockerfile @@ -2,4 +2,4 @@ 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 +CMD (bundle check || (gem install bundler --version 2.3.27 && bundle install)) && bundle exec rake diff --git a/scenarios/rails60.gemfile b/scenarios/rails60.gemfile index 7278a4c..fd83354 100644 --- a/scenarios/rails60.gemfile +++ b/scenarios/rails60.gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gem "rails", github: "rails/rails" +gem "rails", "~> 6.0" gem "mongoid" gem "sqlite3" diff --git a/scenarios/rails72.docker-compose.yml b/scenarios/rails72.docker-compose.yml new file mode 100644 index 0000000..dc70f83 --- /dev/null +++ b/scenarios/rails72.docker-compose.yml @@ -0,0 +1,14 @@ +--- +services: + scenario: + build: + context: .. + dockerfile: scenarios/rails72.dockerfile + image: pryrails_scenario_rails72 + volumes: + - "..:/scenario" + - "bundle_rails72:/usr/local/bundle" + environment: + BUNDLE_GEMFILE: scenarios/rails72.gemfile +volumes: + bundle_rails72: {} diff --git a/scenarios/rails72.dockerfile b/scenarios/rails72.dockerfile new file mode 100644 index 0000000..369bfba --- /dev/null +++ b/scenarios/rails72.dockerfile @@ -0,0 +1,5 @@ +FROM ruby:3.3 +RUN mkdir -p /scenario +WORKDIR /scenario +ENV LANG=C.UTF-8 +CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake diff --git a/scenarios/rails72.gemfile b/scenarios/rails72.gemfile new file mode 100644 index 0000000..1ee6d5c --- /dev/null +++ b/scenarios/rails72.gemfile @@ -0,0 +1,7 @@ +source "https://rubygems.org" + +gem "rails", "~> 7.2" +gem "mongoid" +gem "sqlite3" + +gemspec :path => "../" diff --git a/spec/config/storage.yml b/spec/config/storage.yml new file mode 100644 index 0000000..d32f76e --- /dev/null +++ b/spec/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket + +# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/spec/find_route_spec.rb b/spec/find_route_spec.rb index 3de40d5..6f52017 100644 --- a/spec/find_route_spec.rb +++ b/spec/find_route_spec.rb @@ -16,29 +16,29 @@ it 'returns the route for a single action' do output = mock_pry('find-route Admin::UsersController#show', 'exit-all') - output.must_match(/show GET/) - output.wont_match(/index GET/) + _(output).must_match(/show GET/) + _(output).wont_match(/index GET/) end it 'returns all the routes for a controller' do output = mock_pry('find-route Admin::UsersController', 'exit-all') - output.must_match(/index GET/) - output.must_match(/show GET/) - output.must_match(/new GET/) - output.must_match(/edit GET/) - output.must_match(/update (PATCH|PUT)/) - output.must_match(/update PUT/) - output.must_match(/destroy DELETE/) + _(output).must_match(/index GET/) + _(output).must_match(/show GET/) + _(output).must_match(/new GET/) + _(output).must_match(/edit GET/) + _(output).must_match(/update (PATCH|PUT)/) + _(output).must_match(/update PUT/) + _(output).must_match(/destroy DELETE/) end it 'returns all routes for controllers under a namespace' do output = mock_pry('find-route Admin', 'exit-all') - output.must_match(/Routes for Admin::UsersController/) - output.must_match(/Routes for Admin::ImagesController/) + _(output).must_match(/Routes for Admin::UsersController/) + _(output).must_match(/Routes for Admin::ImagesController/) end it 'returns no routes found when controller is not recognized' do output = mock_pry('find-route Foo', 'exit-all') - output.must_match(/No routes found/) + _(output).must_match(/No routes found/) end end diff --git a/spec/railtie_spec.rb b/spec/railtie_spec.rb index f456a5f..c4347f3 100644 --- a/spec/railtie_spec.rb +++ b/spec/railtie_spec.rb @@ -35,7 +35,7 @@ def self.start(*) end %w(app helper reload!).each do |helper| - TOPLEVEL_BINDING.eval("respond_to?(:#{helper}, true)").must_equal true + _(TOPLEVEL_BINDING.eval("respond_to?(:#{helper}, true)")).must_equal true end end end diff --git a/spec/recognize_path_spec.rb b/spec/recognize_path_spec.rb index 17a7ed7..697dcc9 100644 --- a/spec/recognize_path_spec.rb +++ b/spec/recognize_path_spec.rb @@ -22,36 +22,36 @@ it 'fails gracefully if no path is given' do output = mock_pry('recognize-path', 'exit-all') - output.must_equal \ - "Error: The command 'recognize-path' requires an argument.\n" + _(output).must_equal \ + "\e[0GError: The command 'recognize-path' requires an argument.\n" end it "prints info about controller/action that is bound to the given path" do output = mock_pry('recognize-path example.com', 'exit-all') - output.must_match(/controller.+foo/) - output.must_match(/action.+index/) + _(output).must_match(/controller.+foo/) + _(output).must_match(/action.+index/) end it "accepts short path" do output = mock_pry('recognize-path /booms/1/edit', 'exit-all') - output.must_match(/action.+edit/) - output.must_match(/controller.+booms/) - output.must_match(/id.+1/) + _(output).must_match(/action.+edit/) + _(output).must_match(/controller.+booms/) + _(output).must_match(/id.+1/) end it "accepts -m switch" do output = mock_pry('recognize-path example.com/booms -m post', 'exit-all') - output.must_match(/controller.+booms/) - output.must_match(/action.+create/) + _(output).must_match(/controller.+booms/) + _(output).must_match(/action.+create/) end it "doesn't accept unknown methods" do output = mock_pry('recognize-path example.com/booms -m posty', 'exit-all') - output.must_match 'Unknown HTTP method: posty' + _(output).must_match 'Unknown HTTP method: posty' end it "doesn't accept unknown routes" do output = mock_pry('recognize-path bing/bang/bong', 'exit-all') - output.must_match 'No route matches "http://bing/bang/bong"' + _(output).must_match 'No route matches "http://bing/bang/bong"' end end diff --git a/spec/show_middleware_spec.rb b/spec/show_middleware_spec.rb index d9206ea..242bb13 100644 --- a/spec/show_middleware_spec.rb +++ b/spec/show_middleware_spec.rb @@ -6,9 +6,9 @@ it "should print a list of middleware" do output = mock_pry('show-middleware', 'exit-all') - output.must_match %r{^use ActionDispatch::Static$} - output.must_match %r{^use ActionDispatch::ShowExceptions$} - output.must_match %r{^run TestApp.routes\Z} + _(output).must_match %r{^use ActionDispatch::Static$} + _(output).must_match %r{^use ActionDispatch::ShowExceptions$} + _(output).must_match %r{^run TestApp.routes\Z} end end diff --git a/spec/show_model_spec.rb b/spec/show_model_spec.rb index abf51c4..98d7480 100644 --- a/spec/show_model_spec.rb +++ b/spec/show_model_spec.rb @@ -7,7 +7,7 @@ output = mock_pry('show-model Beer', 'exit-all') expected = <= 5 + if (Rails::VERSION::MAJOR >= 7 && Rails::VERSION::MINOR >= 2) || Rails::VERSION::MAJOR >= 8 + expected_output = rails_7_2_models + expected_output + elsif Rails::VERSION::MAJOR >= 5 expected_output = internal_models + expected_output end - output.must_equal expected_output + _(output).must_equal expected_output end it "should highlight the given phrase with --grep" do @@ -71,12 +113,12 @@ output = mock_pry('show-models --grep rating', 'exit-all') - output.must_include "Beer" - output.must_include "\e[7mrating\e[27m" - output.wont_include "Pokemon" + _(output).must_include "Beer" + _(output).must_include "\e[7mrating\e[27m" + _(output).wont_include "Pokemon" if defined?(Mongoid) - output.wont_include "Artist" + _(output).wont_include "Artist" end ensure Pry.color = false @@ -86,7 +128,7 @@ if defined?(Mongoid) it "should also filter for mongoid" do output = mock_pry('show-models --grep beer', 'exit-all') - output.must_include 'Artist' + _(output).must_include 'Artist' end end end diff --git a/spec/show_routes_spec.rb b/spec/show_routes_spec.rb index 0647dd9..da7ad15 100644 --- a/spec/show_routes_spec.rb +++ b/spec/show_routes_spec.rb @@ -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.wont_match %r{edit_beer} + _(output).must_match %r{edit_pokemon GET /pokemon/edit} + _(output).wont_match %r{edit_beer} end end