Skip to content

Commit

Permalink
compare with zero, not present
Browse files Browse the repository at this point in the history
  • Loading branch information
ajb committed Feb 27, 2014
1 parent 8328a45 commit 1bf9f32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/formbuilder/response_field_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def render_entry(value, opts = {})
total = opts.try(:[], :entry).try(:get_responses).try(:[], "#{self.id}_sum_#{column}")

str += """
<td><span>#{total.present? ? total : ''}</span></td>
<td><span>#{total.to_f > 0 ? total : ''}</span></td>
"""
end

Expand Down
15 changes: 14 additions & 1 deletion spec/models/formbuilder/response_field_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,21 @@
end

describe '#render_entry' do
it 'does not trip on blanks' do
rendered = rf.render_entry(
{'column one' => ['bar', 'baz']},
entry: OpenStruct.new(get_responses: {})
)
expect(rendered).to match 'bar'
expect(rendered).to match 'baz'
expect(rendered).to_not match '0'
end

it 'does not render zeroes' do
rendered = rf.render_entry({'column one' => ['bar', 'baz']})
rendered = rf.render_entry(
{'column one' => ['bar', 'baz']},
entry: OpenStruct.new(get_responses: {"#{rf.id}_sum_column one" => '0.0'})
)
expect(rendered).to match 'bar'
expect(rendered).to match 'baz'
expect(rendered).to_not match '0'
Expand Down

0 comments on commit 1bf9f32

Please sign in to comment.