From 7fb417235919a4c577f2c456db28edc63dc18d63 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 08:52:18 +0100 Subject: Refs #5291@0.5h; Update view Update the view to match the actual controller behaviour. --- spec/views/offer_workbenches/show.html.erb_spec.rb | 35 ++++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'spec/views') diff --git a/spec/views/offer_workbenches/show.html.erb_spec.rb b/spec/views/offer_workbenches/show.html.erb_spec.rb index 44dfe88f1..cc01c9d0e 100644 --- a/spec/views/offer_workbenches/show.html.erb_spec.rb +++ b/spec/views/offer_workbenches/show.html.erb_spec.rb @@ -1,5 +1,18 @@ require 'spec_helper' +RSpec::Matchers.define :have_box_for_item do |item, disabled| + match do |actual| + klass = "#{TableBuilderHelper.item_row_class_name([item])}-#{item.id}" + if disabled + selector = "tr.#{klass} [type=checkbox][disabled][value='#{item.id}']" + else + selector = "tr.#{klass} [type=checkbox][value='#{item.id}']:not([disabled])" + end + expect(actual).to have_selector(selector, count: 1) + end + description { "have a #{disabled ? "disabled ": ""}box for the item ##{item.id}" } +end + describe "workbenches/show", :type => :view do let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] } let!(:lines) { @@ -18,7 +31,7 @@ describe "workbenches/show", :type => :view do before :each do lines controller.request.path_parameters[:id] = workbench.id - expect(workbench.referentials).to include same_organisation_referential + expect(workbench.referentials).to include same_organisation_referential expect(workbench.referentials).to_not include different_organisation_referential expect(workbench.all_referentials).to include same_organisation_referential expect(workbench.all_referentials).to include different_organisation_referential @@ -26,15 +39,19 @@ describe "workbenches/show", :type => :view do end it { should have_link_for_each_item(referentials, "show", -> (referential){ view.referential_path(referential) }) } - it "should enable the checkbox for the referential which belongs to the same organisation" do - klass = "#{TableBuilderHelper.item_row_class_name(referentials)}-#{same_organisation_referential.id}" - selector = "tr.#{klass} [type=checkbox][value='#{same_organisation_referential.id}']:not([disabled])" - expect(rendered).to have_selector(selector, count: 1) + + context "without permission" do + it "should disable all the checkboxes" do + expect(rendered).to have_box_for_item same_organisation_referential, false + expect(rendered).to have_box_for_item different_organisation_referential, true + end end - it "should disable the checkbox for the referential which does not belong to the same organisation" do - klass = "#{TableBuilderHelper.item_row_class_name(referentials)}-#{different_organisation_referential.id}" - selector = "tr.#{klass} [type=checkbox][disabled][value='#{different_organisation_referential.id}']" - expect(rendered).to have_selector(selector, count: 1) + with_permission "referentials.destroy" do + it "should enable the checkbox for the referential which belongs to the same organisation and disable the other one" do + expect(rendered).to have_box_for_item same_organisation_referential, false + expect(rendered).to have_box_for_item different_organisation_referential, true + end end + end -- cgit v1.2.3