From d0f3e5526d8eee86bf6e7231fe01672d1c0a6f28 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 5 Feb 2022 23:02:49 -0600 Subject: [PATCH] tests: fix broken tests. Fix regression in e7744cb6e. --- .../media_assets_controller_test.rb | 2 +- test/unit/storage_manager_test.rb | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/test/functional/media_assets_controller_test.rb b/test/functional/media_assets_controller_test.rb index f4e0bf41c..f789aded2 100644 --- a/test/functional/media_assets_controller_test.rb +++ b/test/functional/media_assets_controller_test.rb @@ -32,7 +32,7 @@ class MediaAssetsControllerTest < ActionDispatch::IntegrationTest get media_asset_path(@media_asset), as: :json assert_response :success - assert_equal(nil, response.parsed_body[:md5]) + assert_nil(response.parsed_body[:md5]) end end end diff --git a/test/unit/storage_manager_test.rb b/test/unit/storage_manager_test.rb index ad054563b..1dfce4e9e 100644 --- a/test/unit/storage_manager_test.rb +++ b/test/unit/storage_manager_test.rb @@ -1,8 +1,11 @@ require 'test_helper' class StorageManagerTest < ActiveSupport::TestCase - setup do - CurrentUser.ip_addr = "127.0.0.1" + def tempfile(data) + file = Tempfile.new + file.write(data) + file.flush + file end context "StorageManager::Local" do @@ -12,22 +15,22 @@ class StorageManagerTest < ActiveSupport::TestCase context "#store method" do should "store the file" do - @storage_manager.store(StringIO.new("data"), "test.txt") + @storage_manager.store(tempfile("data"), "test.txt") - assert("data", File.read("#{@temp_dir}/test.txt")) + assert_equal("data", File.read("#{@temp_dir}/test.txt")) end should "overwrite the file if it already exists" do - @storage_manager.store(StringIO.new("foo"), "test.txt") - @storage_manager.store(StringIO.new("bar"), "test.txt") + @storage_manager.store(tempfile("foo"), "test.txt") + @storage_manager.store(tempfile("bar"), "test.txt") - assert("bar", File.read("#{@temp_dir}/test.txt")) + assert_equal("bar", File.read("#{@temp_dir}/test.txt")) end end context "#delete method" do should "delete the file" do - @storage_manager.store(StringIO.new("data"), "test.txt") + @storage_manager.store(tempfile("data"), "test.txt") @storage_manager.delete("test.txt") assert_not(File.exist?("#{@temp_dir}/test.txt")) @@ -57,16 +60,16 @@ class StorageManagerTest < ActiveSupport::TestCase context "#store method" do should "store the file on both backends" do - @storage_manager.store(StringIO.new("data"), "test.txt") + @storage_manager.store(tempfile("data"), "test.txt") - assert("data", File.read("#{@temp_dir1}/test.txt")) - assert("data", File.read("#{@temp_dir2}/test.txt")) + assert_equal("data", File.read("#{@temp_dir1}/test.txt")) + assert_equal("data", File.read("#{@temp_dir2}/test.txt")) end end context "#delete method" do should "delete the file from both backends" do - @storage_manager.store(StringIO.new("data"), "test.txt") + @storage_manager.store(tempfile("data"), "test.txt") @storage_manager.delete("test.txt") assert_not(File.exist?("#{@temp_dir1}/test.txt")) @@ -76,7 +79,7 @@ class StorageManagerTest < ActiveSupport::TestCase context "#open method" do should "open the file from the first backend" do - @storage_manager.store(StringIO.new("data"), "test.txt") + @storage_manager.store(tempfile("data"), "test.txt") assert_equal("data", @storage_manager.open("test.txt").read) end