aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test
diff options
context:
space:
mode:
authorYoshiyuki Hirano <yhirano@me.com>2017-09-17 18:24:16 +0900
committerYoshiyuki Hirano <yhirano@me.com>2017-09-19 06:02:00 +0900
commit704bf9b9c64a2f92c6e72d74350bd8f00aaca5c5 (patch)
tree55807438551878c881d32363bfb980ef9e17ffe7 /activestorage/test
parent37be1cb47755a3d0a02eed12ac8cfb377b172f2d (diff)
downloadrails-704bf9b9c64a2f92c6e72d74350bd8f00aaca5c5.tar.gz
rails-704bf9b9c64a2f92c6e72d74350bd8f00aaca5c5.tar.bz2
rails-704bf9b9c64a2f92c6e72d74350bd8f00aaca5c5.zip
Add `with_attached_*` scope to `has_one_attached` macro
* For avoiding N+1 problem, added `with_attached_*` scope to `has_one_attached` macro.
Diffstat (limited to 'activestorage/test')
-rw-r--r--activestorage/test/models/attachments_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activestorage/test/models/attachments_test.rb b/activestorage/test/models/attachments_test.rb
index ac346c0087..379ae0a416 100644
--- a/activestorage/test/models/attachments_test.rb
+++ b/activestorage/test/models/attachments_test.rb
@@ -84,6 +84,19 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
end
end
+ test "find with attached blob" do
+ records = %w[alice bob].map do |name|
+ User.create!(name: name).tap do |user|
+ user.avatar.attach create_blob(filename: "#{name}.jpg")
+ end
+ end
+
+ users = User.where(id: records.map(&:id)).with_attached_avatar.all
+
+ assert_equal "alice.jpg", users.first.avatar.filename.to_s
+ assert_equal "bob.jpg", users.second.avatar.filename.to_s
+ end
+
test "attach existing blobs" do
@user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "wonky.jpg")