diff options
| author | Zog | 2017-12-15 17:54:31 +0100 |
|---|---|---|
| committer | Zog | 2017-12-19 14:21:52 +0100 |
| commit | 3a78b0d44affe79ec297f1a25ee3cfe4ecd32a74 (patch) | |
| tree | de6b3e6a258a7cadb83a97f019f67576738522a5 /spec | |
| parent | 74a601f6f35e0a547d3cde0501081e6e9f509959 (diff) | |
| download | chouette-core-3a78b0d44affe79ec297f1a25ee3cfe4ecd32a74.tar.bz2 | |
Refs: #5291@1h; Update TableBuilderHelper
Update TableBuilderHelper to allow the `selectable` param to be a
lambda, thus allowing us to have row-based granularity.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/helpers/table_builder_helper_spec.rb | 81 | ||||
| -rw-r--r-- | spec/views/offer_workbenches/show.html.erb_spec.rb | 2 |
2 files changed, 81 insertions, 2 deletions
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 3b0a18379..8c77bd465 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -381,5 +381,86 @@ describe TableBuilderHelper, type: :helper do expect(beautified_html).to eq(expected.chomp) end + + context "on a single row" do + let(:referential){ build_stubbed :referential } + let(:other_referential){ build_stubbed :referential } + let(:user_context){ + UserContext.new( + build_stubbed( + :user, + organisation: referential.organisation, + permissions: [ + 'referentials.create', + 'referentials.update', + 'referentials.destroy', + ] + ), + referential: referential + ) + } + let(:columns){ + [ + TableBuilderHelper::Column.new( + key: :name, + attribute: 'name' + ), + ] + } + let(:item){ referential.decorate } + let(:other_item){ other_referential.decorate } + let(:selectable){ false } + let(:links){ [:show] } + let(:overhead){ [] } + let(:model_name){ "referential" } + let(:other_tr){ helper.send(:tr, other_item, columns, selectable, links, overhead, model_name) } + let(:items){ [item, other_item] } + + before(:each){ + allow(helper).to receive(:current_user).and_return(user_context) + } + + context "with all rows non-selectable" do + let(:selectable){ false } + it "sets all rows as non selectable" do + items.each do |i| + tr = helper.send(:tr, i, columns, selectable, links, overhead, model_name) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{i.id}" + selector = "tr.#{klass} [type=checkbox]" + expect(tr).to_not have_selector selector + end + end + end + + context "with all rows selectable" do + let(:selectable){ true } + it "adds a checkbox in all rows" do + items.each do |i| + tr = helper.send(:tr, i, columns, selectable, links, overhead, model_name) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{i.id}" + selector = "tr.#{klass} [type=checkbox]" + expect(tr).to have_selector selector + end + end + end + + context "with THIS row non selectable" do + let(:selectable){ ->(i){ i.id != item.id } } + it "adds a checkbox in all rows" do + items.each do |i| + tr = helper.send(:tr, i, columns, selectable, links, overhead, model_name) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{i.id}" + selector = "tr.#{klass} [type=checkbox]" + expect(tr).to have_selector selector + end + end + it "disables this rows checkbox" do + tr = helper.send(:tr, item, columns, selectable, links, overhead, model_name) + klass = "#{TableBuilderHelper.item_row_class_name([referential])}-#{item.id}" + selector = "tr.#{klass} [type=checkbox][disabled]" + expect(tr).to have_selector selector + end + end + end end end diff --git a/spec/views/offer_workbenches/show.html.erb_spec.rb b/spec/views/offer_workbenches/show.html.erb_spec.rb index 597335166..44dfe88f1 100644 --- a/spec/views/offer_workbenches/show.html.erb_spec.rb +++ b/spec/views/offer_workbenches/show.html.erb_spec.rb @@ -7,7 +7,6 @@ describe "workbenches/show", :type => :view do create :line, objectid: id, line_referential: workbench.line_referential end } - let!(:workbench){ assign :workbench, create(:workbench) } let!(:same_organisation_referential){ create :workbench_referential, workbench: workbench, metadatas: [create(:referential_metadata, lines: lines)] } let!(:different_organisation_referential){ create :workbench_referential, metadatas: [create(:referential_metadata, lines: lines)] } @@ -17,7 +16,6 @@ describe "workbenches/show", :type => :view do } let!(:q) { assign :q_for_form, Ransack::Search.new(Referential) } before :each do - lines controller.request.path_parameters[:id] = workbench.id expect(workbench.referentials).to include same_organisation_referential |
