Skip to content
Browse files

fix for superfluous Rollback exception on failed validation

  • Loading branch information...
1 parent 5336f2a commit 2496b18efffbe4d8ac01726635c2c1185706e0ee Mike Dirolf committed Aug 27, 2009
Showing with 23 additions and 1 deletion.
  1. +4 −1 lib/mongo_record/active_record/connection_adapters.rb
  2. +1 −0 test/models/user.rb
  3. +18 −0 test/mongo_record_test.rb
View
5 lib/mongo_record/active_record/connection_adapters.rb
@@ -85,7 +85,10 @@ def supports_count_distinct?
# Transactions are not yet supported by Mongo, so this method simply
# yields to the given block.
def transaction(start_db_transaction=true)
- yield
+ begin
+ yield
+ rescue ActiveRecord::Rollback
+ end
end
# Enable the query cache within the block. Ignored.
View
1 test/models/user.rb
@@ -1,3 +1,4 @@
class User < ActiveRecord::Base
+ validates_presence_of :name
end
View
18 test/mongo_record_test.rb
@@ -251,4 +251,22 @@ def test_update
assert_equal "bar", v.name
end
+ def test_validation
+ assert_equal 1, User.count
+
+ u = User.new
+ u.name = "foobar"
+ u.save
+ assert u.errors.empty?
+
+ assert_equal 2, User.count
+
+ u = User.new
+ u.password = "foobar"
+ u.save
+ assert !u.errors.empty?
+
+ assert_equal 2, User.count
+ end
+
end

0 comments on commit 2496b18

Please sign in to comment.
Something went wrong with that request. Please try again.