spec/admino/table/presenter_spec.rb in admino-0.0.12 vs spec/admino/table/presenter_spec.rb in admino-0.0.13
- old
+ new
@@ -15,16 +15,16 @@
let(:head_row) { double('HeadRow', to_html: '<td id="thead_td"></td>'.html_safe) }
let(:resource_row) { double('ResourceRow', to_html: '<td id="tbody_td"></td>'.html_safe) }
before do
- HeadRow.stub(:new).with(Post, query, view).and_return(head_row)
- ResourceRow.stub(:new).with(first_post, view).and_return(resource_row)
- ResourceRow.stub(:new).with(second_post, view).and_return(resource_row)
+ allow(HeadRow).to receive(:new).with(Post, query, view).and_return(head_row)
+ allow(ResourceRow).to receive(:new).with(first_post, view).and_return(resource_row)
+ allow(ResourceRow).to receive(:new).with(second_post, view).and_return(resource_row)
end
- describe '#.to_html' do
+ describe '#to_html' do
let(:result) { presenter.to_html }
it 'outputs a table' do
expect(result).to have_tag(:table)
end
@@ -37,12 +37,12 @@
expect(result).to have_tag('table tbody tr', count: 2)
end
context 'if the record responds to #dom_id' do
before do
- first_post.stub(:dom_id).and_return('post_1')
- second_post.stub(:dom_id).and_return('post_2')
+ allow(first_post).to receive(:dom_id).and_return('post_1')
+ allow(second_post).to receive(:dom_id).and_return('post_2')
end
it 'adds a record identifier to each collection row' do
expect(result).to have_tag('tbody tr#post_1:first-child')
expect(result).to have_tag('tbody tr#post_2:last-child')
@@ -160,9 +160,18 @@
expect(presenter.to_html).to have_tag('thead tr td#custom_thead_td')
end
it 'allows customizing resource row renderers' do
expect(presenter.to_html).to have_tag('tbody tr td#custom_tbody_td')
+ end
+ end
+
+ context 'with empty collection and no collection_klass' do
+ let(:collection) { [] }
+ subject(:presenter) { presenter_klass.new(collection, nil, query, view) }
+
+ it 'raises an Exception' do
+ expect { result }.to raise_error(ArgumentError)
end
end
end
end
end