Previously, the transaction would always create a report, which would
some times be overridden with a new report.

Now, the transaction optionally takes a report at initialization time,
and only creates a report of its own if none was provided.

Reviewed-by: Jacob Helwig <[email protected]>
Signed-off-by: Josh Cooper <[email protected]>
---
 lib/puppet/resource/catalog.rb |    3 +--
 lib/puppet/transaction.rb      |    9 +++------
 spec/unit/transaction_spec.rb  |   10 ++++++++--
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index a8668d8..8d4918b 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -132,9 +132,8 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
     expire
 
     Puppet::Util::Storage.load if host_config?
-    transaction = Puppet::Transaction.new(self)
+    transaction = Puppet::Transaction.new(self, options[:report])
 
-    transaction.report = options[:report] if options[:report]
     transaction.tags = options[:tags] if options[:tags]
     transaction.ignoreschedules = true if options[:ignoreschedules]
 
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 48154ad..16f201e 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -15,7 +15,7 @@ class Puppet::Transaction
   attr_accessor :sorted_resources, :configurator
 
   # The report, once generated.
-  attr_accessor :report
+  attr_reader :report
 
   # Routes and stores any events and subscriptions.
   attr_reader :event_manager
@@ -228,13 +228,10 @@ class Puppet::Transaction
 
   # this should only be called by a Puppet::Type::Component resource now
   # and it should only receive an array
-  def initialize(catalog)
+  def initialize(catalog, report = nil)
     @catalog = catalog
-
-    @report = Report.new("apply", catalog.version)
-
+    @report = report || Report.new("apply", catalog.version)
     @event_manager = Puppet::Transaction::EventManager.new(self)
-
     @resource_harness = Puppet::Transaction::ResourceHarness.new(self)
   end
 
diff --git a/spec/unit/transaction_spec.rb b/spec/unit/transaction_spec.rb
index 862413a..b5703e7 100755
--- a/spec/unit/transaction_spec.rb
+++ b/spec/unit/transaction_spec.rb
@@ -88,13 +88,19 @@ describe Puppet::Transaction do
     @transaction.should_not be_any_failed
   end
 
-  it "should be possible to replace the report object" do
+  it "should use the provided report object" do
     report = Puppet::Transaction::Report.new("apply")
-    @transaction.report = report
+    @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new, 
report)
 
     @transaction.report.should == report
   end
 
+  it "should create a report if none is provided" do
+    @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
+
+    @transaction.report.should be_kind_of Puppet::Transaction::Report
+  end
+
   it "should consider a resource to have failed dependencies if any of its 
dependencies are failed"
 
   describe "when initializing" do
-- 
1.7.4.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to