Skip to content

Commit

Permalink
Validates uniqueness of does not care about ids
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Jan 20, 2010
1 parent 61fb666 commit 0799262
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/validatable.rb
@@ -1,5 +1,8 @@
require 'forwardable' require 'forwardable'
require 'rubygems' require 'rubygems'

gem "activesupport", ">= 2.2.2", "< 3.0.pre"

require 'active_support' require 'active_support'


dir = File.expand_path(File.dirname(__FILE__)) dir = File.expand_path(File.dirname(__FILE__))
Expand Down
4 changes: 2 additions & 2 deletions lib/validations/validates_uniqueness_of.rb
Expand Up @@ -8,11 +8,11 @@ def valid?(instance)
conditions.merge!(scope => instance.send(scope)) conditions.merge!(scope => instance.send(scope))
end end
doc = instance.class.first(:conditions => conditions) doc = instance.class.first(:conditions => conditions)
doc.nil? || instance.id == doc.id doc.nil?
end end


def message(instance) def message(instance)
super || "must be unique" super || "must be unique"
end end
end end
end end

0 comments on commit 0799262

Please sign in to comment.