aboutsummaryrefslogtreecommitdiffstats
path: root/spec/helpers
diff options
context:
space:
mode:
authorLuc Donnet2018-03-01 16:01:54 +0100
committerGitHub2018-03-01 16:01:54 +0100
commit28b44152c66039a052db8766a61ddfc6566d214d (patch)
treeba6c63e2f271be80a114844947499733c14b6653 /spec/helpers
parentc283c5ea57445d5188b18e61b694ba9976bcf0da (diff)
parentb090709fa414939f8c561e9d14bcbb378015c67e (diff)
downloadchouette-core-28b44152c66039a052db8766a61ddfc6566d214d.tar.bz2
Merge pull request #302 from af83/5877-handle-nil-objects-in-tablebuilderhelper
5877 Add a condition on TableBuilderHelper::Column
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/table_builder_helper_spec.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 478875118..b0c17859f 100644
--- a/spec/helpers/table_builder_helper_spec.rb
+++ b/spec/helpers/table_builder_helper_spec.rb
@@ -441,6 +441,53 @@ describe TableBuilderHelper, type: :helper do
allow(helper).to receive(:mutual_workbench).and_return(referential.workbench)
}
+ 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