Permalink
Browse files

Cleanup column spec.

  • Loading branch information...
1 parent 2ecec3f commit dd8f0a9943e7ac6a1b197bb15f971bbc6dfd0596 @bobbytables committed Dec 14, 2012
Showing with 15 additions and 27 deletions.
  1. +15 −27 spec/lib/column_spec.rb
View
@@ -3,51 +3,39 @@
describe TableCloth::Column do
subject { Class.new(TableCloth::Column) }
let(:view_context) { ActionView::Base.new }
- 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) }
context 'values' do
- let(:name_column) do
- TableCloth::Column.new(:name)
+ let(:proc) do
+ lambda {|object, view| object.email.gsub("@", " at ")}
end
- let(:email_column) do
- proc = lambda {|object, view|
- object.email
- }
-
- TableCloth::Column.new(:my_email, proc: proc)
- end
+ let(:name_column) { TableCloth::Column.new(:name) }
+ let(:email_column) { TableCloth::Column.new(:my_email, proc: proc) }
it 'returns the name correctly' do
name_column.value(dummy_model, view_context).should == 'robert'
end
it 'returns the email from a proc correctly' do
- email_column.value(dummy_model, view_context).should == 'robert@example.com'
+ email_column.value(dummy_model, view_context).should == 'robert at example.com'
end
context '.available?' do
- let(:dummy_table) do
- Class.new(TableCloth::Table) do
- column :name, if: :admin?
-
- def admin?
- view.admin?
- end
- end
- end
-
it 'returns true on successful constraint' do
table = Class.new(DummyTable).new([dummy_model], view_context)
column = TableCloth::Column.new(:name, if: :admin?)
column.available?(table).should be_true
end
+
+ it 'returns false on failed constraints' do
+ table = Class.new(DummyTable).new([dummy_model], view_context)
+ table.stub admin?: false
+
+
+ column = TableCloth::Column.new(:name, if: :admin?)
+ column.available?(table).should be_false
+ end
end
end
end

0 comments on commit dd8f0a9

Please sign in to comment.