@@ -32,7 +32,7 @@ class MediaAssetsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get media_asset_path(@media_asset), as: :json
|
get media_asset_path(@media_asset), as: :json
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal(nil, response.parsed_body[:md5])
|
assert_nil(response.parsed_body[:md5])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class StorageManagerTest < ActiveSupport::TestCase
|
class StorageManagerTest < ActiveSupport::TestCase
|
||||||
setup do
|
def tempfile(data)
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
file = Tempfile.new
|
||||||
|
file.write(data)
|
||||||
|
file.flush
|
||||||
|
file
|
||||||
end
|
end
|
||||||
|
|
||||||
context "StorageManager::Local" do
|
context "StorageManager::Local" do
|
||||||
@@ -12,22 +15,22 @@ class StorageManagerTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "#store method" do
|
context "#store method" do
|
||||||
should "store the file" 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
|
end
|
||||||
|
|
||||||
should "overwrite the file if it already exists" do
|
should "overwrite the file if it already exists" do
|
||||||
@storage_manager.store(StringIO.new("foo"), "test.txt")
|
@storage_manager.store(tempfile("foo"), "test.txt")
|
||||||
@storage_manager.store(StringIO.new("bar"), "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
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#delete method" do
|
context "#delete method" do
|
||||||
should "delete the file" 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")
|
@storage_manager.delete("test.txt")
|
||||||
|
|
||||||
assert_not(File.exist?("#{@temp_dir}/test.txt"))
|
assert_not(File.exist?("#{@temp_dir}/test.txt"))
|
||||||
@@ -57,16 +60,16 @@ class StorageManagerTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "#store method" do
|
context "#store method" do
|
||||||
should "store the file on both backends" 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_equal("data", File.read("#{@temp_dir1}/test.txt"))
|
||||||
assert("data", File.read("#{@temp_dir2}/test.txt"))
|
assert_equal("data", File.read("#{@temp_dir2}/test.txt"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#delete method" do
|
context "#delete method" do
|
||||||
should "delete the file from both backends" 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")
|
@storage_manager.delete("test.txt")
|
||||||
|
|
||||||
assert_not(File.exist?("#{@temp_dir1}/test.txt"))
|
assert_not(File.exist?("#{@temp_dir1}/test.txt"))
|
||||||
@@ -76,7 +79,7 @@ class StorageManagerTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "#open method" do
|
context "#open method" do
|
||||||
should "open the file from the first backend" 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)
|
assert_equal("data", @storage_manager.open("test.txt").read)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user