diff options
| author | Zog | 2017-12-18 08:52:18 +0100 |
|---|---|---|
| committer | Zog | 2017-12-19 17:02:37 +0100 |
| commit | 7fb417235919a4c577f2c456db28edc63dc18d63 (patch) | |
| tree | 0496b0e5f6193b67267fbe96701a56fe8bbdfaa4 | |
| parent | 926c0a338e86c7f0e1f651ba507e8120fb26ad17 (diff) | |
| download | chouette-core-7fb417235919a4c577f2c456db28edc63dc18d63.tar.bz2 | |
Refs #5291@0.5h; Update view
Update the view to match the actual controller behaviour.
| -rw-r--r-- | app/views/workbenches/show.html.slim | 2 | ||||
| -rw-r--r-- | spec/views/offer_workbenches/show.html.erb_spec.rb | 35 |
2 files changed, 27 insertions, 10 deletions
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index af312fc08..1c82c34b7 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -57,7 +57,7 @@ attribute: '' \ ) \ ], - selectable: true, + selectable: ->(ref){ @workbench.referentials.include?(ref) }, links: [:show, :edit], cls: 'table has-filter has-search' 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 |
