When running puppet agent when remote filebucketing is enabled, the old
content is file bucketed when there's a change, but not the new content.
Therefore, we won't link to the new content.

There's still plenty of potential to be wrong with the link.  The new
content would be there if an inspect run was done with --archive_files
after the apply report, and then we wouldn't link even though the
content was there.

We also will link when remote filebucketing isn't being used by the
agents (which may be more often than we thought since there's a bug
preventing it from working with the agent (#5362), or if the inspect
runs don't have --archive_files set (which defaults to false).

The baseline plugin will update its usage of popup_md5s as part of
ticket #9105.

Reviewed-by: Nick Lewis <n...@puppetlabs.com>
Signed-off-by: Matt Robinson <m...@puppetlabs.com>
---
Local-branch: ticket/1.2rc/7934-filebucket_links
 app/helpers/reports_helper.rb                  |    8 +++-
 app/views/reports/_resource_statuses.html.haml |    2 +-
 spec/helpers/reports_helper_spec.rb            |   52 +++++++++++++++++++++--
 3 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb
index 337020a..41cd1fc 100644
--- a/app/helpers/reports_helper.rb
+++ b/app/helpers/reports_helper.rb
@@ -1,8 +1,12 @@
 module ReportsHelper
-  def popup_md5s( string, label = nil )
+  def popup_md5s( string, options = {} )
     if SETTINGS.use_file_bucket_diffs
       string.gsub(/\{md5\}[a-fA-F0-9]{32}/) do |match|
-        link_to_function label || match, "display_file_popup('#{url_for 
:controller => :files, :action => :show, :file => match.sub('{md5}','')}')", 
:class => 'popup-md5'
+        if options[:exclude_md5s] and options[:exclude_md5s].include? match
+          match
+        else
+          link_to_function options[:label] || match, 
"display_file_popup('#{url_for :controller => :files, :action => :show, :file 
=> match.sub('{md5}','')}')", :class => 'popup-md5'
+        end
       end
     else
       string
diff --git a/app/views/reports/_resource_statuses.html.haml 
b/app/views/reports/_resource_statuses.html.haml
index d862706..a561466 100644
--- a/app/views/reports/_resource_statuses.html.haml
+++ b/app/views/reports/_resource_statuses.html.haml
@@ -24,7 +24,7 @@
                 - status.events.each do |event|
                   %tr{:class => "status #{event.status}"}
                     %td= event.property
-                    %td= popup_md5s( h event.message )
+                    %td= popup_md5s( h(event.message), :exclude_md5s => 
[event.desired_value])
           %br
   - else
     %h3 Events
diff --git a/spec/helpers/reports_helper_spec.rb 
b/spec/helpers/reports_helper_spec.rb
index 5ae9836..23133b7 100644
--- a/spec/helpers/reports_helper_spec.rb
+++ b/spec/helpers/reports_helper_spec.rb
@@ -1,11 +1,53 @@
 require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
 
 describe ReportsHelper do
+  describe "#popup_md5s" do
+    before do
+      SETTINGS.stubs(:use_file_bucket_diffs).returns(true)
+      @text = "content changed '{md5}b84b7c77fb71f0d945f186513a09e185' to 
'{md5}d28d2d3560fa76f0dbb1a452f8c38169'"
+    end
 
-  #Delete this example and add some real ones or delete this file
-  it "should be included in the object returned by #helper" do
-    included_modules = (class << helper; self; end).send :included_modules
-    included_modules.should include(ReportsHelper)
-  end
+    it "should make anything that looks like an md5 into a filebucket link" do
+      helper.popup_md5s(@text).gsub(/\s/, '').should == <<-HEREDOC.gsub(/\s/, 
'')
+        content changed '<a
+          class=\"popup-md5\"
+          href=\"#\"
+          onclick=\"display_file_popup( 
'/files/show?file=b84b7c77fb71f0d945f186513a09e185'); return false;\">
+          {md5}b84b7c77fb71f0d945f186513a09e185
+        </a>' to '<a
+          class=\"popup-md5\"
+          href=\"#\"
+          
onclick=\"display_file_popup('/files/show?file=d28d2d3560fa76f0dbb1a452f8c38169');
 return false;\">
+          {md5}d28d2d3560fa76f0dbb1a452f8c38169
+        </a>'
+      HEREDOC
+    end
+
+    it "should make the link text be a label if it's passed in" do
+      helper.popup_md5s(@text, :label => 'foo').gsub(/\s/, '').should == 
<<-HEREDOC.gsub(/\s/, '')
+        content changed '<a
+          class=\"popup-md5\"
+          href=\"#\"
+          onclick=\"display_file_popup( 
'/files/show?file=b84b7c77fb71f0d945f186513a09e185'); return false;\">
+          foo
+        </a>' to '<a
+          class=\"popup-md5\"
+          href=\"#\"
+          
onclick=\"display_file_popup('/files/show?file=d28d2d3560fa76f0dbb1a452f8c38169');
 return false;\">
+          foo
+        </a>'
+      HEREDOC
+    end
 
+    it "should not link md5s if they're in the excluded list" do
+      helper.popup_md5s(@text, :exclude_md5s => 
['{md5}d28d2d3560fa76f0dbb1a452f8c38169']).gsub(/\s/, '').should == 
<<-HEREDOC.gsub(/\s/, '')
+        content changed '<a
+          class=\"popup-md5\"
+          href=\"#\"
+          onclick=\"display_file_popup( 
'/files/show?file=b84b7c77fb71f0d945f186513a09e185'); return false;\">
+          {md5}b84b7c77fb71f0d945f186513a09e185
+        </a>' to '{md5}d28d2d3560fa76f0dbb1a452f8c38169'
+      HEREDOC
+    end
+  end
 end
-- 
1.7.3.1

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

Reply via email to