From b090709fa414939f8c561e9d14bcbb378015c67e Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 12 Feb 2018 11:18:10 +0100 Subject: Refs #5877; Add a condition on TableBuilderHelper::Column --- spec/helpers/table_builder_helper_spec.rb | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'spec/helpers') diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 5bddbb16f..aff63ec59 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -435,6 +435,53 @@ describe TableBuilderHelper, type: :helper do allow(helper).to receive(:current_user).and_return(user_context) } + context "with a condition" do + let(:columns){ + [ + TableBuilderHelper::Column.new( + key: :name, + attribute: 'name', + if: condition + ), + ] + } + + context "when the condition is true" do + let(:condition){ ->(obj){true} } + it "should show the value" do + items.each do |i| + tr = helper.send(:tr, i, columns, selectable, links, overhead, model_name, :index) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{i.id}" + expect(tr).to include(i.name) + end + end + end + + context "when the condition depends on the object" do + let(:condition){ ->(obj){ obj == referential } } + it "should show the value accordingly" do + tr = helper.send(:tr, item, columns, selectable, links, overhead, model_name, :index) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{referential.id}" + expect(tr).to include(referential.name) + tr = helper.send(:tr, other_item, columns, selectable, links, overhead, model_name, :index) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{other_referential.id}" + expect(tr).to_not include(other_referential.name) + end + end + + context "when the condition is false" do + let(:condition){ ->(obj){false} } + it "should not show the value" do + items.each do |i| + tr = helper.send(:tr, i, columns, selectable, links, overhead, model_name, :index) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{i.id}" + expect(tr).to_not include(i.name) + end + end + end + + end + context "with all rows non-selectable" do let(:selectable){ false } it "sets all rows as non selectable" do -- cgit v1.2.3