Skip to content
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 @@ -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