diff --git a/lib/create_or_update.rb b/lib/create_or_update.rb index 1e40311..58272da 100644 --- a/lib/create_or_update.rb +++ b/lib/create_or_update.rb @@ -10,14 +10,14 @@ class ActiveRecord::Base # Returns the record. def self.create_or_update(options = {}) id = options.delete(primary_key.to_sym) - validate = options.delete(:perform_validations) || true + validate = options.delete(:perform_validations){|k| true} record = send("find_by_#{primary_key}", id) || new record.id = id record.attributes = options if validate record.save! else - record.save!(false) + record.save(false) end record end diff --git a/test/db_populate_test.rb b/test/db_populate_test.rb index bf390cc..57b10b4 100644 --- a/test/db_populate_test.rb +++ b/test/db_populate_test.rb @@ -49,7 +49,7 @@ class DbPopulateTest < Test::Unit::TestCase def test_creates_new_record_without_validation Customer.delete_all - Customer.create_or_update(:cust_id => 1, :name => "Me") + Customer.create_or_update(:cust_id => 1, :name => "Me", :perform_validations => false) assert_equal Customer.count, 1 c = Customer.find(:first) assert_equal c.name, "Me"