Commit d4dcf1b3 authored by Reuben Pereira's avatar Reuben Pereira

Remove allows_nil: false setting in default_value_for

The default_value_for gem uses the `<column>_changed?` method
to determine if the default value should be applied. For new records,
the `<column>_changed?` method returns false if the value of the
column is the same as the database default.

One workaround is to remove the `allows_nil: false` in the
`default_value_for` setting for container_registry_access_level so
that default_value_for does not overwrite the database default value.

This bug should be fixed by
https://github.com/FooBarWidget/default_value_for/pull/90.

The container_registry_access_level column has a null: false
constraint, so removing the allows_nil: false from the
default_value_for should not be a problem.
parent ee2778b5
......@@ -79,7 +79,7 @@ class ProjectFeature < ApplicationRecord
end
end
default_value_for(:container_registry_access_level, allows_nil: false) do |feature|
default_value_for(:container_registry_access_level) do |feature|
if gitlab_config_features.container_registry
ENABLED
else
......
......@@ -67,21 +67,11 @@ FactoryBot.define do
pages_access_level: evaluator.pages_access_level,
metrics_dashboard_access_level: evaluator.metrics_dashboard_access_level,
operations_access_level: evaluator.operations_access_level,
analytics_access_level: evaluator.analytics_access_level
analytics_access_level: evaluator.analytics_access_level,
container_registry_access_level: evaluator.container_registry_access_level
}
project.build_project_feature(hash)
# This is not included in the `hash` above because the default_value_for in
# the ProjectFeature model overrides the value set by `build_project_feature` when
# evaluator.container_registry_access_level == ProjectFeature::DISABLED.
#
# This is because the default_value_for gem uses the <column>_changed? method
# to determine if the default value should be applied. For new records,
# <column>_changed? returns false if the value of the column is the same as
# the database default.
# See https://github.com/FooBarWidget/default_value_for/blob/release-3.4.0/lib/default_value_for.rb#L158.
project.project_feature.container_registry_access_level = evaluator.container_registry_access_level
end
after(:create) do |project, evaluator|
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment