From eb0af6d5eb7c0ac049e6c89bd6ee991586f4d256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 31 Aug 2017 15:31:55 -0400 Subject: [PATCH] Make sure find_sources behaves in the same way when the assets don't exists --- lib/sprockets/manifest.rb | 3 ++- test/test_manifest.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/sprockets/manifest.rb b/lib/sprockets/manifest.rb index 9e6329e00..2d42c9f8b 100644 --- a/lib/sprockets/manifest.rb +++ b/lib/sprockets/manifest.rb @@ -161,7 +161,8 @@ def find_sources(*args) end else args.each do |path| - yield File.binread(File.join(dir, assets[path])) + asset = assets[path] + yield File.binread(File.join(dir, asset)) if asset end end end diff --git a/test/test_manifest.rb b/test/test_manifest.rb index 323bb3229..acef521ea 100644 --- a/test/test_manifest.rb +++ b/test/test_manifest.rb @@ -634,7 +634,13 @@ def teardown manifest = Sprockets::Manifest.new(@env, @dir) result = manifest.find_sources("mobile/a.js", "mobile/b.js") - assert_equal ["var A;\n", "var B;\n"], result.to_a + assert_equal ["var A;\n", "var B;\n"], result.to_a.sort + + result = manifest.find_sources("not_existent.js", "also_not_existent.js") + assert_equal [], result.to_a + + result = manifest.find_sources("mobile/a.js", "also_not_existent.js") + assert_equal ["var A;\n"], result.to_a end test "find_sources without environment" do @@ -645,6 +651,12 @@ def teardown result = manifest.find_sources("mobile/a.js", "mobile/b.js") assert_equal ["var A;\n", "var B;\n"], result.to_a + + result = manifest.find_sources("not_existent.js", "also_not_existent.js") + assert_equal [], result.to_a + + result = manifest.find_sources("mobile/a.js", "also_not_existent.js") + assert_equal ["var A;\n"], result.to_a end test "compress non-binary assets" do