DEV: uses `in: {}` with lambda to work with `eager_load` (#25039)
When validating with a dynamic set of values, especially one that might change during runtime, we should use a lambda or a proc to ensure that the validation uses the most up-to-date set of values. This is particularly important when using config.eager_load = true, which can cause some elements to be loaded only once at startup, thus not reflecting changes made at runtime. This was the root cause of the issues here, as we were adding more ReviewableScore types after initial load through: `register_reviewable_type Chat::ReviewableMessage`
This commit is contained in:
parent
6e8c2bb4ab
commit
40ce619edd
|
@ -40,7 +40,7 @@ module Chat
|
|||
validates :channel_id, presence: true
|
||||
|
||||
attribute :flag_type_id, :integer
|
||||
validates :flag_type_id, inclusion: { in: ::ReviewableScore.types.values }
|
||||
validates :flag_type_id, inclusion: { in: ->(_flag_type) { ::ReviewableScore.types.values } }
|
||||
|
||||
attribute :message, :string
|
||||
attribute :is_warning, :boolean
|
||||
|
|
|
@ -8,7 +8,6 @@ RSpec.describe Chat::FlagMessage do
|
|||
it { is_expected.to validate_presence_of(:message_id) }
|
||||
|
||||
it do
|
||||
skip("TODO: This does not work in CI when eager load is set to true") if ENV["CI"]
|
||||
is_expected.to validate_inclusion_of(:flag_type_id).in_array(ReviewableScore.types.values)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue