Skip to content
Browse files

Include specs to ensure that columns aren't included when unavailable.

  • Loading branch information...
1 parent 0e130a1 commit 6d1d929d13cf033f398529fdecf3f7e14193f05b @bobbytables committed
Showing with 37 additions and 3 deletions.
  1. +8 −2 lib/table_cloth/presenter.rb
  2. +11 −0 spec/factories/dummy_tables.rb
  3. +18 −1 spec/lib/presenter_spec.rb
View
10 lib/table_cloth/presenter.rb
@@ -28,8 +28,14 @@ def render_rows
def columns
@columns ||= table.class.columns.map do |name, options|
- options[:class].new(name, options[:options])
- end
+ column = options[:class].new(name, options[:options])
+
+ if ColumnJury.new(column, table).available?
+ column
+ else
+ nil
+ end
+ end.compact
end
def column_names
View
11 spec/factories/dummy_tables.rb
@@ -0,0 +1,11 @@
+FactoryGirl.define do
+ factory :dummy_table, class: "TableCloth::Base" do
+ initialize_with do
+ Class.new(TableCloth::Base).tap do |klass|
+ attributes.each do |key,attribute|
+ klass.column *[key, attribute]
+ end
+ end
+ end
+ end
+end
View
19 spec/lib/presenter_spec.rb
@@ -20,6 +20,23 @@
expect(column).to be_kind_of TableCloth::Column
end
end
+
+ context "that are unavaialble" do
+ let(:dummy_table) { FactoryGirl.build(:dummy_table, email: {if: :admin?}) }
+ let(:table_instance) { dummy_table.new(objects, view_context) }
+ before(:each) do
+ table_instance.stub admin?: false
+ subject.stub table: table_instance
+ end
+
+ specify "are not returned" do
+ expect(subject).to have(0).columns
+ end
+
+ specify "name is not returned" do
+ expect(subject.column_names).not_to include "email"
+ end
+ end
end
context ".column_names" do
@@ -27,7 +44,7 @@
before(:each) { table_instance.stub admin?: false, awesome?: true }
it 'returns all names' do
- subject.column_names.should =~ ["Id", "Name", "Email"]
+ subject.column_names.should == ["Id", "Name", "Email"]
end
end

0 comments on commit 6d1d929

Please sign in to comment.
Something went wrong with that request. Please try again.