Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sstephenson/sprockets
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jul 3, 2012
2 parents 92b7d12 + 84debc4 commit 25beca9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/sprockets/context.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/default/missing_absolute_depend_on.js
@@ -0,0 +1 @@
//= depend_on /tmp/sprockets/notfound
1 change: 1 addition & 0 deletions test/fixtures/default/missing_depend_on.js
@@ -0,0 +1 @@
//= depend_on notfound
17 changes: 17 additions & 0 deletions test/test_asset.rb
Expand Up @@ -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')
Expand Down
28 changes: 22 additions & 6 deletions test/test_environment.rb
Expand Up @@ -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
Expand All @@ -163,38 +175,42 @@ 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
paths = []
@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")
Expand All @@ -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
Expand Down

0 comments on commit 25beca9

Please sign in to comment.