From 7f85e8bbb15ec4063dad8b080e61d690b77dead7 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 1 Sep 2017 14:51:07 +0200 Subject: TableBuilderHelper::Column: Add `#linkable?` method This tells the markup assembler whether or not this column should be wrapped in a link (``). It intends to serve the same purpose as `TableBuilderHelper#column_is_linkable`, but at the column level. The idea is to remove that method when these links only operate by column and not by pre-defined values like before/now. --- app/helpers/table_builder_helper/column.rb | 4 ++++ spec/helpers/table_builder_helper/column_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb index ef3c0b629..b4c569882 100644 --- a/app/helpers/table_builder_helper/column.rb +++ b/app/helpers/table_builder_helper/column.rb @@ -31,6 +31,10 @@ module TableBuilderHelper I18n.t("activerecord.attributes.#{model_key}.#{@key}") end + def linkable? + !@link_to.nil? + end + def link_to(obj) @link_to.call(obj) end diff --git a/spec/helpers/table_builder_helper/column_spec.rb b/spec/helpers/table_builder_helper/column_spec.rb index 0c5c89e8a..e0bfd8a6a 100644 --- a/spec/helpers/table_builder_helper/column_spec.rb +++ b/spec/helpers/table_builder_helper/column_spec.rb @@ -21,6 +21,29 @@ describe TableBuilderHelper::Column do 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') -- cgit v1.2.3