aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2017-12-18 08:52:18 +0100
committerZog2017-12-19 14:21:52 +0100
commit0403917aab03cfc3200f62e70f255bc7887cdcdf (patch)
treea417a100bd8e9c6dd9eb583683733670c7e3c550
parent3a78b0d44affe79ec297f1a25ee3cfe4ecd32a74 (diff)
downloadchouette-core-0403917aab03cfc3200f62e70f255bc7887cdcdf.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.slim2
-rw-r--r--spec/views/offer_workbenches/show.html.erb_spec.rb35
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