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 ignoring columns from has_one association for missing_unique_indexes #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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

table_name = has_one.klass.table_name
next if unique_index?(table_name, columns)
Expand Down
20 changes: 20 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 @@ -440,6 +440,26 @@ def test_config_ignore_columns
refute_problems
end

def test_config_ignore_columns_from_has_one
create_table(:users)
.define_model do
has_one :account, class_name: "TransientRecord::Models::Account"
end

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: ["TransientRecord::Models::Account(user_id)"]
end
CONFIG

refute_problems
end

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