From 7f9fb4e2d21c4df1d2caf547ea63a56c65afdb3a Mon Sep 17 00:00:00 2001 From: Mike Nguyen Date: Mon, 18 Mar 2019 23:01:02 -0700 Subject: [PATCH] Fix bug: scoped attributes of data type time See issue #1114: validate_uniqueness_of with scoped_to fails when the scope is of data type time --- .../matchers/active_record/validate_uniqueness_of_matcher.rb | 2 +- .../active_record/validate_uniqueness_of_matcher_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 ad298b145..85cc81d2b 100644 --- a/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +++ b/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb @@ -820,7 +820,7 @@ def next_scalar_value_for(scope, previous_value) elsif previous_value.respond_to?(:next) previous_value.next elsif previous_value.respond_to?(:to_datetime) - previous_value.to_datetime.next + previous_value.to_datetime.in(60).next elsif boolean_value?(previous_value) !previous_value else diff --git a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb index f39ef9575..95725c93f 100644 --- a/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +++ b/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb @@ -829,6 +829,11 @@ column_type: :datetime end + context 'when one of the scoped attributes is a time column (using Time)' do + include_context 'it supports scoped attributes of a certain type', + column_type: :time + end + context 'when one of the scoped attributes is a datetime column (using Time)' do include_context 'it supports scoped attributes of a certain type', column_type: :datetime,