Permalink
Browse files

Cleanup presenter spec.

  • Loading branch information...
1 parent dd8f0a9 commit 15b7c26db3a328961d94c67fac7e31295c40a604 @bobbytables committed Dec 14, 2012
Showing with 7 additions and 25 deletions.
  1. +7 −25 spec/lib/presenter_spec.rb
View
@@ -1,51 +1,33 @@
require 'spec_helper'
describe TableCloth::Presenter do
+ subject { TableCloth::Presenter.new(objects, dummy_table, view_context) }
let(:dummy_table) { Class.new(DummyTable) }
- let(:dummy_model) do
- DummyModel.new.tap do |d|
- d.id = 1
- d.email = 'robert@example.com'
- d.name = 'robert'
- end
- end
+ let(:dummy_model) { FactoryGirl.build(:dummy_model) }
- let(:objects) do
- 3.times.map do |n|
- num = n+1
- DummyModel.new.tap do |d|
- d.id = num # Wat
- d.email = "robert#{num}@example.com"
- d.name = "robert#{num}"
- end
- end
- end
+ let(:objects) { 3.times.map { FactoryGirl.build(:dummy_model) } }
let(:view_context) { ActionView::Base.new }
subject { TableCloth::Presenter.new(objects, dummy_table, view_context) }
it 'returns all values for a row' do
- subject.row_values(dummy_model).should == [1, 'robert', 'robert@example.com']
+ subject.row_values(dummy_model).should == [dummy_model.id, dummy_model.name, dummy_model.email]
end
it 'returns an edit link in the actions column' do
dummy_table.actions do
action {|object, view| link_to 'Edit', '/model/1/edit' }
end
- presenter = TableCloth::Presenter.new(objects, dummy_table, view_context)
- actions_value = presenter.row_values(dummy_model).last
+ actions_value = subject.row_values(dummy_model).last
column = Nokogiri::HTML(actions_value)
column.at_xpath('//a')[:href].should == '/model/1/edit'
column.at_xpath('//a').text.should == 'Edit'
end
it 'generates the values for all of the rows' do
- subject.rows.should == [
- [1, 'robert1', 'robert1@example.com'],
- [2, 'robert2', 'robert2@example.com'],
- [3, 'robert3', 'robert3@example.com']
- ]
+ expected = objects.map {|o| [o.id, o.name, o.email] }
+ expect(subject.rows).to eq(expected)
end
context 'tags' do

0 comments on commit 15b7c26

Please sign in to comment.