diff --git a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb index 039e65a21..6dbdb5997 100644 --- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb @@ -591,20 +591,7 @@ def dummy_value_for(scope) end def dummy_scalar_value_for(column) - case column.type - when :integer - 0 - when :date - Date.today - when :datetime - DateTime.now - when :uuid - SecureRandom.uuid - when :boolean - true - else - 'dummy value' - end + Shoulda::Matchers::Util.dummy_value_for(column.type) end def next_value_for(scope, previous_value) diff --git a/lib/shoulda/matchers/util.rb b/lib/shoulda/matchers/util.rb index f3539a698..bc3687530 100644 --- a/lib/shoulda/matchers/util.rb +++ b/lib/shoulda/matchers/util.rb @@ -50,6 +50,29 @@ def self.inspect_values(values) def self.inspect_range(range) "#{inspect_value(range.first)} to #{inspect_value(range.last)}" end + + def self.dummy_value_for(column_type, array: false) + if array + [dummy_value_for(column_type, array: false)] + else + case column_type + when :integer + 0 + when :date + Date.new(2100, 1, 1) + when :datetime, :timestamp + DateTime.new(2100, 1, 1) + when :time + Time.new(2100, 1, 1) + when :uuid + SecureRandom.uuid + when :boolean + true + else + 'dummy value' + end + end + end end end end