Skip to content
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.
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 @@ -36,6 +36,9 @@ def detect
model_maximum = maximum_allowed_by_validations(model, column.name.to_sym)
next if model_maximum == column.limit

# Add violation only to the root model of STI.
next if (model_maximum.nil? || column.limit.nil?) && sti_subclass?(model)

problem!(
model: model.name,
attribute: column.name,
Expand All @@ -55,6 +58,11 @@ def maximum_allowed_by_validations(model, column)
end
length_validator ? length_validator.options[:maximum] : nil
end

def sti_subclass?(model)
model.columns_hash.include?(model.inheritance_column.to_s) &&
model.base_class != model
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def test_no_validation_and_limit_is_error
OUTPUT
end

def test_sti_subclasses_are_ignored
Context.create_table(:users) do |t|
t.string :email, limit: 64
t.string :type, null: false
end.define_model do
end

Context.define_model(:Client, Context::User)

assert_problems(<<~OUTPUT)
the schema limits users.email to 64 characters but there's no length validator on Context::User.email - remove the database limit or add the validator
OUTPUT
end

def test_no_validation_and_no_limit_is_ok
require_arbitrary_long_text_columns!

Expand Down
Loading