summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-04 16:32:04 -0500
committerLuke Kanies <luke@madstop.com>2008-07-04 16:32:04 -0500
commit9d69b3fd12f90ddead7b6a3392395fbe4e901d9b (patch)
treebd8a4e16ed9c0e34568ea321d152e786f1e6090a
parent61ec332144ad794fae80a16feac543afc014a5f9 (diff)
downloadpuppet-9d69b3fd12f90ddead7b6a3392395fbe4e901d9b.tar.gz
puppet-9d69b3fd12f90ddead7b6a3392395fbe4e901d9b.tar.xz
puppet-9d69b3fd12f90ddead7b6a3392395fbe4e901d9b.zip
Testing and simplifying the Transaction::Change#backward method.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/transaction/change.rb19
-rwxr-xr-xspec/unit/transaction/change.rb31
2 files changed, 36 insertions, 14 deletions
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb
index 396b9233e..e05c2592c 100644
--- a/lib/puppet/transaction/change.rb
+++ b/lib/puppet/transaction/change.rb
@@ -4,24 +4,15 @@ require 'puppet/transaction/event'
# Handle all of the work around performing an actual change,
# including calling 'sync' on the properties and producing events.
class Puppet::Transaction::Change
- attr_accessor :is, :should, :type, :path, :property, :changed, :proxy
-
- # The log file generated when this object was changed.
- attr_reader :report
+ attr_accessor :is, :should, :path, :property, :changed, :proxy
# Switch the goals of the property, thus running the change in reverse.
def backward
- @property.should = @is
- @is = @property.retrieve
+ @is, @should = @should, @is
+ @property.should = @should
- unless @property.insync?(@is)
- @property.info "Backing %s" % self
- return self.go
- else
- @property.debug "rollback is already in sync: %s vs. %s" %
- [@is, @property.should.inspect]
- return nil
- end
+ @property.info "Reversing %s" % self
+ return self.go
end
def changed?
diff --git a/spec/unit/transaction/change.rb b/spec/unit/transaction/change.rb
index 3312b12e8..eaa6fb4ab 100755
--- a/spec/unit/transaction/change.rb
+++ b/spec/unit/transaction/change.rb
@@ -146,6 +146,37 @@ describe Puppet::Transaction::Change do
@change.forward.should == [:uno, :dos]
end
end
+
+ describe "backward" do
+ before do
+ @property = stub 'property'
+ @property.stub_everything
+ @property.stubs(:should).returns "shouldval"
+ @change = Change.new(@property, "value")
+ @change.stubs :go
+ end
+
+ it "should swap the 'is' and 'should' values" do
+ @change.backward
+ @change.is.should == "shouldval"
+ @change.should.should == "value"
+ end
+
+ it "should set the 'should' value on the property to the previous 'is' value" do
+ @property.expects(:should=).with "value"
+ @change.backward
+ end
+
+ it "should log that it's reversing the change" do
+ @property.expects(:info)
+ @change.backward
+ end
+
+ it "should execute" do
+ @change.expects(:go)
+ @change.backward
+ end
+ end
end
end
end