<commit_before>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

    context '.available?' do
      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<commit_msg>Remove available spec in columns. Add specs for human name.<commit_after>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).to eq("Whatever")
    end

    it "humanizes the symbol if no label is set" do
      column = FactoryGirl.build(:column, name: :email)
      expect(column.human_name).to eq("Email")
    end
  end
end
{'fraction_non_alphanumeric': 0.12352221769262128, 'fraction_numerical': 0.0, 'mean_word_length': 3.4945054945054945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2814832', 'n_tokens_mistral': 777, 'n_tokens_neox': 756, 'n_words': 196}