diff options
| author | Luc Donnet | 2018-03-01 16:01:54 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-01 16:01:54 +0100 |
| commit | 28b44152c66039a052db8766a61ddfc6566d214d (patch) | |
| tree | ba6c63e2f271be80a114844947499733c14b6653 /spec | |
| parent | c283c5ea57445d5188b18e61b694ba9976bcf0da (diff) | |
| parent | b090709fa414939f8c561e9d14bcbb378015c67e (diff) | |
| download | chouette-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')
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 47 |
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 |
