Permalink
Browse files

Merge pull request #119 from twinturbo/deleted-files-fix

Test for handling deleted files
  • Loading branch information...
2 parents 93d0f0e + 0310a35 commit 66128dee62ddc75e8e7231261768123e8213d8e6 @wycats wycats committed Oct 31, 2012
Showing with 42 additions and 8 deletions.
  1. +22 −8 lib/rake-pipeline/project.rb
  2. +20 −0 spec/rake_acceptance_spec.rb
@@ -115,6 +115,14 @@ def invoke
if dirty?
rebuild_from_assetfile(assetfile_path) if assetfile_dirty?
+ # The temporary files have to be cleaned otherwise
+ # there will be a "ghost" input. Here's an example
+ # rake task: application.js => [a.js, b.js]. Deleting a.js
+ # will make application.js => [b.js]. The task correctly checks
+ # if B has changed (which it hasn't) and says that application.js
+ # is correct. Cleaning tmp files ensures that this doesn't happen.
+ clean if files_deleted?
+
pipelines.each(&:invoke)
manifest.write_manifest
@@ -265,7 +273,7 @@ def digest(str)
end
def dirty?
- assetfile_dirty? || files_dirty?
+ assetfile_dirty? || files_dirty? || files_deleted?
end
def assetfile_dirty?
@@ -278,19 +286,17 @@ def assetfile_dirty?
end
# Returns true if any of these conditions are met:
- # The pipeline hasn't been invoked yet
- # The input files have been modified
- # Any of the input files have been deleted
- # There are new input files
+ # * The pipeline hasn't been invoked yet
+ # * The input files have changed
+ # * There is a new input file
def files_dirty?
return true if manifest.empty?
previous_files = manifest.files
+ # check for modifications to new files
input_files.each do |input_file|
- if !File.exists? input_file
- return true # existing input file has been deleted
- elsif !previous_files[input_file]
+ if !previous_files[input_file]
return true # there is a new file in the pipeline
elsif File.mtime(input_file).to_i != previous_files[input_file]
return true # existing file has been changed
@@ -300,6 +306,14 @@ def files_dirty?
false
end
+ def files_deleted?
+ manifest.files.each_key do |input_file|
+ return true if !File.exists?(input_file)
+ end
+
+ false
+ end
+
def input_files
static_input_files = pipelines.collect do |p|
p.input_files.reject { |file| file.in_directory? tmpdir }.map(&:fullpath)
@@ -98,6 +98,10 @@ def copy_files
end
end
+ def delete_files
+ FileUtils.rm_rf File.join(tmp, "app/javascripts/jquery.js")
+ end
+
before do
Rake.application = Rake::Application.new
copy_files
@@ -262,6 +266,18 @@ def copy_files
project.invoke
File.mtime(output_file).should == previous_mtime
end
+
+ it "handles deleted files" do
+ output_file = File.join(tmp, "public/javascripts/application.js")
+
+ project.invoke
+ content = File.read output_file
+
+ delete_files
+ project.invoke
+
+ content.should_not == File.read(output_file)
+ end
end
describe "the raw pipeline DSL (with block strip_asserts_filter)" do
@@ -495,6 +511,10 @@ def output_should_exist(expected=EXPECTED_JS_OUTPUT)
File.exists?(junk).should be_false
end
+ def delete_files
+ FileUtils.rm_rf File.join(tmp1, "app/javascripts/jquery.js")
+ end
+
before do
tmp1 = self.tmp1
tmp2 = self.tmp2

0 comments on commit 66128de

Please sign in to comment.