Because failed resources are the resources a user likely cares about most, we
move those to the top to make them more immediately visible.

This commit also moves the logic for grouping and sorting resource_statuses
from the view to the callback. Because the callback functions as an ad-hoc
controller for the partial it renders, it is a better place for this logic than
the view itself.

Reviewed-By: Jacob Helwig <[email protected]>
Signed-off-by: Nick Lewis <[email protected]>
---
Local-branch: ticket/master/8199
 app/views/reports/_resource_statuses.html.haml |    2 +-
 lib/core_callbacks.rb                          |    4 ++-
 spec/lib/core_callbacks_spec.rb                |   26 ++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 2 deletions(-)
 create mode 100644 spec/lib/core_callbacks_spec.rb

diff --git a/app/views/reports/_resource_statuses.html.haml 
b/app/views/reports/_resource_statuses.html.haml
index d55b232..d3ea038 100644
--- a/app/views/reports/_resource_statuses.html.haml
+++ b/app/views/reports/_resource_statuses.html.haml
@@ -5,7 +5,7 @@
       %a{ :href => '#', :class => 'expand-all' } Expand all
     .section
       %dl.expandable-list
-        - report.resource_statuses.group_by(&:status).each do |status, 
resources|
+        - statuses.each do |status, resources|
           %h3 #{status.titleize} (#{resources.count})
           - resources.sort_by(&:time).each do |status|
             - index += 1
diff --git a/lib/core_callbacks.rb b/lib/core_callbacks.rb
index 2c0d6ea..f311753 100644
--- a/lib/core_callbacks.rb
+++ b/lib/core_callbacks.rb
@@ -25,7 +25,9 @@ end
 
 # Report view widgets
 Registry.add_callback :core, :report_view_widgets, "800_resource_statuses" do 
|view_renderer, report|
-  view_renderer.render 'reports/resource_statuses', :report => report
+  statuses = report.resource_statuses.group_by(&:status).sort
+  if failed = statuses.index {|s,rs| s == 'failed'} then 
statuses.unshift(statuses.delete_at(failed)) end
+  view_renderer.render 'reports/resource_statuses', :report => report, 
:statuses => statuses
 end
 
 Registry.add_callback :core, :report_view_widgets, "700_log" do 
|view_renderer, report|
diff --git a/spec/lib/core_callbacks_spec.rb b/spec/lib/core_callbacks_spec.rb
new file mode 100644
index 0000000..d7eedca
--- /dev/null
+++ b/spec/lib/core_callbacks_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe 'core' do
+  before :each do
+    @registry_hash = Registry.instance.instance_variable_get('@registry')
+  end
+
+  describe 'report_view_widgets' do
+    describe '800_resource_statuses' do
+      it "should move 'failed' resource_statuses to the start" do
+        callback = 
@registry_hash[:core][:report_view_widgets]['800_resource_statuses']
+        report = Report.create_from_yaml(File.read(File.join(Rails.root, 
'spec/fixtures/reports/puppet26/report_error_on_package_service_and_files.yaml')))
+
+        statuses = nil
+        mock_renderer = stub('view_renderer')
+        mock_renderer.expects(:render).with do |name, args|
+          statuses = args[:statuses]
+        end
+
+        callback.call(mock_renderer, report)
+
+        statuses.map(&:first).should == ['failed', 'unchanged']
+      end
+    end
+  end
+end
-- 
1.7.5.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