From 5963766d840ddcdb577a1bd10eb1491a4ef9132f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 9 Jul 2017 18:48:26 +0200 Subject: Explore regular polymorphic associations rather than record_gid --- test/models/attachments_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/models') diff --git a/test/models/attachments_test.rb b/test/models/attachments_test.rb index c0f5db819d..1a9fc6f932 100644 --- a/test/models/attachments_test.rb +++ b/test/models/attachments_test.rb @@ -68,6 +68,14 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase assert_equal "country.jpg", @user.highlights.second.filename.to_s end + test "find attached blobs" do + @user.highlights.attach( + { io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg" }, + { io: StringIO.new("IT"), filename: "country.jpg", content_type: "image/jpg" }) + + User.where(id: @user.id).includes(highlights_attachments: :blob).first + end + test "purge attached blobs" do @user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "wonky.jpg") highlight_keys = @user.highlights.collect(&:key) -- cgit v1.2.3 From a4f36f957e013f6da34e04f0d3f1d86d86491454 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 23 Jul 2017 21:41:16 +0200 Subject: Fix attaching with standard Rails associations. Removes needless ivar caching (a Rails association handles that). Inserts a reload and a nil assign, since the association proxy doesn't seem to that it's been destroyed through `purge`. --- test/models/attachments_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/models') diff --git a/test/models/attachments_test.rb b/test/models/attachments_test.rb index 1a9fc6f932..45f62b0bbf 100644 --- a/test/models/attachments_test.rb +++ b/test/models/attachments_test.rb @@ -70,9 +70,9 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase test "find attached blobs" do @user.highlights.attach( - { io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg" }, + { io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg" }, { io: StringIO.new("IT"), filename: "country.jpg", content_type: "image/jpg" }) - + User.where(id: @user.id).includes(highlights_attachments: :blob).first end -- cgit v1.2.3 From 68b5d274a365c1babdb92dedfcf2e600138be5eb Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 23 Jul 2017 16:47:11 -0500 Subject: Add and test preloading scope --- test/models/attachments_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/models') diff --git a/test/models/attachments_test.rb b/test/models/attachments_test.rb index 45f62b0bbf..eac3cbe680 100644 --- a/test/models/attachments_test.rb +++ b/test/models/attachments_test.rb @@ -73,7 +73,10 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase { io: StringIO.new("STUFF"), filename: "town.jpg", content_type: "image/jpg" }, { io: StringIO.new("IT"), filename: "country.jpg", content_type: "image/jpg" }) - User.where(id: @user.id).includes(highlights_attachments: :blob).first + highlights = User.where(id: @user.id).with_attached_highlights.first.highlights + + assert_equal "town.jpg", highlights.first.filename.to_s + assert_equal "country.jpg", highlights.second.filename.to_s end test "purge attached blobs" do -- cgit v1.2.3