Permalink
Browse files

when using paranoia, validate uniquness ignore deleted

  • Loading branch information...
dot committed Jun 14, 2012
1 parent 961d7ca commit 11c4468e5eafa2bf7762b9a65fa4af752fde8464
Showing with 24 additions and 1 deletion.
  1. +1 −1 lib/mongoid/validations/uniqueness.rb
  2. +23 −0 spec/unit/mongoid/validations/uniqueness_spec.rb
@@ -101,7 +101,7 @@ def case_sensitive?
# @since 2.4.10
def create_criteria(base, document, attribute, value)
field = document.fields[attribute.to_s]
criteria = base.unscoped
criteria = base.paranoid ? base.unscoped.where(:deleted_at => nil) : base.unscoped
if field.try(:localized?)
criterion(document, attribute, value).each_pair do |key, value|
criteria.selector.store(key, value)
@@ -134,6 +134,29 @@
end
end
context "when using paranoia" do
before do
Dictionary.class_eval do
include Mongoid::Paranoia
validates_uniqueness_of :name
end
end
context "when the document is unique in not deleted" do
before do
Dictionary.create(name: "Oxford").destroy
end
let(:dictionary) do
Dictionary.new(name: "Oxford")
end
it "returns true" do
dictionary.should be_valid
end
end
end
context "when the document is embedded" do
let(:word) do

0 comments on commit 11c4468

Please sign in to comment.