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

Fix missing_unique_indexes detector's ignore_columns config for has_one associations #153

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def has_ones_without_indexes # rubocop:disable Naming/PredicateName
else
[has_one.foreign_key.to_s]
end
next if ignored?("#{model.name}(#{columns.join(',')})", ignore_columns)
next if ignored?("#{has_one.klass.name}(#{columns.join(',')})", ignore_columns)

table_name = has_one.klass.table_name
next if unique_index?(table_name, columns)
Expand Down
19 changes: 19 additions & 0 deletions test/active_record_doctor/detectors/missing_unique_indexes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,25 @@ def test_config_ignore_columns
refute_problems
end

def test_config_ignore_columns_for_has_one
Context.create_table(:users).define_model do
has_one :account, class_name: "Context::Account"
end

Context.create_table(:accounts) do |t|
t.integer :user_id
end.define_model

config_file(<<-CONFIG)
ActiveRecordDoctor.configure do |config|
config.detector :missing_unique_indexes,
ignore_columns: ["Context::Account(user_id)"]
end
CONFIG

refute_problems
end

class DummyValidator < ActiveModel::Validator
def validate(record)
end
Expand Down