Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix Row#cell nil assignment bug #8

Merged
merged 1 commit into from Aug 18, 2012
Jump to file or symbol
Failed to load files and symbols.
+21 −1
Split
View
@@ -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
@@ -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