A preliminary for searching latest inspect reports

Paired-With: Matt Robinson <[email protected]>
Signed-off-by: Jesse Wolfe <[email protected]>
---
Local-branch: ticket/next/5863-squash
 app/helpers/application_helper.rb                  |    2 +-
 app/models/node.rb                                 |   16 ++++++++--------
 app/views/nodes/_nodes.html.haml                   |    2 +-
 ...t_report_id_to_last_apply_report_id_on_nodes.rb |    9 +++++++++
 db/schema.rb                                       |    4 ++--
 spec/models/report_spec.rb                         |   14 +++++++-------
 6 files changed, 28 insertions(+), 19 deletions(-)
 create mode 100644 
db/migrate/20110113195253_rename_column_last_report_id_to_last_apply_report_id_on_nodes.rb

diff --git a/app/helpers/application_helper.rb 
b/app/helpers/application_helper.rb
index f0012a1..541c374 100755
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -141,7 +141,7 @@ module ApplicationHelper
 
   # Return status icon for the +node+.
   def node_status_icon(node)
-    report_status_icon(node.last_report)
+    report_status_icon(node.last_apply_report)
   end
 
   # Return status icon for the +report+.
diff --git a/app/models/node.rb b/app/models/node.rb
index 2212201..3df1877 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -14,10 +14,10 @@ class Node < ActiveRecord::Base
   has_many :node_groups, :through => :node_group_memberships
 
   has_many :reports, :dependent => :destroy
-  belongs_to :last_report, :class_name => 'Report'
+  belongs_to :last_apply_report, :class_name => 'Report'
   belongs_to :baseline_report, :class_name => 'Report'
 
-  named_scope :with_last_report, :include => :last_report
+  named_scope :with_last_report, :include => :last_apply_report
   named_scope :by_report_date, :order => 'reported_at DESC'
 
   named_scope :search, lambda{|q| q.blank? ? {} : {:conditions => ['name LIKE 
?', "%#{q}%"]} }
@@ -47,7 +47,7 @@ class Node < ActiveRecord::Base
   named_scope :by_currentness_and_successfulness, lambda {|currentness, 
successfulness|
     operator = successfulness ? '!=' : '='
     if currentness
-      { :conditions => ["nodes.status #{operator} 'failed' AND 
nodes.last_report_id is not NULL"]  }
+      { :conditions => ["nodes.status #{operator} 'failed' AND 
nodes.last_apply_report_id is not NULL"]  }
     else
       {
         :conditions => ["reports.kind = 'apply' AND reports.status #{operator} 
'failed'"],
@@ -104,8 +104,8 @@ class Node < ActiveRecord::Base
   end
 
   def status_class
-    return 'no reports' unless last_report
-    last_report.status
+    return 'no reports' unless last_apply_report
+    last_apply_report.status
   end
 
   attr_accessor :node_class_names
@@ -138,12 +138,12 @@ class Node < ActiveRecord::Base
     return false
   end
 
-  # Assigns the node's :last_report attribute. # FIXME
+  # Assigns the node's :last_apply_report attribute. # FIXME
   def assign_last_report(report=nil)
     report ||= Report.applies.find_last_for(self)
 
-    if self.last_report != report
-      self.last_report = report
+    if self.last_apply_report != report
+      self.last_apply_report = report
       self.reported_at = report ? report.time : nil
       self.status = report ? report.status : 'unchanged'
 
diff --git a/app/views/nodes/_nodes.html.haml b/app/views/nodes/_nodes.html.haml
index dbc237e..6efce09 100644
--- a/app/views/nodes/_nodes.html.haml
+++ b/app/views/nodes/_nodes.html.haml
@@ -29,7 +29,7 @@
               - else
                 = sources.map{|s| link_to(s.name,s)}.join(", ")
           %td.latest_report
-            = node.last_report ? node.last_report.time : "Has not reported"
+            = node.last_apply_report ? node.last_apply_report.time : "Has not 
reported"
     - else
       %td.empty{:colspan => container.nil? ? 3 : 4}
         = describe_no_matches_for :nodes
diff --git 
a/db/migrate/20110113195253_rename_column_last_report_id_to_last_apply_report_id_on_nodes.rb
 
b/db/migrate/20110113195253_rename_column_last_report_id_to_last_apply_report_id_on_nodes.rb
new file mode 100644
index 0000000..47937f8
--- /dev/null
+++ 
b/db/migrate/20110113195253_rename_column_last_report_id_to_last_apply_report_id_on_nodes.rb
@@ -0,0 +1,9 @@
+class RenameColumnLastReportIdToLastApplyReportIdOnNodes < 
ActiveRecord::Migration
+  def self.up
+    rename_column :nodes, :last_report_id, :last_apply_report_id
+  end
+
+  def self.down
+    rename_column :nodes, :last_apply_report_id, :last_report_id
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 267db1f..3c3f9e8 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
 #
 # It's strongly recommended to check this file into your version control 
system.
 
-ActiveRecord::Schema.define(:version => 20110113183616) do
+ActiveRecord::Schema.define(:version => 20110113195253) do
 
   create_table "metrics", :force => true do |t|
     t.integer "report_id",                                :null => false
@@ -67,7 +67,7 @@ ActiveRecord::Schema.define(:version => 20110113183616) do
     t.datetime "updated_at"
     t.string   "url"
     t.datetime "reported_at"
-    t.integer  "last_report_id"
+    t.integer  "last_apply_report_id"
     t.string   "status"
     t.boolean  "hidden",             :default => false
     t.integer  "baseline_report_id"
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index e12c80f..61a6503 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -67,14 +67,14 @@ describe Report do
       node = Node.generate!
       report = Report.create!(:host => node.name, :time => Time.now, :kind => 
"apply")
       node.reload
-      node.last_report.should == report
+      node.last_apply_report.should == report
     end
 
     it "should not update the node's last report for inspect reports" do
       node = Node.generate
       report = Report.create!(:host => node.name, :time => Time.now, :kind => 
"inspect")
       node.reload
-      node.last_report.should_not == report
+      node.last_apply_report.should_not == report
     end
   end
 
@@ -121,14 +121,14 @@ describe Report do
       # so time matches what the node has
       @newer_report.reload
       @node.reload
-      @node.last_report.should == @newer_report
+      @node.last_apply_report.should == @newer_report
       @node.reported_at.should == @newer_report.time
       @node.status.should == @newer_report.status
 
       @newer_report.destroy
       @node.reload
 
-      @node.last_report.should == @report
+      @node.last_apply_report.should == @report
       @node.reported_at.should == @report.time
       @node.status.should == @report.status
     end
@@ -142,14 +142,14 @@ describe Report do
       # so time matches what the node has
       @newer_report.reload
       @node.reload
-      @node.last_report.should == @newer_report
+      @node.last_apply_report.should == @newer_report
       @node.reported_at.should == @newer_report.time
       @node.status.should == @newer_report.status
 
       @newer_report.destroy
       @node.reload
 
-      @node.last_report.should == @report
+      @node.last_apply_report.should == @report
       @node.reported_at.should == @report.time
       @node.status.should == @report.status
     end
@@ -158,7 +158,7 @@ describe Report do
       @report.destroy
       @node.reload
 
-      @node.last_report.should == nil
+      @node.last_apply_report.should == nil
       @node.reported_at.should == nil
       @node.status.should == 'unchanged'
     end
-- 
1.7.0.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