<commit_before>module Spree
  class OptionValue < Spree::Base
    belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_values
    acts_as_list scope: :option_type

    has_many :option_value_variants, class_name: 'Spree::OptionValueVariant'
    has_many :variants, through: :option_value_variants, class_name: 'Spree::Variant'

    validates :name, presence: true, uniqueness: { scope: :option_type_id }
    validates :presentation, presence: true

    after_touch :touch_all_variants

    self.whitelisted_ransackable_attributes = ['presentation']

    def touch_all_variants
      variants.update_all(updated_at: Time.current)
    end
  end
end<commit_msg>Use allow blank to save a query for uniqueness in option_value's name validation<commit_after>module Spree
  class OptionValue < Spree::Base
    belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_values
    acts_as_list scope: :option_type

    has_many :option_value_variants, class_name: 'Spree::OptionValueVariant'
    has_many :variants, through: :option_value_variants, class_name: 'Spree::Variant'

    validates :name, presence: true, uniqueness: { scope: :option_type_id, allow_blank: true }
    validates :presentation, presence: true

    after_touch :touch_all_variants

    self.whitelisted_ransackable_attributes = ['presentation']

    def touch_all_variants
      variants.update_all(updated_at: Time.current)
    end
  end
end
{'fraction_non_alphanumeric': 0.08457374830852503, 'fraction_numerical': 0.0, 'mean_word_length': 5.347639484978541, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1868903', 'n_tokens_mistral': 476, 'n_tokens_neox': 457, 'n_words': 109}