提交 93717f39 编写于 作者: A Alan Kennedy

Don't autosave unchanged has_one through records

上级 62955c77
* Don't autosave unchanged has_one through records
*Alan Kennedy*, *Steve Parrington*
* When a thread is killed, rollback the active transaction, instead of
committing it during the stack unwind. Previously, we could commit half-
completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
......
......@@ -403,7 +403,9 @@ def save_has_one_association(reflection)
# If the record is new or it has changed, returns true.
def record_changed?(reflection, record, key)
record.new_record? || record[reflection.foreign_key] != key || record.attribute_changed?(reflection.foreign_key)
record.new_record? ||
(record.attributes.keys.include?(reflection.foreign_key) && record[reflection.foreign_key] != key) ||
record.attribute_changed?(reflection.foreign_key)
end
# Saves the associated record if it's new or <tt>:autosave</tt> is enabled.
......
......@@ -19,6 +19,9 @@
require 'models/eye'
require 'models/electron'
require 'models/molecule'
require 'models/member'
require 'models/member_detail'
require 'models/organization'
class TestAutosaveAssociationsInGeneral < ActiveRecord::TestCase
def test_autosave_validation
......@@ -1116,6 +1119,27 @@ def test_should_not_load_the_associated_model
end
end
class TestAutosaveAssociationOnAHasOneThroughAssociation < ActiveRecord::TestCase
self.use_transactional_fixtures = false unless supports_savepoints?
def setup
super
organization = Organization.create
@member = Member.create
MemberDetail.create(organization: organization, member: @member)
end
def test_should_not_has_one_through_model
class << @member.organization
def save(*args)
super
raise 'Oh noes!'
end
end
assert_nothing_raised { @member.save }
end
end
class TestAutosaveAssociationOnABelongsToAssociation < ActiveRecord::TestCase
self.use_transactional_fixtures = false unless supports_savepoints?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册