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

Migration helper module #45

Merged
merged 8 commits into from
Oct 25, 2024
Merged

Conversation

AlasdairWallaceMackie
Copy link
Contributor

@AlasdairWallaceMackie AlasdairWallaceMackie commented Oct 24, 2024

Resolves this issue: #44
Bug was introduced in this PR: #43

Primary Change

IrreversibleMigration will now check if a change block is inside a Sequel.migration block before checking for offenses

New patterns

lib

  • Created new directory: lib/rubocop/cop/sequel/helpers/
    • Within this directory, created module Migration (Can be included via include Helpers::Migration)
      • This helper module contains logic to check if a node is inside a migration, now available for use with other Cops
  • Where relevant, existing cops have been refactored to use this new helper. Now they will check if a node is inside a Sequel.migration block before checking for offenses.

spec

  • Created new directory: spec/rubocop/cop/sequel/helpers
    • Within this directory, created module Migration (Can be included via include Spec::Helpers::Migration)
      • New method: #inspect_source_within_migration
        • This is a wrapper for #inspect_source. Will wrap the source argument within a Sequel.migration block
  • Refactored existing specs with this new method

context 'when a change block is used outside of a Sequel migration' do
let(:source) do
<<~SOURCE
it { expect { subject }.to change { document_count(user_id) }.by(-1) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test case taken directly from the reported issue:
#44

config/default.yml Outdated Show resolved Hide resolved
@@ -5,6 +5,8 @@ module Cop
module Sequel
# IrreversibleMigration looks for methods inside a `change` block that cannot be reversed.
class IrreversibleMigration < Base
include RuboCop::Cop::Sequel::Helpers::Migration
Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to apply this to other migration related cops?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I've updated the PR description with these additional changes, and also created a spec helper module to wrap test code in a Sequel.migration block.

@cyberdelia cyberdelia merged commit ff013a5 into rubocop:master Oct 25, 2024
5 checks passed
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