-
-
Notifications
You must be signed in to change notification settings - Fork 263
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
Rails/UniqueValidationWithoutIndex keeps failing even if the issue has been resolved #227
Labels
bug
Something isn't working
Comments
Same problem with scoped uniqueness. |
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 8, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following API: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239
8 tasks
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 8, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following API: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 8, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following method: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 8, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following method: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 8, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following method: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 9, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following method: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239
koic
added a commit
to koic/rubocop-rails
that referenced
this issue
Apr 9, 2020
…updating schema.rb Fixes rubocop#227. This PR makes `Rails/UniqueValidationWithoutIndex` aware of updating db/schema.rb `Rails/UniqueValidationWithoutIndex` cop needs to know both model and db/schema.rb changes to register an offense. However, with default RuboCop, only changes to the model affect cache behavior. This PR ensures that changes to db/schema.rb affect the cache by overriding the following method: ```ruby # This method should be overridden when a cop's behavior depends # on state that lives outside of these locations: # # (1) the file under inspection # (2) the cop's source code # (3) the config (eg a .rubocop.yml file) # # For example, some cops may want to look at other parts of # the codebase being inspected to find violations. A cop may # use the presence or absence of file `foo.rb` to determine # whether a certain violation exists in `bar.rb`. # # Overriding this method allows the cop to indicate to RuboCop's # ResultCache system when those external dependencies change, # ie when the ResultCache should be invalidated. def external_dependency_checksum nil end ``` https://github.com/rubocop-hq/rubocop/blob/v0.81.0/lib/rubocop/cop/cop.rb#L222-L239 See for more details: rubocop/rubocop#7496
koic
added a commit
that referenced
this issue
Apr 9, 2020
…x_aware_schema [Fix #227] Make `Rails/UniqueValidationWithoutIndex` aware of updating schema.rb
RuboCop Rails 2.5.2 has been released to solve this issue. Thanks for the feedback. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected behavior
I expect the cop to detect that
schema.rb
has changed and I expect it to run the cop again.Actual behavior
The cop keeps failing until I change the offending file. Adding or removing any character will do the trick. I'm pretty confident that [caching])https://github.com/rubocop-hq/rubocop/blob/master/manual/caching.md) is the issue. My guess is that it stores a result with a key that is a hash of the file it is testing; but I think that should be a hash of
[the_file_that_is_being_tested, schema.rb]
for this cop since the outcome is dependent on both files.I can resolve the issue by deleting the rubocop cache:
Steps to reproduce the problem
Run rubocop; see that it fails the test.
Create a migration to add the missing index.
Run the migration
Run rubocop; see that it still fails the test.
Remove the cache
On macOs without XDG-DIRS set:
RuboCop version
The text was updated successfully, but these errors were encountered: