Navigation Menu

Skip to content

Commit

Permalink
fix for superfluous Rollback exception on failed validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Dirolf committed Aug 27, 2009
1 parent 5336f2a commit 2496b18
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/mongo_record/active_record/connection_adapters.rb
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/models/user.rb
@@ -1,3 +1,4 @@
class User < ActiveRecord::Base
validates_presence_of :name
end

18 changes: 18 additions & 0 deletions test/mongo_record_test.rb
Expand Up @@ -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.