From 9d0c74e4bfc2a1abb509cc4bdc1756ffdb561b9d Mon Sep 17 00:00:00 2001 From: Steve Madsen Date: Tue, 20 Sep 2011 10:51:57 -0400 Subject: [PATCH] Fallback when previous_value doesn't respond to #next. For example, floating point attributes won't respond to #next, so in this case fall back to adding 1. This is not perfect, but it seems to rarely occur in practice since I wasn't able to find anyone else complaining about it. --- .../matchers/active_model/validate_uniqueness_of_matcher.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb b/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb index 3ec596831..cb1c31ef1 100644 --- a/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb +++ b/lib/shoulda/matchers/active_model/validate_uniqueness_of_matcher.rb @@ -116,7 +116,11 @@ def validate_after_scope_change # Assume the scope is a foreign key if the field is nil previous_value ||= 0 - next_value = previous_value.next + next_value = if previous_value.respond_to?(:next) + previous_value.next + else + previous_value + 1 + end @subject.send("#{scope}=", next_value)