aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorZog2018-02-12 11:18:10 +0100
committerZog2018-02-12 11:18:10 +0100
commitb090709fa414939f8c561e9d14bcbb378015c67e (patch)
treee9dd671c94ecbfc3735fd86c89deb2a834b30eee /spec
parent7f044f8ab9cf9394c4180f3d467a74bd95dcd398 (diff)
downloadchouette-core-b090709fa414939f8c561e9d14bcbb378015c67e.tar.bz2
Refs #5877; Add a condition on TableBuilderHelper::Column5877-handle-nil-objects-in-tablebuilderhelper
Diffstat (limited to 'spec')
-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 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