Skip to content

Commit

Permalink
missing_presence_validation: ignore columns with default functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Jan 14, 2025
1 parent 7b349fe commit 125af16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def validator_needed?(model, column)
end

def default_value_instead_of_validation?(column)
!column.default.nil? && config(:ignore_columns_with_default)
(!column.default.nil? || column.default_function) && config(:ignore_columns_with_default)
end

def validator_present?(model, column)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_config_ignore_columns_with_default_columns_are_not_ignored_by_default
OUTPUT
end

def test_config_ignore_columns_with_default
def test_config_ignore_columns_with_default_when_using_value
Context.create_table(:users) do |t|
t.integer :posts_count, null: false, default: 0
end.define_model
Expand All @@ -278,4 +278,19 @@ def test_config_ignore_columns_with_default

refute_problems
end

def test_config_ignore_columns_with_default_when_using_function
Context.create_table(:users) do |t|
t.timestamp :started_at, null: false, default: -> { "CURRENT_TIMESTAMP" }
end.define_model

config_file(<<-CONFIG)
ActiveRecordDoctor.configure do |config|
config.detector :missing_presence_validation,
ignore_columns_with_default: true
end
CONFIG

refute_problems
end
end

0 comments on commit 125af16

Please sign in to comment.