Skip to content

Commit

Permalink
Merge 1de967c into 24576b3
Browse files Browse the repository at this point in the history
  • Loading branch information
abraham-chan committed Jul 1, 2021
2 parents 24576b3 + 1de967c commit d5d2312
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -310,6 +310,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 a 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;
Expand Down
46 changes: 46 additions & 0 deletions 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
12 changes: 12 additions & 0 deletions 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)

0 comments on commit d5d2312

Please sign in to comment.