未验证 提交 eb5f5ed0 编写于 作者: L Lawrence Chou 提交者: GitHub

Fix attaching blobs via nested attributes

Closes #37411.
上级 b39ea7cc
......@@ -65,7 +65,7 @@ def find_or_build_blob
**attachable.reverse_merge(
record: record,
service_name: attachment_service_name
)
).symbolize_keys
)
when String
ActiveStorage::Blob.find_signed!(attachable, record: record)
......
......@@ -319,6 +319,13 @@ def upload.open
assert_equal 2736, @user.avatar.metadata[:height]
end
test "creating an attachment as part of an autosave association through nested attributes" do
group = Group.create!(users_attributes: [{ name: "John", avatar: { io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg" } }])
group.save!
new_user = User.find_by(name: "John")
assert new_user.avatar.attached?
end
test "updating an attachment as part of an autosave association" do
group = Group.create!(users: [@user])
@user.avatar = fixture_file_upload("racecar.jpg")
......
......@@ -127,6 +127,8 @@ class User < ActiveRecord::Base
class Group < ActiveRecord::Base
has_one_attached :avatar
has_many :users, autosave: true
accepts_nested_attributes_for :users
end
require_relative "../../tools/test_common"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册