Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopped unintentional SQL execute. #39003

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,7 +42,7 @@ def delete(method = options[:dependent])
def replace(record, save = true)
raise_on_type_mismatch!(record) if record

return target unless load_target || record
return target unless record || load_target

assigning_another_record = target != record
if assigning_another_record || record.has_changes_to_save?
Expand Down
Expand Up @@ -88,6 +88,14 @@ def test_proxy_assignment
assert_nothing_raised { company.account = company.account }
end

def test_proxy_assignment_from_hash
company = companies(:first_firm)
company_from_hash = Company.new(company.attributes)
attrs = company.account.attributes
sql = capture_sql { company_from_hash.account = Account.new(attrs) }
assert_equal [], sql
end

def test_type_mismatch
assert_raise(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).account = 1 }
assert_raise(ActiveRecord::AssociationTypeMismatch) { companies(:first_firm).account = Project.find(1) }
Expand Down