Skip to content
This repository
Browse code

Fixed bug where passed a nil value to Row#cell would be treated

as though there was no second value
  • Loading branch information...
commit cd70ded30e1c5db0b9dae359196d0324d24f4fb5 1 parent 13b138b
Paul Springett authored August 18, 2012
2  lib/csv_shaper/row.rb
@@ -60,7 +60,7 @@ def cells(*args)
60 60
     def cell(column, value = nil)
61 61
       column = column.to_sym
62 62
       
63  
-      if @model && value.nil?
  63
+      if @model && @model.respond_to?(column) && value.nil?
64 64
         @cells[column] = @model.send(column)
65 65
       else
66 66
         @cells[column] = value
20  spec/row_spec.rb
@@ -22,4 +22,24 @@
22 22
       csv.should be_kind_of(CsvShaper::Row)
23 23
     }
24 24
   end
  25
+  
  26
+  describe "cells" do
  27
+    it "should send parse an attribute of the model" do
  28
+      row = CsvShaper::Row.new(user, :gender)
  29
+      row.cell :name
  30
+      row.cells.should eq({ name: 'Paul', gender: 'Male' })
  31
+    end
  32
+    
  33
+    it "should send assign an unrelated value" do
  34
+      row = CsvShaper::Row.new(user, :gender)
  35
+      row.cell :foo, 'bar'
  36
+      row.cells.should eq({ foo: 'bar', gender: 'Male' })
  37
+    end
  38
+    
  39
+    it "ignore nil values passed" do
  40
+      row = CsvShaper::Row.new(user, :gender)
  41
+      row.cell :foo, nil
  42
+      row.cells.should eq({ foo: nil, gender: 'Male' })
  43
+    end
  44
+  end
25 45
 end

0 notes on commit cd70ded

Please sign in to comment.
Something went wrong with that request. Please try again.