Permalink
Browse files

Merge pull request #184 from bolandrm/new_files_get_ignored

ensure parents of globbed files are added to dependencies
  • Loading branch information...
2 parents 6d4e551 + 17f839c commit bf4a122324a60964c9567fd4a018d8a3bd4ae07c @guilleiguaran guilleiguaran committed Feb 25, 2014
Showing with 37 additions and 3 deletions.
  1. +15 −2 lib/sass/rails/importer.rb
  2. +17 −0 test/sass_rails_test.rb
  3. +5 −1 test/support/sass_rails_test_case.rb
View
@@ -47,9 +47,9 @@ def glob_imports(glob, base_pathname, options)
contents = ""
each_globbed_file(glob, base_pathname.dirname, options) do |filename|
if File.directory?(filename)
- context.depend_on(filename)
+ depend_on(filename)
elsif context.asset_requirable?(filename)
- context.depend_on(filename)
+ depend_on(filename)
contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
end
end
@@ -63,6 +63,19 @@ def glob_imports(glob, base_pathname, options)
private
+ def depend_on(filename)
+ context.depend_on(filename)
+ context.depend_on(globbed_file_parent(filename))
+ end
+
+ def globbed_file_parent(filename)
+ if File.directory?(filename)
+ File.expand_path('..', filename)
+ else
+ File.dirname(filename)
+ end
+ end
+
def engine_from_path(name, dir, options)
full_filename, syntax = Sass::Util.destructure(find_real_file(dir, name, options))
return unless full_filename && File.readable?(full_filename)
View
@@ -89,6 +89,23 @@ class SassRailsTest < Sass::Rails::TestCase
assert_match /default-old-css/, css_output
end
+ test 'globbed imports work when new file is added' do
+ project = 'scss_project'
+ filename = 'application.css.scss'
+
+ within_rails_app(project) do |tmpdir|
+ asset_output(filename)
+
+ new_file = File.join(tmpdir, 'app', 'assets', 'stylesheets', 'globbed', 'new.scss')
+ File.open(new_file, 'w') do |file|
+ file.puts '.new-file-test { color: #000; }'
+ end
+
+ css_output = asset_output(filename)
+ assert_match /new-file-test/, css_output
+ end
+ end
+
test 'sass asset paths work' do
css_output = sprockets_render('scss_project', 'application.css.scss')
assert_match %r{asset-path:\s*"/assets/rails.png"}, css_output, 'asset-path:\s*"/assets/rails.png"'
@@ -37,10 +37,14 @@ module TestAssetPaths
def sprockets_render(project, filename)
within_rails_app(project) do
- runcmd "ruby script/rails runner 'puts Rails.application.assets[#{filename.inspect}]'"
+ asset_output(filename)
end
end
+ def asset_output(filename)
+ runcmd "ruby script/rails runner 'puts Rails.application.assets[#{filename.inspect}]'"
+ end
+
def assert_file_exists(filename)
assert File.exists?(filename), "could not find #{filename}. PWD=#{Dir.pwd}\nDid find: #{Dir.glob(File.dirname(filename)+"/*").join(", ")}"
end

0 comments on commit bf4a122

Please sign in to comment.