Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverts breaking behaviour introduced in v2.1.4 #277

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,3 @@ def paranoia_sentinel_value
end

require 'paranoia/rspec' if defined? RSpec

module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator
protected
def build_relation_with_paranoia(klass, table, attribute, value)
relation = build_relation_without_paranoia(klass, table, attribute, value)
return relation unless klass.respond_to?(:paranoia_column)
relation.and(klass.arel_table[klass.paranoia_column].eq(klass.paranoia_sentinel_value))
end
alias_method_chain :build_relation, :paranoia
end
end
end
8 changes: 4 additions & 4 deletions test/paranoia_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ def test_active_column_model
assert_equal 1, model.class.deleted.count
end

def test_active_column_model_with_uniqueness_validation_only_checks_non_deleted_records
def test_active_column_model_with_uniqueness_validation_checks_all_records
a = ActiveColumnModelWithUniquenessValidation.create!(name: "A")
a.destroy
b = ActiveColumnModelWithUniquenessValidation.new(name: "A")
assert b.valid?
refute b.valid?
end

def test_active_column_model_with_uniqueness_validation_still_works_on_non_deleted_records
Expand Down Expand Up @@ -744,11 +744,11 @@ def test_observers_not_notified_if_not_supported
# essentially, we're just ensuring that this doesn't crash
end

def test_validates_uniqueness_only_checks_non_deleted_records
def test_validates_uniqueness_checks_all_records
a = Employer.create!(name: "A")
a.destroy
b = Employer.new(name: "A")
assert b.valid?
refute b.valid?
end

def test_validates_uniqueness_still_works_on_non_deleted_records
Expand Down