Sha256: 24f9626726502a2c21dd5217f5eda134b5189a4e93232862dce6b229bfc47305

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

require 'spec_helper'

describe TableCloth::Column do
  subject { Class.new(TableCloth::Column) }
  let(:view_context) { ActionView::Base.new }
  let(:dummy_model) { FactoryGirl.build(:dummy_model) }

  context 'values' do
    let(:proc) do
      lambda {|object, view| object.email.gsub("@", " at ")}
    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 at example.com'
    end
  end

  context "human name" do
    it "returns the label when set" do
      column = FactoryGirl.build(:column, options: { label: "Whatever" })
      expect(column.human_name(view_context)).to eq("Whatever")
    end

    it "humanizes the symbol if no label is set" do
      column = FactoryGirl.build(:column, name: :email)
      expect(column.human_name(view_context)).to eq("Email")
    end

    it "runs with a proc" do
      column = FactoryGirl.build(:column, options: { label: Proc.new{ tag :span }} )
      expect(column.human_name(view_context)).to eq("<span />")
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
table_cloth-0.4.3 spec/lib/column_spec.rb
table_cloth-0.4.2 spec/lib/column_spec.rb
table_cloth-0.4.1 spec/lib/column_spec.rb
table_cloth-0.4.0 spec/lib/column_spec.rb
table_cloth-0.3.2 spec/lib/column_spec.rb
table_cloth-0.3.1.alpha1 spec/lib/column_spec.rb