aboutsummaryrefslogtreecommitdiffstats
path: root/spec/helpers/table_builder_helper/column_spec.rb
blob: e0bfd8a6afd02299aba9d3d4730aa82b6204700f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'spec_helper'

describe TableBuilderHelper::Column do
  describe "#header_label" do
    it "returns the column @name if present" do
      expect(
        TableBuilderHelper::Column.new(
          name: 'ID Codif',
          attribute: nil
        ).header_label
      ).to eq('ID Codif')
    end

    it "returns the I18n translation of @key if @name not present" do
      expect(
        TableBuilderHelper::Column.new(
          key: :phone,
          attribute: 'phone'
        ).header_label(Chouette::Company)
      ).to eq('Numéro de téléphone')
    end
  end

  describe "#linkable?" do
    it "returns true if :link_to is not nil" do
      expect(
        TableBuilderHelper::Column.new(
          name: 'unused',
          attribute: nil,
          link_to: lambda do
            train.kind
          end
        ).linkable?
      ).to be true
    end

    it "returns false if :link_to is nil" do
      expect(
        TableBuilderHelper::Column.new(
          name: 'unused',
          attribute: nil
        ).linkable?
      ).to be false
    end
  end

  describe "#link_to" do
    it "calls the block passed in and returns the result" do
      train = double('train', kind: 'TGV')

      expect(
        TableBuilderHelper::Column.new(
          name: 'unused',
          attribute: nil,
          link_to: lambda do |train|
            train.kind
          end
        ).link_to(train)
      ).to eq('TGV')
    end
  end
end