Skip to content

Commit 0f69a0d

Browse files
committed
Merge pull request #246 from codeodor/rails3
Fix "normal" validates_uniqueness_of after #122 broke it
2 parents 926c4ff + 48a7137 commit 0f69a0d

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

lib/paranoia.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class UniquenessValidator < ActiveModel::EachValidator
181181
protected
182182
def build_relation_with_paranoia(klass, table, attribute, value)
183183
relation = build_relation_without_paranoia(klass, table, attribute, value)
184-
relation.and(klass.quoted_table_name + ".#{klass.paranoia_column} IS NULL")
184+
relation.and(klass.arel_table[klass.paranoia_column].eq(nil))
185185
end
186186
alias_method_chain :build_relation, :paranoia
187187
end

test/paranoia_test.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def test_restore_with_nil_has_one_association
415415

416416
# Does it raise NoMethodException on restore of nil
417417
hasOne.restore(:recursive => true)
418-
418+
419419
assert hasOne.reload.deleted_at.nil?
420420
end
421421

@@ -434,14 +434,20 @@ def test_observers_not_notified_if_not_supported
434434
a.restore!
435435
# essentially, we're just ensuring that this doesn't crash
436436
end
437-
437+
438438
def test_validates_uniqueness_only_checks_non_deleted_records
439439
a = Employer.create!(name: "A")
440440
a.destroy
441441
b = Employer.new(name: "A")
442442
assert b.valid?
443443
end
444444

445+
def test_validates_uniqueness_still_works_on_non_deleted_records
446+
a = Employer.create!(name: "A")
447+
b = Employer.new(name: "A")
448+
refute b.valid?
449+
end
450+
445451
private
446452
def get_featureful_model
447453
FeaturefulModel.new(:name => 'not empty')

0 commit comments

Comments
 (0)