1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-05 18:31:10 +01:00

#1210: Add rule 'rails_migrations_pending'

* Add rule 'rails_migrations_pending'

* Update thefuck/rules/rails_migrations_pending.py

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>

* Add initial command to corrected command

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
This commit is contained in:
Abraham Chan 2021-07-06 03:52:54 -07:00 committed by GitHub
parent 24576b30b2
commit 6111523034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 0 deletions

View File

@ -310,6 +310,7 @@ following rules are enabled by default:
* `python_module_error` &ndash; fixes ModuleNotFoundError by trying to `pip install` that module;
* `quotation_marks` &ndash; fixes uneven usage of `'` and `"` when containing args';
* `path_from_history` &ndash; replaces not found path with a similar absolute path from history;
* `rails_migrations_pending` &ndash; runs pending migrations;
* `react_native_command_unrecognized` &ndash; fixes unrecognized `react-native` commands;
* `remove_shell_prompt_literal` &ndash; remove leading shell prompt symbol `$`, common when copying commands from documentations;
* `remove_trailing_cedilla` &ndash; remove trailing cedillas `ç`, a common typo for European keyboard layouts;

View File

@ -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("bin/rspec", output_env_development), "rails db:migrate RAILS_ENV=development && bin/rspec"),
(Command("bin/rspec", output_env_test), "bin/rails db:migrate RAILS_ENV=test && bin/rspec"),
],
)
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command

View File

@ -0,0 +1,14 @@
import re
from thefuck.shells import shell
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):
migration_script = re.search(SUGGESTION_REGEX, command.output).group(1)
return shell.and_(migration_script, command.script)