Skip to content

Commit

Permalink
Merge pull request #51766 from Shopify/revert-actionable-errors-retry
Browse files Browse the repository at this point in the history
Revert "Merge pull request #50941 from andrewn617/actionable-cli"
  • Loading branch information
rafaelfranca committed May 13, 2024
1 parent a4d58dd commit a70d89c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 64 deletions.
20 changes: 0 additions & 20 deletions railties/lib/rails/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,26 +179,6 @@ def invoke_command(command, *) # :nodoc:
ensure
@current_subcommand = original_subcommand
end

protected
def with_actionable_errors_retried(&block)
block.call
rescue ActiveSupport::ActionableError => e
puts e.to_s.strip
exit 1 unless tty?

ActiveSupport::ActionableError.actions(e).each_key do |action_name|
if yes? "#{action_name}? [Yn]"
ActiveSupport::ActionableError.dispatch(e, action_name)
return with_actionable_errors_retried(&block)
end
end
exit 1
end

def tty?
STDOUT.tty?
end
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions railties/lib/rails/commands/test/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def perform(*args)

Rails::TestUnit::Runner.parse_options(args)
run_prepare_task if self.args.none?(EXACT_TEST_ARGUMENT_PATTERN)
with_actionable_errors_retried do
Rails::TestUnit::Runner.run(args)
end
Rails::TestUnit::Runner.run(args)
rescue Rails::TestUnit::InvalidTestError => error
say error.message
end
Expand Down
8 changes: 6 additions & 2 deletions railties/lib/rails/testing/maintain_test_schema.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# frozen_string_literal: true

if defined?(ActiveRecord::Base)

ActiveRecord::Migration.maintain_test_schema!
begin
ActiveRecord::Migration.maintain_test_schema!
rescue ActiveRecord::PendingMigrationError => e
puts e.to_s.strip
exit 1
end

if Rails.configuration.eager_load
ActiveRecord::Base.descendants.each do |model|
Expand Down
39 changes: 0 additions & 39 deletions railties/test/application/test_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,45 +345,6 @@ def self.load_schema!
assert_unsuccessful_run "models/user_test.rb", "SCHEMA LOADED!"
end

def test_actionable_command_line_error_with_tty
rails "generate", "scaffold", "user", "name:string"
app_file "config/initializers/thor_yes.rb", <<-RUBY
Rails::Command::Base.class_eval <<-INITIALIZER
def yes?(statement, color = nil)
raise ArgumentError unless statement == "Run pending migrations? [Yn]"
true
end
def tty?
true
end
INITIALIZER
RUBY

run_test_file("models/user_test.rb").tap do |output|
assert_match "Migrations are pending. To resolve this issue, run:", output
assert_match "CreateUsers: migrating", output
assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
end
end

def test_actionable_command_line_without_tty
rails "generate", "scaffold", "user", "name:string"
app_file "config/initializers/thor_yes.rb", <<-RUBY
Rails::Command::Base.class_eval <<-INITIALIZER
def tty?
false
end
INITIALIZER
RUBY

run_test_file("models/user_test.rb").tap do |output|
assert_match "Migrations are pending. To resolve this issue, run:", output
assert_no_match "CreateUsers: migrating", output
assert_no_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
end
end

private
def assert_unsuccessful_run(name, message)
result = run_test_file(name)
Expand Down

0 comments on commit a70d89c

Please sign in to comment.