Skip to content

Commit

Permalink
Merge pull request #34 from mvdamme/fix_presenter_bug
Browse files Browse the repository at this point in the history
Fixed presenter bug related to combining html_safe cell content and td_options
  • Loading branch information
bobbytables committed Jun 16, 2014
2 parents f5b6309 + 4677011 commit a1985ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/table_cloth/presenters/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def row_for_object(object)
end

def column_for_object(column, object)
td_options = column.options[:td_options] || {}
td_options = column.options[:td_options].try(:dup) || {}
value = column.value(object, view_context, table)

if value.is_a?(Array)
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/presenters/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,20 @@
end
end
end

context 'html_safe cell content with td_options' do
let(:objects) do
list = FactoryGirl.build_list(:dummy_model, 3, :name => nil)
list.first.name = 'robert'
list
end
let(:dummy_table) { Class.new(DummyTableWithHTMLSafe) }

it 'only outputs html_safe content in the correct column' do
tbody = Nokogiri::HTML(subject.tbody.to_s).at_xpath('//tbody')

expect( tbody.xpath('//td').map(&:content) ).to eq ['robert', '', '']
end
end
end
end
5 changes: 5 additions & 0 deletions spec/support/dummy_table_with_html_safe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DummyTableWithHTMLSafe < TableCloth::Base
column :name, td_options: { class: 'irrelevant' } do |object|
object.name.html_safe if object.name
end
end

0 comments on commit a1985ec

Please sign in to comment.