Skip to content

Commit

Permalink
Make missing_non_null_constraint skip contextual validators (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored Dec 12, 2024
1 parent c662c8f commit b0d597f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def required_presence_validators(model)
model.validators.select do |validator|
validator.is_a?(ActiveRecord::Validations::PresenceValidator) &&
!validator.options[:allow_nil] &&
validator.options[:on].blank? &&
(rails_belongs_to_presence_validator?(validator) || !conditional_validator?(validator))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ def test_validators_allowing_nil_on_optional_columns_are_allowed
refute_problems
end

def test_validators_with_specific_context_on_optional_columns_are_allowed
Context.create_table(:users) do |t|
t.string :name, null: true
end.define_model do
validates :name, presence: true, on: :create
end

refute_problems
end

def test_models_with_non_existent_tables_are_skipped
Context.define_model(:User)

Expand Down

0 comments on commit b0d597f

Please sign in to comment.