Skip to content

Commit 6111523

Browse files
#1210: Add rule 'rails_migrations_pending'
* Add rule 'rails_migrations_pending' * Update thefuck/rules/rails_migrations_pending.py Co-authored-by: Pablo Aguiar <[email protected]> * Add initial command to corrected command Co-authored-by: Pablo Aguiar <[email protected]>
1 parent 24576b3 commit 6111523

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ following rules are enabled by default:
310310
* `python_module_error` &ndash; fixes ModuleNotFoundError by trying to `pip install` that module;
311311
* `quotation_marks` &ndash; fixes uneven usage of `'` and `"` when containing args';
312312
* `path_from_history` &ndash; replaces not found path with a similar absolute path from history;
313+
* `rails_migrations_pending` &ndash; runs pending migrations;
313314
* `react_native_command_unrecognized` &ndash; fixes unrecognized `react-native` commands;
314315
* `remove_shell_prompt_literal` &ndash; remove leading shell prompt symbol `$`, common when copying commands from documentations;
315316
* `remove_trailing_cedilla` &ndash; remove trailing cedillas `ç`, a common typo for European keyboard layouts;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import pytest
2+
from thefuck.rules.rails_migrations_pending import match, get_new_command
3+
from thefuck.types import Command
4+
5+
output_env_development = '''
6+
Migrations are pending. To resolve this issue, run:
7+
8+
rails db:migrate RAILS_ENV=development
9+
'''
10+
output_env_test = '''
11+
Migrations are pending. To resolve this issue, run:
12+
13+
bin/rails db:migrate RAILS_ENV=test
14+
'''
15+
16+
17+
@pytest.mark.parametrize(
18+
"command",
19+
[
20+
Command("", output_env_development),
21+
Command("", output_env_test),
22+
],
23+
)
24+
def test_match(command):
25+
assert match(command)
26+
27+
28+
@pytest.mark.parametrize(
29+
"command",
30+
[
31+
Command("Environment data not found in the schema. To resolve this issue, run: \n\n", ""),
32+
],
33+
)
34+
def test_not_match(command):
35+
assert not match(command)
36+
37+
38+
@pytest.mark.parametrize(
39+
"command, new_command",
40+
[
41+
(Command("bin/rspec", output_env_development), "rails db:migrate RAILS_ENV=development && bin/rspec"),
42+
(Command("bin/rspec", output_env_test), "bin/rails db:migrate RAILS_ENV=test && bin/rspec"),
43+
],
44+
)
45+
def test_get_new_command(command, new_command):
46+
assert get_new_command(command) == new_command
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import re
2+
from thefuck.shells import shell
3+
4+
5+
SUGGESTION_REGEX = r"To resolve this issue, run:\s+(.*?)\n"
6+
7+
8+
def match(command):
9+
return "Migrations are pending. To resolve this issue, run:" in command.output
10+
11+
12+
def get_new_command(command):
13+
migration_script = re.search(SUGGESTION_REGEX, command.output).group(1)
14+
return shell.and_(migration_script, command.script)

0 commit comments

Comments
 (0)