<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -275,11 +275,12 @@ module Prawn
           contents.last.border_style  = :no_top
         end
         
-        contents.first.background_color = C(:header_color) if C(:header_color)
+        contents.first.background_color = C(:header_color) if C(:header_color) &amp;&amp; C(:headers)
 
-        contents.each do |x|
+        rows_to_skip_coloring = C(:headers) ? 1 : 0
+        contents.each_with_index do |x,index|
           unless x.background_color 
-            x.background_color = next_row_color if C(:row_colors) 
+            x.background_color = next_row_color if C(:row_colors)  &amp;&amp; index &gt;= rows_to_skip_coloring
           end
           x.draw 
         end</diff>
      <filename>lib/prawn/document/table.rb</filename>
    </modified>
    <modified>
      <diff>@@ -73,6 +73,99 @@ describe &quot;A table's height&quot; do
   
 end
 
+describe &quot;Table background colors&quot; do
+  setup do
+    @default_row_count = 6
+    @data              = [[&quot;foo&quot;,&quot;bar&quot;]] * @default_row_count
+    @headers           = [&quot;baz&quot;,&quot;foobar&quot;]
+  end
+
+  def expect_background_color( color )
+    Prawn::Graphics::CellBlock.any_instance.expects(:background_color=).with(color)
+  end
+
+  it &quot;should correctly cycle row colors for PDF::Writer rows and an uncolored header&quot; do
+    row_colors     = :pdf_writer
+    odd_row_color  = &quot;cccccc&quot;   # These colors are copied from table.rb  Perhaps they
+    even_row_color = &quot;ffffff&quot;   # should be constants in Prawn::Document or elsewhere?
+
+    (@default_row_count/2).times do
+      expect_background_color( odd_row_color )
+      expect_background_color( even_row_color )
+    end
+
+    Prawn::Document.new.table(@data, :headers =&gt; @headers, :row_colors =&gt; row_colors )
+  end
+
+  it &quot;should correctly cycle row colors for a custom row color set and an uncolored header&quot; do
+    odd_row_color  = &quot;CC0000&quot;
+    even_row_color = &quot;0000BB&quot;
+    row_colors     = [ odd_row_color, even_row_color ]
+
+    (@default_row_count/2).times do
+      expect_background_color( odd_row_color )
+      expect_background_color( even_row_color )
+    end
+
+    Prawn::Document.new.table(@data, :headers =&gt; @headers, :row_colors =&gt; row_colors )
+  end
+
+  it &quot;should correctly cycle row colors and apply a custom header color when specified&quot; do
+    header_row_color = &quot;00DD00&quot;
+    odd_row_color    = &quot;CC0000&quot;
+    even_row_color   = &quot;0000BB&quot;
+    row_colors       = [ odd_row_color, even_row_color ]
+
+    expect_background_color( header_row_color )
+    (@default_row_count/2).times do
+      expect_background_color( odd_row_color )
+      expect_background_color( even_row_color )
+    end
+
+    Prawn::Document.new.table(@data, :headers =&gt; @headers, :header_color =&gt; header_row_color, :row_colors =&gt; row_colors )
+  end
+
+  it &quot;should correctly cycle row colors even if a header color is specified for a headerless table&quot; do
+    header_row_color = &quot;00DD00&quot;
+    odd_row_color    = &quot;CC0000&quot;
+    even_row_color   = &quot;0000BB&quot;
+    row_colors       = [ odd_row_color, even_row_color ]
+
+    (@default_row_count/2).times do
+      expect_background_color( odd_row_color )
+      expect_background_color( even_row_color )
+    end
+
+    Prawn::Document.new.table(@data, :header_color =&gt; @header_row_color, :row_colors =&gt; row_colors )
+  end
+
+  it &quot;should correctly cycle row colors even when only one row color is specified&quot; do
+    row_color   = &quot;0000BB&quot;
+    row_colors  = [ row_color ]
+
+    @default_row_count.times do
+      expect_background_color( row_color )
+    end
+
+    Prawn::Document.new.table(@data, :row_colors =&gt; row_colors )
+  end
+
+  it &quot;should correctly cycle row colors even when more than two row colors are specified&quot; do
+    row_color_1   = &quot;0000BB&quot;
+    row_color_2   = &quot;00CC00&quot;
+    row_color_3   = &quot;DD0000&quot;
+    row_colors  = [ row_color_1, row_color_2, row_color_3 ]
+
+    (@default_row_count/3).times do
+      expect_background_color( row_color_1 )
+      expect_background_color( row_color_2 )
+      expect_background_color( row_color_3 )
+    end
+
+    Prawn::Document.new.table(@data, :row_colors =&gt; row_colors )
+  end
+end
+
 describe &quot;A table's content&quot; do
 
   it &quot;should output content cell by cell, row by row&quot; do
@@ -109,7 +202,7 @@ describe &quot;A table's content&quot; do
       @pdf.table(data)
     }.should.not.raise
   end   
-  
+
   it &quot;should paginate for large tables&quot; do
     # 30 rows fit on the table with default setting, 31 exceed.
     data = [[&quot;foo&quot;]] * 31</diff>
      <filename>spec/table_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>89989e0dfd9f48783ddd16f6a0f777064aaf9112</id>
    </parent>
  </parents>
  <author>
    <name>Gavin Stark</name>
    <email>g.stark@realdigitalmedia.com</email>
  </author>
  <url>http://github.com/sandal/prawn/commit/22697cabb6c729dcf2e3f3b0fb149eb1b7d6817a</url>
  <id>22697cabb6c729dcf2e3f3b0fb149eb1b7d6817a</id>
  <committed-date>2008-11-06T22:33:18-08:00</committed-date>
  <authored-date>2008-11-06T22:33:18-08:00</authored-date>
  <message>[#105 state:resolved] Added specs for row background color and fixed the code such that the header color is properly set (it was being included in the row background coloring iteration.)</message>
  <tree>5b10bdea0339d6cf5adaed5fa1a9d2316c0c0960</tree>
  <committer>
    <name>Gavin Stark</name>
    <email>g.stark@realdigitalmedia.com</email>
  </committer>
</commit>
