summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-15 15:44:09 -0600
committerJames Turnbull <james@lovedthanlost.net>2009-02-13 14:16:36 +1100
commitd5a193a594bbc2194dbf1e5264369ebea0e55880 (patch)
tree8078cfd0c8c180ded487aa1427354025742014d8 /spec
parent53f15b9208a3271e944c687b8d0e670d422fb832 (diff)
Fixing #1541 - ParsedFile only backs up files once per transaction
This moves responsibility for backups from the filetype to the consumer of the filetype, but only ParsedFile actually uses filetypes. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/provider/parsedfile.rb36
-rw-r--r--spec/unit/util/filetype.rb6
2 files changed, 36 insertions, 6 deletions
diff --git a/spec/unit/provider/parsedfile.rb b/spec/unit/provider/parsedfile.rb
index 05e9de3ab..11a91c8d7 100755
--- a/spec/unit/provider/parsedfile.rb
+++ b/spec/unit/provider/parsedfile.rb
@@ -47,4 +47,40 @@ describe Puppet::Provider::ParsedFile do
@class.instances
end
end
+
+ describe "when flushing a file's records to disk" do
+ before do
+ # This way we start with some @records, like we would in real life.
+ @class.stubs(:retrieve).returns []
+ @class.default_target = "/foo/bar"
+ @class.initvars
+ @class.prefetch
+
+ @filetype = mock 'filetype'
+ Puppet::Util::FileType.filetype(:flat).expects(:new).with("/my/file").returns @filetype
+
+ @filetype.stubs(:write)
+ end
+
+ it "should back up the file being written" do
+ @filetype.expects(:backup)
+
+ @class.flush_target("/my/file")
+ end
+
+ it "should not back up the file more than once between calls to 'prefetch'" do
+ @filetype.expects(:backup).once
+
+ @class.flush_target("/my/file")
+ @class.flush_target("/my/file")
+ end
+
+ it "should back the file up again once the file has been reread" do
+ @filetype.expects(:backup).times(2)
+
+ @class.flush_target("/my/file")
+ @class.prefetch
+ @class.flush_target("/my/file")
+ end
+ end
end
diff --git a/spec/unit/util/filetype.rb b/spec/unit/util/filetype.rb
index 74dae3356..0506b6b47 100644
--- a/spec/unit/util/filetype.rb
+++ b/spec/unit/util/filetype.rb
@@ -91,12 +91,6 @@ describe Puppet::Util::FileType do
Tempfile.stubs(:new).returns @tempfile
end
- it "should back up the file" do
- @file.expects(:backup)
-
- @file.write("foo")
- end
-
it "should first create a temp file and copy its contents over to the file location" do
Tempfile.expects(:new).with("puppet").returns @tempfile
@tempfile.expects(:print).with("my text")