Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@paulspringett authored
Showing with 21 additions and 1 deletion.
  1. +1 −1  lib/csv_shaper/row.rb
  2. +20 −0 spec/row_spec.rb
View
2  lib/csv_shaper/row.rb
@@ -60,7 +60,7 @@ def cells(*args)
def cell(column, value = nil)
column = column.to_sym
- if @model && value.nil?
+ if @model && @model.respond_to?(column) && value.nil?
@cells[column] = @model.send(column)
else
@cells[column] = value
View
20 spec/row_spec.rb
@@ -22,4 +22,24 @@
csv.should be_kind_of(CsvShaper::Row)
}
end
+
+ describe "cells" do
+ it "should send parse an attribute of the model" do
+ row = CsvShaper::Row.new(user, :gender)
+ row.cell :name
+ row.cells.should eq({ name: 'Paul', gender: 'Male' })
+ end
+
+ it "should send assign an unrelated value" do
+ row = CsvShaper::Row.new(user, :gender)
+ row.cell :foo, 'bar'
+ row.cells.should eq({ foo: 'bar', gender: 'Male' })
+ end
+
+ it "ignore nil values passed" do
+ row = CsvShaper::Row.new(user, :gender)
+ row.cell :foo, nil
+ row.cells.should eq({ foo: nil, gender: 'Male' })
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.