diff options
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/database/setup.rb | 3 | ||||
-rw-r--r-- | activestorage/test/service/azure_storage_service_test.rb | 9 | ||||
-rw-r--r-- | activestorage/test/template/image_tag_test.rb | 40 |
3 files changed, 49 insertions, 3 deletions
diff --git a/activestorage/test/database/setup.rb b/activestorage/test/database/setup.rb index b12038ee68..610b927cc3 100644 --- a/activestorage/test/database/setup.rb +++ b/activestorage/test/database/setup.rb @@ -1,6 +1,5 @@ -require "active_storage/migration" require_relative "create_users_migration" ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") -ActiveStorageCreateTables.migrate(:up) +ActiveRecord::Migrator.migrate File.expand_path("../../../db/migrate", __FILE__) ActiveStorageCreateUsers.migrate(:up) diff --git a/activestorage/test/service/azure_storage_service_test.rb b/activestorage/test/service/azure_storage_service_test.rb index e2be510b60..a0c6a4de73 100644 --- a/activestorage/test/service/azure_storage_service_test.rb +++ b/activestorage/test/service/azure_storage_service_test.rb @@ -6,8 +6,15 @@ if SERVICE_CONFIGURATIONS[:azure] SERVICE = ActiveStorage::Service.configure(:azure, SERVICE_CONFIGURATIONS) include ActiveStorage::Service::SharedServiceTests - end + test "signed URL generation" do + url = @service.url(FIXTURE_KEY, expires_in: 5.minutes, + disposition: :inline, filename: "avatar.png", content_type: "image/png") + + assert_match(/(\S+)&rsct=image%2Fpng&rscd=inline%3B\+filename%3D%22avatar.png/, url) + assert_match SERVICE_CONFIGURATIONS[:azure][:container], url + end + end else puts "Skipping Azure Storage Service tests because no Azure configuration was supplied" end diff --git a/activestorage/test/template/image_tag_test.rb b/activestorage/test/template/image_tag_test.rb new file mode 100644 index 0000000000..83c95c01a1 --- /dev/null +++ b/activestorage/test/template/image_tag_test.rb @@ -0,0 +1,40 @@ +require "test_helper" +require "database/setup" + +class User < ActiveRecord::Base + has_one_attached :avatar +end + +class ActiveStorage::ImageTagTest < ActionView::TestCase + tests ActionView::Helpers::AssetTagHelper + + setup do + @blob = create_image_blob filename: "racecar.jpg" + end + + test "blob" do + assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url @blob}" />), image_tag(@blob) + end + + test "variant" do + variant = @blob.variant(resize: "100x100") + assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url variant}" />), image_tag(variant) + end + + test "attachment" do + attachment = ActiveStorage::Attachment.new(blob: @blob) + assert_dom_equal %(<img alt="Racecar" src="#{polymorphic_url attachment}" />), image_tag(attachment) + end + + test "error when attachment's empty" do + @user = User.create!(name: "DHH") + + assert_not @user.avatar.attached? + assert_raises(ArgumentError) { image_tag(@user.avatar) } + end + + test "error when object can't be resolved into url" do + unresolvable_object = ActionView::Helpers::AssetTagHelper + assert_raises(ArgumentError) { image_tag(unresolvable_object) } + end +end |