From f85bed592e97ac7367e72415c9660519d33ede1b Mon Sep 17 00:00:00 2001 From: Abraham Chan Date: Sun, 27 Jun 2021 17:04:29 -0700 Subject: [PATCH 1/2] Add rule 'rails_migrations_pending' --- README.md | 1 + tests/rules/test_rails_migrations_pending.py | 46 ++++++++++++++++++++ thefuck/rules/rails_migrations_pending.py | 12 +++++ 3 files changed, 59 insertions(+) create mode 100644 tests/rules/test_rails_migrations_pending.py create mode 100644 thefuck/rules/rails_migrations_pending.py diff --git a/README.md b/README.md index 4f396ce95..183643ebc 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,7 @@ following rules are enabled by default: * `python_module_error` – fixes ModuleNotFoundError by trying to `pip install` that module; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args'; * `path_from_history` – replaces not found path with similar absolute path from history; +* `rails_migrations_pending` – runs pending migrations; * `react_native_command_unrecognized` – fixes unrecognized `react-native` commands; * `remove_shell_prompt_literal` – remove leading shell prompt symbol `$`, common when copying commands from documentations; * `remove_trailing_cedilla` – remove trailing cedillas `รง`, a common typo for european keyboard layouts; diff --git a/tests/rules/test_rails_migrations_pending.py b/tests/rules/test_rails_migrations_pending.py new file mode 100644 index 000000000..735b3f3de --- /dev/null +++ b/tests/rules/test_rails_migrations_pending.py @@ -0,0 +1,46 @@ +import pytest +from thefuck.rules.rails_migrations_pending import match, get_new_command +from thefuck.types import Command + +output_env_development = ''' +Migrations are pending. To resolve this issue, run: + + rails db:migrate RAILS_ENV=development +''' +output_env_test = ''' +Migrations are pending. To resolve this issue, run: + + bin/rails db:migrate RAILS_ENV=test +''' + + +@pytest.mark.parametrize( + "command", + [ + Command("", output_env_development), + Command("", output_env_test), + ], +) +def test_match(command): + assert match(command) + + +@pytest.mark.parametrize( + "command", + [ + Command("Environment data not found in the schema. To resolve this issue, run: \n\n", ""), + ], +) +def test_not_match(command): + assert not match(command) + + +@pytest.mark.parametrize( + "command, new_command", + [ + (Command("", output_env_development), "rails db:migrate RAILS_ENV=development"), + (Command("", output_env_test), "bin/rails db:migrate RAILS_ENV=test"), + ], +) +def test_get_new_command(command, new_command): + assert get_new_command(command) == new_command diff --git a/thefuck/rules/rails_migrations_pending.py b/thefuck/rules/rails_migrations_pending.py new file mode 100644 index 000000000..378fae081 --- /dev/null +++ b/thefuck/rules/rails_migrations_pending.py @@ -0,0 +1,12 @@ +import re + + +SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n" + + +def match(command): + return ("Migrations are pending. To resolve this issue, run:" in command.output) + + +def get_new_command(command): + return re.search(SUGGESTION_REGEX, command.output).group(1) From 1de967cd15f83f2629c909c4ff5706c8290610ba Mon Sep 17 00:00:00 2001 From: Abraham Chan Date: Thu, 1 Jul 2021 16:50:33 -0700 Subject: [PATCH 2/2] Update thefuck/rules/rails_migrations_pending.py Co-authored-by: Pablo Aguiar --- thefuck/rules/rails_migrations_pending.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thefuck/rules/rails_migrations_pending.py b/thefuck/rules/rails_migrations_pending.py index 378fae081..234b27767 100644 --- a/thefuck/rules/rails_migrations_pending.py +++ b/thefuck/rules/rails_migrations_pending.py @@ -5,7 +5,7 @@ def match(command): - return ("Migrations are pending. To resolve this issue, run:" in command.output) + return "Migrations are pending. To resolve this issue, run:" in command.output def get_new_command(command):