Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure absolute paths passed to depend_on exist

  • Loading branch information...
commit 84debc4708ffd1adf4f27b4da82a0669b67a93a8 1 parent 2cb598f
@josh josh authored
View
6 lib/sprockets/context.rb
@@ -81,7 +81,11 @@ def resolve(path, options = {}, &block)
attributes = environment.attributes_for(pathname)
if pathname.absolute?
- pathname
+ if environment.stat(pathname)
+ pathname
+ else
+ raise FileNotFound, "couldn't find file '#{pathname}'"
+ end
elsif content_type = options[:content_type]
content_type = self.content_type if content_type == :self
View
1  test/fixtures/default/missing_absolute_depend_on.js
@@ -0,0 +1 @@
+//= depend_on /tmp/sprockets/notfound
View
1  test/fixtures/default/missing_depend_on.js
@@ -0,0 +1 @@
+//= depend_on notfound
View
17 test/test_asset.rb
@@ -154,6 +154,23 @@ def self.test(name, &block)
end
end
+ test "asset is stale when one of its dependencies is removed" do
+ main = fixture_path('asset/test-main.js')
+ dep = fixture_path('asset/test-dep.js')
+
+ sandbox main, dep do
+ File.open(main, 'w') { |f| f.write "//= depend_on test-dep\n" }
+ File.open(dep, 'w') { |f| f.write "a;" }
+ asset = asset('test-main.js')
+
+ assert asset.fresh?(@env)
+
+ File.unlink(dep)
+
+ assert asset.stale?(@env)
+ end
+ end
+
test "asset is stale when one of its asset dependencies is modified" do
main = fixture_path('asset/test-main.js')
dep = fixture_path('asset/test-dep.js')
View
28 test/test_environment.rb
@@ -154,6 +154,18 @@ def self.test(name, &block)
end
end
+ test "asset with missing depend_on raises an exception" do
+ assert_raises Sprockets::FileNotFound do
+ @env["missing_depend_on.js"]
+ end
+ end
+
+ test "asset with missing absolute depend_on raises an exception" do
+ assert_raises Sprockets::FileNotFound do
+ @env["missing_absolute_depend_on.js"]
+ end
+ end
+
test "asset logical path for absolute path" do
assert_equal "gallery.js",
@env[fixture_path("default/gallery.js")].logical_path
@@ -163,30 +175,34 @@ def self.test(name, &block)
@env[fixture_path("default/mobile/a.js")].logical_path
end
+ ENTRIES_IN_PATH = 36
+
test "iterate over each entry" do
entries = []
@env.each_entry(fixture_path("default")) do |path|
entries << path
end
- assert_equal 34, entries.length
+ assert_equal ENTRIES_IN_PATH, entries.length
end
test "each entry enumerator" do
enum = @env.each_entry(fixture_path("default"))
- assert_equal 34, enum.to_a.length
+ assert_equal ENTRIES_IN_PATH, enum.to_a.length
end
+ FILES_IN_PATH = 31
+
test "iterate over each file" do
files = []
@env.each_file do |filename|
files << filename
end
- assert_equal 29, files.length
+ assert_equal FILES_IN_PATH, files.length
end
test "each file enumerator" do
enum = @env.each_file
- assert_equal 29, enum.to_a.length
+ assert_equal FILES_IN_PATH, enum.to_a.length
end
test "iterate over each logical path" do
@@ -194,7 +210,7 @@ def self.test(name, &block)
@env.each_logical_path do |logical_path|
paths << logical_path
end
- assert_equal 29, paths.length
+ assert_equal FILES_IN_PATH, paths.length
assert_equal paths.size, paths.uniq.size, "has duplicates"
assert paths.include?("application.js")
@@ -205,7 +221,7 @@ def self.test(name, &block)
test "each logical path enumerator" do
enum = @env.each_logical_path
- assert_equal 29, enum.to_a.length
+ assert_equal FILES_IN_PATH, enum.to_a.length
end
test "iterate over each logical path matching fnmatch filters" do
Please sign in to comment.
Something went wrong with that request. Please try again.