Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule 'rails_migrations_pending' #1210

Merged
merged 4 commits into from
Jul 6, 2021

Conversation

abraham-chan
Copy link
Contributor

Add rule to fix a common Rails issue when running tests.

Rails source code that generates the message: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/migration.rb#L152

Example output on my console:

abrahamchan [master] > bin/rspec     
Running via Spring preloader in process 35661
Migrations are pending. To resolve this issue, run:

        rails db:migrate RAILS_ENV=test
No examples found.

abrahamchan [master] > fuck
rails db:migrate RAILS_ENV=test [enter/↑/↓/ctrl+c]
== 20210627174953 Example: migrating ==========================================
== 20210627174953 Example: migrated (0.0000s) =================================

abrahamchan [master] > bin/rspec
[successful rspec output]

Copy link
Collaborator

@scorphus scorphus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks.

Please consider my sugestion below.

thefuck/rules/rails_migrations_pending.py Outdated Show resolved Hide resolved
Comment on lines 41 to 42
(Command("", output_env_development), "rails db:migrate RAILS_ENV=development"),
(Command("", output_env_test), "bin/rails db:migrate RAILS_ENV=test"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing it again, I thought that the corrected command could include the one initially intended by the user.

Suggested change
(Command("", output_env_development), "rails db:migrate RAILS_ENV=development"),
(Command("", output_env_test), "bin/rails db:migrate RAILS_ENV=test"),
(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"),

Make sure to use shell._and to join the commands together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done

thefuck/rules/rails_migrations_pending.py Show resolved Hide resolved
Copy link
Collaborator

@scorphus scorphus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, @abraham-chan! Thanks for contributing! :shipit:

@scorphus scorphus merged commit 6111523 into nvbn:master Jul 6, 2021
@scorphus scorphus added this to the 3.32 milestone Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants