Skip to content
Closed
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 @@ -81,7 +81,8 @@ def presence_validator_present?(model, column)
allowed_attributes = [column.name.to_sym]

belongs_to = model.reflect_on_all_associations(:belongs_to).find do |reflection|
reflection.foreign_key == column.name
reflection.foreign_key == column.name ||
(reflection.polymorphic? && reflection.foreign_type == column.name)
end
allowed_attributes << belongs_to.name.to_sym if belongs_to

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ def test_non_null_column_is_not_reported_if_association_validation_present
refute_problems
end

def test_non_null_type_column_is_not_reported_if_association_validation_present
Context.create_table(:comments) do |t|
t.integer :commentable_id, null: false
t.string :commentable_type, null: false
end.define_model do
belongs_to :commentable, polymorphic: true, required: true
end

refute_problems
end

def test_not_null_column_is_not_reported_if_habtm_association
Context.create_table(:users).define_model do
has_and_belongs_to_many :projects, class_name: "Context::Project"
Expand Down
Loading