This project is archived and is in readonly mode.
transactions don't fail in 3.0
Reported by Sam Ruby | September 15th, 2009 @ 09:53 PM | in 3.0.2
Section 20.4 of Agile Web Development with Rails describes how transactions can be used to prevent things such as negative balances from being stored in a database. Doing so fails (as expected) in Rails 2.3.4 (and all prior versions of Rails), but doesn't fail (as you would hope it would) with Rails 3.0
Full scenario: http://intertwingly.net/projects/AWDwR3/checkdepot.html#section-20
The script itself is standalone, and I'm attaching it here. To run from a checked out version of Rails, set RUBYLIB as appropriate (see comment in the script); otherwise it will attempt to use the gem version of Rails installed on your system.
Run the script, passing in a single argument of '2' to see the behavior, thus:
ruby transactions.rb 2
Comments and changes to this ticket
-
Jeremy Kemper September 16th, 2009 @ 05:45 AM
- Milestone cleared.
- State changed from new to open
- Assigned user set to Jeremy Kemper
The root problem here is that the 'validate' method isn't being called, so the record saves. Looking into it.
-
Daniel Guettler January 18th, 2010 @ 04:55 AM
The reason why this is failing is because validate is a private method and overriding 'validate' is a deprecated callback. So this calls 'deprecated_callback_method' which checks if the object responds to the passed method. If the method is private it will return false and 'validate' is never executed. If the method is not private validation works fine.
It also works if the new syntax Account.validate(:balance_positive) is used. There it doesn't matter if the method is private or not. -
Daniel Guettler January 18th, 2010 @ 04:57 AM
Upps, this should say: 'validate is defined as private in the given example'...
-
Repository January 18th, 2010 @ 08:57 AM
(from [40c4a0036a690b2e0e3157520f1851efc77fbef7]) Ensure deprecated validate methods are invoked when they are private [#3214 status:resolved] http://github.com/rails/rails/commit/40c4a0036a690b2e0e3157520f1851...
-
José Valim January 18th, 2010 @ 08:59 AM
- State changed from open to resolved
Thanks Daniel, the information you provided helped fix the issue.
-
Jeremy Kemper October 15th, 2010 @ 11:01 PM
- Milestone set to 3.0.2
- Importance changed from to
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 3198 nested resource routes not generated correctly (rails 2.3) [ at the moment, 3.0 has an unrelated failure, which is d...
- 3214 transactions don't fail in 3.0 (from [40c4a0036a690b2e0e3157520f1851efc77fbef7]) Ensure ...