Permalink
Browse files

Merge pull request #444 from toptal/fix-bypassing-uniqueness-validators

Fix bypassing uniqueness validators
  • Loading branch information...
jkowens committed Sep 1, 2017
2 parents 34a2b33 + 0f968a7 commit 1e0f5c37dacec9a673585e232042c591e95043d0
@@ -38,7 +38,7 @@ def valid_model?(model)
model.errors.clear
validate_callbacks = model._validate_callbacks.dup
validate_callbacks.each do |callback|
model._validate_callbacks.each do |callback|
validate_callbacks.delete(callback) if callback.raw_filter.is_a? ActiveRecord::Validations::UniquenessValidator
end
View
@@ -121,12 +121,12 @@
end
context "with :validation option" do
let(:columns) { %w(title author_name) }
let(:valid_values) { [["LDAP", "Jerry Carter"], ["Rails Recipes", "Chad Fowler"]] }
let(:valid_values_with_context) { [[1111, "Jerry Carter"], [2222, "Chad Fowler"]] }
let(:invalid_values) { [["The RSpec Book", ""], ["Agile+UX", ""]] }
let(:valid_models) { valid_values.map { |title, author_name| Topic.new(title: title, author_name: author_name) } }
let(:invalid_models) { invalid_values.map { |title, author_name| Topic.new(title: title, author_name: author_name) } }
let(:columns) { %w(title author_name content) }
let(:valid_values) { [["LDAP", "Jerry Carter", "Putting Directories to Work."], ["Rails Recipes", "Chad Fowler", "A trusted collection of solutions."]] }
let(:valid_values_with_context) { [[1111, "Jerry Carter", "1111"], [2222, "Chad Fowler", "2222"]] }
let(:invalid_values) { [["The RSpec Book", "", "Get the most out of BDD in Ruby."], ["Agile+UX", "", "All about Agile in UX."]] }
let(:valid_models) { valid_values.map { |title, author_name, content| Topic.new(title: title, author_name: author_name, content: content) } }
let(:invalid_models) { invalid_values.map { |title, author_name, content| Topic.new(title: title, author_name: author_name, content: content) } }
context "with validation checks turned off" do
it "should import valid data" do
View
@@ -2,6 +2,7 @@ class Topic < ActiveRecord::Base
validates_presence_of :author_name
validates :title, numericality: { only_integer: true }, on: :context_test
validates :title, uniqueness: true
validates :content, uniqueness: true
validate -> { errors.add(:title, :validate_failed) if title == 'validate_failed' }
before_validation -> { errors.add(:title, :invalid) if title == 'invalid' }
@@ -15,6 +15,7 @@
factory :topic do
sequence(:title) { |n| "Title #{n}" }
sequence(:author_name) { |n| "Author #{n}" }
sequence(:content) { |n| "Content #{n}" }
end
factory :widget do
@@ -64,8 +64,8 @@ def should_support_mysql_import_functionality
let(:columns) { %w(id author_name title) }
setup do
topics << Topic.create!(title: "LDAP", author_name: "Big Bird")
topics << Topic.create!(title: "Rails Recipes", author_name: "Elmo")
topics << Topic.create!(title: "LDAP", author_name: "Big Bird", content: "Putting Directories to Work.")
topics << Topic.create!(title: "Rails Recipes", author_name: "Elmo", content: "A trusted collection of solutions.")
end
it "synchronizes passed in ActiveRecord model instances with the data just imported" do

0 comments on commit 1e0f5c3

Please sign in to comment.