From 8e55e7036aafb485058bf9122bf47cde73a54c33 Mon Sep 17 00:00:00 2001 From: Zog Date: Thu, 14 Dec 2017 16:42:00 +0100 Subject: Remove duplicate links in StopArea index view Refs #5287 --- app/views/stop_areas/index.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index c4d880081..99b399f5c 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -51,7 +51,7 @@ attribute: Proc.new { |s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}")) } \ ), \ ], - links: [:show, :edit, :delete], + links: [:show], cls: 'table has-filter has-search' = new_pagination @stop_areas, 'pull-right' -- cgit v1.2.3 From 676f45e8fd85c1422345d4d27ba2385e4bd536fe Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 09:11:04 +0100 Subject: Refs #5287; Add specs for the view. Refactor to come --- app/helpers/table_builder_helper.rb | 10 +++- spec/helpers/table_builder_helper_spec.rb | 6 +-- spec/support/integration_spec_helper.rb | 17 ++++++ spec/support/pundit/pundit_view_policy.rb | 16 +++--- spec/views/stop_areas/index.html.erb_spec.rb | 78 +++++++++++++++++++++++----- 5 files changed, 102 insertions(+), 25 deletions(-) create mode 100644 spec/support/integration_spec_helper.rb diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 37f01ce0d..64bec6bae 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -188,10 +188,16 @@ module TableBuilderHelper end def tbody(collection, columns, selectable, links, overhead) + if collection.respond_to?(:model) + model_name = collection.model.name.split("::").last + else + model_name = "item" + end + content_tag :tbody do collection.map do |item| - - content_tag :tr do + klass = "#{model_name.parameterize}-#{item.id}" + content_tag :tr, class: klass do bcont = [] if selectable diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 3b0a18379..3b3504c60 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -59,7 +59,7 @@ describe TableBuilderHelper, type: :helper do - +
@@ -213,7 +213,7 @@ describe TableBuilderHelper, type: :helper do - + #{company.get_objectid.local_id} #{company.name} @@ -326,7 +326,7 @@ describe TableBuilderHelper, type: :helper do - + #{company.get_objectid.local_id} #{company.name} diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb new file mode 100644 index 000000000..958aab9d5 --- /dev/null +++ b/spec/support/integration_spec_helper.rb @@ -0,0 +1,17 @@ +module IntegrationSpecHelper + extend ActiveSupport::Concern + + included do + def self.with_permission permission, &block + context "with permission #{permission}" do + let(:permissions){ [permission] } + context('', &block) if block_given? + end + end + end +end + + +RSpec.configure do |config| + config.include IntegrationSpecHelper, type: :view +end diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index b8434cac0..02a78a4e0 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -3,14 +3,16 @@ module Pundit extend ActiveSupport::Concern included do + + let(:permissions){ nil } + let(:current_referential){ build_stubbed :referential } + let(:current_user){ build_stubbed :user, permissions: permissions } + let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } before do - controller.singleton_class.class_eval do - def policy(instance) - Class.new do - def method_missing(*args, &block); true; end - end.new - end - helper_method :policy + allow(view).to receive(:pundit_user) { pundit_user } + + allow(view).to receive(:policy) do |instance| + ::Pundit.policy pundit_user, instance end end end diff --git a/spec/views/stop_areas/index.html.erb_spec.rb b/spec/views/stop_areas/index.html.erb_spec.rb index 2dfae1bfd..a354586d2 100644 --- a/spec/views/stop_areas/index.html.erb_spec.rb +++ b/spec/views/stop_areas/index.html.erb_spec.rb @@ -1,25 +1,77 @@ require 'spec_helper' describe "/stop_areas/index", :type => :view do - let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } - let!(:stop_areas) { assign :stop_areas, Array.new(2) { create(:stop_area, stop_area_referential: stop_area_referential) }.paginate } + let!(:stop_areas) do + 2.times { create(:stop_area, stop_area_referential: stop_area_referential) } + assign :stop_areas, ModelDecorator.decorate( Chouette::StopArea.page(1), with: StopAreaDecorator ) + end let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } before :each do allow(view).to receive(:link_with_search).and_return("#") + allow(view).to receive(:collection).and_return(stop_areas) + allow(view).to receive(:current_referential).and_return(stop_area_referential) + controller.request.path_parameters[:stop_area_referential_id] = stop_area_referential.id + render + end + + it "should render a row for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id}", count: 1) + end + end + + it "should render a show link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1) + end + end + + it "should render no other link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 1) + end end - # it "should render a show link for each group" do - # render - # stop_areas.each do |stop_area| - # expect(rendered).to have_selector(".stop_area a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", :text => stop_area.name) - # end - # end - # - # it "should render a link to create a new group" do - # render - # expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_stop_area_referential_stop_area_path(stop_area_referential)}']") - # end + with_permission "stop_areas.create" do + it "should render a show link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1) + end + end + + it "should render a create link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.new_stop_area_referential_stop_area_path(stop_area_referential)}']", count: 1) + end + end + + it "should render no other link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 2) + end + end + end + + with_permission "stop_areas.update" do + it "should render a show link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1) + end + end + + it "should render a edit link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area.id)}']", count: 1) + end + end + + it "should render no other link for each group" do + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 2) + end + end + end end -- cgit v1.2.3 From 357563bbf408aa2000097ee200dfbfba1f677121 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 11:27:14 +0100 Subject: - Fix specs on connections_links/index - Fix specs on connections_links/show - Update pundit view specs helper to use the current referential when it has already been defined --- spec/support/pundit/pundit_view_policy.rb | 5 +++-- spec/views/connection_links/index.html.erb_spec.rb | 8 +++++--- spec/views/connection_links/show.html.erb_spec.rb | 23 ++++++++++------------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 02a78a4e0..6a663a471 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -5,8 +5,9 @@ module Pundit included do let(:permissions){ nil } - let(:current_referential){ build_stubbed :referential } - let(:current_user){ build_stubbed :user, permissions: permissions } + let(:organisation){ referential.try(:organisation) } + let(:current_referential){ referential || build_stubbed(:referential) } + let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } before do allow(view).to receive(:pundit_user) { pundit_user } diff --git a/spec/views/connection_links/index.html.erb_spec.rb b/spec/views/connection_links/index.html.erb_spec.rb index a01380094..1f133e31e 100644 --- a/spec/views/connection_links/index.html.erb_spec.rb +++ b/spec/views/connection_links/index.html.erb_spec.rb @@ -17,9 +17,11 @@ describe "/connection_links/index", :type => :view do end end - it "should render a link to create a new group" do - render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_connection_link_path(referential)}']") + with_permission "connection_links.create" do + it "should render a link to create a new group" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_connection_link_path(referential)}']") + end end end diff --git a/spec/views/connection_links/show.html.erb_spec.rb b/spec/views/connection_links/show.html.erb_spec.rb index c04a4f3f1..afe94fc6c 100644 --- a/spec/views/connection_links/show.html.erb_spec.rb +++ b/spec/views/connection_links/show.html.erb_spec.rb @@ -15,21 +15,18 @@ describe "/connection_links/show", :type => :view do expect(rendered).to have_selector("h2", :text => Regexp.new(connection_link.name)) end -# it "should display a map with class 'connection_link'" do -# pending ": map not yet implemented" -# render -# expect(rendered).to have_selector("#map", :class => 'connection_link') -# end - - it "should render a link to edit the connection_link" do - render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_connection_link_path(referential, connection_link)}']") + with_permission "connection_links.update" do + it "should render a link to edit the connection_link" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_connection_link_path(referential, connection_link)}']") + end end - it "should render a link to remove the connection_link" do - render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_connection_link_path(referential, connection_link)}'][class='remove']") + with_permission "connection_links.destroy" do + it "should render a link to remove the connection_link" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_connection_link_path(referential, connection_link)}'][class='remove']") + end end end - -- cgit v1.2.3 From 2091a1ababa68810f42257fb392692f80b3bd78f Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 14:52:33 +0100 Subject: Refactor stopareas index specs --- spec/views/stop_areas/index.html.erb_spec.rb | 78 ++++++++++------------------ 1 file changed, 27 insertions(+), 51 deletions(-) diff --git a/spec/views/stop_areas/index.html.erb_spec.rb b/spec/views/stop_areas/index.html.erb_spec.rb index a354586d2..e0c50685c 100644 --- a/spec/views/stop_areas/index.html.erb_spec.rb +++ b/spec/views/stop_areas/index.html.erb_spec.rb @@ -1,6 +1,25 @@ require 'spec_helper' +RSpec::Matchers.define :have_link_for_each_stop_area do |stop_areas, name, href| + match do |actual| + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{href.call(stop_area)}']", count: 1) + end + end + description { "have #{name} link for each stop area" } +end + +RSpec::Matchers.define :have_the_right_number_of_links do |stop_areas, count| + match do |actual| + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: count) + end + end + description { "have #{count} links for each stop area" } +end + describe "/stop_areas/index", :type => :view do + let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } let!(:stop_areas) do 2.times { create(:stop_area, stop_area_referential: stop_area_referential) } @@ -16,62 +35,19 @@ describe "/stop_areas/index", :type => :view do render end - it "should render a row for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id}", count: 1) - end - end - - it "should render a show link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1) - end - end - - it "should render no other link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 1) - end - end + it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_the_right_number_of_links(stop_areas, 1) } with_permission "stop_areas.create" do - it "should render a show link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1) - end - end - - it "should render a create link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.new_stop_area_referential_stop_area_path(stop_area_referential)}']", count: 1) - end - end - - it "should render no other link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 2) - end - end + it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } + it { should have_the_right_number_of_links(stop_areas, 2) } end with_permission "stop_areas.update" do - it "should render a show link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", count: 1) - end - end - - it "should render a edit link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area.id)}']", count: 1) - end - end - - it "should render no other link for each group" do - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: 2) - end - end + it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_stop_area(stop_areas, "edit", -> (stop_area){ view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_the_right_number_of_links(stop_areas, 2) } end end -- cgit v1.2.3 From 548fe7f13d698fe9a6620ef60fc239f28347af79 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 09:25:10 +0100 Subject: Refs #5287; CR 1 - Get rid of ActiveSupport::Concern in the spec helpers - Rename misnamed spec files --- spec/support/integration_spec_helper.rb | 15 ++---- spec/support/pundit/pundit_view_policy.rb | 17 +++---- spec/views/connection_links/show.html.erb_spec.rb | 32 ------------- spec/views/connection_links/show.html.slim_spec.rb | 32 +++++++++++++ spec/views/stop_areas/index.html.erb_spec.rb | 53 ---------------------- spec/views/stop_areas/index.html.slim_spec.rb | 53 ++++++++++++++++++++++ 6 files changed, 97 insertions(+), 105 deletions(-) delete mode 100644 spec/views/connection_links/show.html.erb_spec.rb create mode 100644 spec/views/connection_links/show.html.slim_spec.rb delete mode 100644 spec/views/stop_areas/index.html.erb_spec.rb create mode 100644 spec/views/stop_areas/index.html.slim_spec.rb diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 958aab9d5..182cadf24 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -1,17 +1,12 @@ module IntegrationSpecHelper - extend ActiveSupport::Concern - - included do - def self.with_permission permission, &block - context "with permission #{permission}" do - let(:permissions){ [permission] } - context('', &block) if block_given? - end + def with_permission permission, &block + context "with permission #{permission}" do + let(:permissions){ [permission] } + context('', &block) if block_given? end end end - RSpec.configure do |config| - config.include IntegrationSpecHelper, type: :view + config.extend IntegrationSpecHelper, type: :view end diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index 6a663a471..91be0624c 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -1,15 +1,12 @@ module Pundit module PunditViewPolicy - extend ActiveSupport::Concern - - included do - - let(:permissions){ nil } - let(:organisation){ referential.try(:organisation) } - let(:current_referential){ referential || build_stubbed(:referential) } - let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } - let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } - before do + def self.included into + into.let(:permissions){ nil } + into.let(:organisation){ referential.try(:organisation) } + into.let(:current_referential){ referential || build_stubbed(:referential) } + into.let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } + into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } + into.before do allow(view).to receive(:pundit_user) { pundit_user } allow(view).to receive(:policy) do |instance| diff --git a/spec/views/connection_links/show.html.erb_spec.rb b/spec/views/connection_links/show.html.erb_spec.rb deleted file mode 100644 index afe94fc6c..000000000 --- a/spec/views/connection_links/show.html.erb_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'spec_helper' - -describe "/connection_links/show", :type => :view do - - assign_referential - let!(:connection_link) { assign(:connection_link, create(:connection_link)) } - let!(:map) { assign(:map, double(:to_html => '
'.html_safe)) } - - before do - allow(view).to receive_messages(current_organisation: referential.organisation) - end - - it "should render h2 with the connection_link name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(connection_link.name)) - end - - with_permission "connection_links.update" do - it "should render a link to edit the connection_link" do - render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_connection_link_path(referential, connection_link)}']") - end - end - - with_permission "connection_links.destroy" do - it "should render a link to remove the connection_link" do - render - expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_connection_link_path(referential, connection_link)}'][class='remove']") - end - end - -end diff --git a/spec/views/connection_links/show.html.slim_spec.rb b/spec/views/connection_links/show.html.slim_spec.rb new file mode 100644 index 000000000..afe94fc6c --- /dev/null +++ b/spec/views/connection_links/show.html.slim_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe "/connection_links/show", :type => :view do + + assign_referential + let!(:connection_link) { assign(:connection_link, create(:connection_link)) } + let!(:map) { assign(:map, double(:to_html => '
'.html_safe)) } + + before do + allow(view).to receive_messages(current_organisation: referential.organisation) + end + + it "should render h2 with the connection_link name" do + render + expect(rendered).to have_selector("h2", :text => Regexp.new(connection_link.name)) + end + + with_permission "connection_links.update" do + it "should render a link to edit the connection_link" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_connection_link_path(referential, connection_link)}']") + end + end + + with_permission "connection_links.destroy" do + it "should render a link to remove the connection_link" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_connection_link_path(referential, connection_link)}'][class='remove']") + end + end + +end diff --git a/spec/views/stop_areas/index.html.erb_spec.rb b/spec/views/stop_areas/index.html.erb_spec.rb deleted file mode 100644 index e0c50685c..000000000 --- a/spec/views/stop_areas/index.html.erb_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' - -RSpec::Matchers.define :have_link_for_each_stop_area do |stop_areas, name, href| - match do |actual| - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{href.call(stop_area)}']", count: 1) - end - end - description { "have #{name} link for each stop area" } -end - -RSpec::Matchers.define :have_the_right_number_of_links do |stop_areas, count| - match do |actual| - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: count) - end - end - description { "have #{count} links for each stop area" } -end - -describe "/stop_areas/index", :type => :view do - - let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } - let!(:stop_areas) do - 2.times { create(:stop_area, stop_area_referential: stop_area_referential) } - assign :stop_areas, ModelDecorator.decorate( Chouette::StopArea.page(1), with: StopAreaDecorator ) - end - let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } - - before :each do - allow(view).to receive(:link_with_search).and_return("#") - allow(view).to receive(:collection).and_return(stop_areas) - allow(view).to receive(:current_referential).and_return(stop_area_referential) - controller.request.path_parameters[:stop_area_referential_id] = stop_area_referential.id - render - end - - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should have_the_right_number_of_links(stop_areas, 1) } - - with_permission "stop_areas.create" do - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } - it { should have_the_right_number_of_links(stop_areas, 2) } - end - - with_permission "stop_areas.update" do - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should have_link_for_each_stop_area(stop_areas, "edit", -> (stop_area){ view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should have_the_right_number_of_links(stop_areas, 2) } - end - -end diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb new file mode 100644 index 000000000..e0c50685c --- /dev/null +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +RSpec::Matchers.define :have_link_for_each_stop_area do |stop_areas, name, href| + match do |actual| + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{href.call(stop_area)}']", count: 1) + end + end + description { "have #{name} link for each stop area" } +end + +RSpec::Matchers.define :have_the_right_number_of_links do |stop_areas, count| + match do |actual| + stop_areas.each do |stop_area| + expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: count) + end + end + description { "have #{count} links for each stop area" } +end + +describe "/stop_areas/index", :type => :view do + + let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } + let!(:stop_areas) do + 2.times { create(:stop_area, stop_area_referential: stop_area_referential) } + assign :stop_areas, ModelDecorator.decorate( Chouette::StopArea.page(1), with: StopAreaDecorator ) + end + let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } + + before :each do + allow(view).to receive(:link_with_search).and_return("#") + allow(view).to receive(:collection).and_return(stop_areas) + allow(view).to receive(:current_referential).and_return(stop_area_referential) + controller.request.path_parameters[:stop_area_referential_id] = stop_area_referential.id + render + end + + it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_the_right_number_of_links(stop_areas, 1) } + + with_permission "stop_areas.create" do + it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } + it { should have_the_right_number_of_links(stop_areas, 2) } + end + + with_permission "stop_areas.update" do + it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_stop_area(stop_areas, "edit", -> (stop_area){ view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_the_right_number_of_links(stop_areas, 2) } + end + +end -- cgit v1.2.3 From 129f10e701a72690091cd4e5af1c88e55194e12d Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Mon, 18 Dec 2017 19:18:31 +0100 Subject: Fix link use in StopArea name into stop_areas#index. Refs #5287 --- app/views/stop_areas/index.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index 99b399f5c..dbf3b848d 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -24,7 +24,7 @@ key: :name, \ attribute: 'name', \ link_to: lambda do |stop_area| \ - referential_stop_area_path( \ + stop_area_referential_stop_area_path( \ @stop_area_referential, \ stop_area \ ) \ -- cgit v1.2.3 From 4983eca8f4be6acf00589d4d34e7dc17377bb070 Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 19 Dec 2017 13:09:47 +0100 Subject: Refs #5287@0.5h; Use I18n in dashboard For calendars panel, instead of hardcoded string --- app/assets/stylesheets/components/_panels.sass | 1 + app/views/dashboards/_dashboard.html.slim | 2 +- config/locales/calendars.en.yml | 5 +++-- config/locales/calendars.fr.yml | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/components/_panels.sass b/app/assets/stylesheets/components/_panels.sass index e9f615081..ab25d8184 100644 --- a/app/assets/stylesheets/components/_panels.sass +++ b/app/assets/stylesheets/components/_panels.sass @@ -34,6 +34,7 @@ a text-decoration: none color: $blue + text-transform: capitalize &:hover, &:focus color: $darkblue diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim index e5aa5093a..7d547bf4c 100644 --- a/app/views/dashboards/_dashboard.html.slim +++ b/app/views/dashboards/_dashboard.html.slim @@ -22,7 +22,7 @@ .panel.panel-default .panel-heading h3.panel-title.with_actions - = link_to "Modèles de calendrier", calendars_path + = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), calendars_path div = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right' - if @dashboard.current_organisation.calendars.present? diff --git a/config/locales/calendars.en.yml b/config/locales/calendars.en.yml index 0076e5207..d3cc57677 100644 --- a/config/locales/calendars.en.yml +++ b/config/locales/calendars.en.yml @@ -56,8 +56,9 @@ en: end: End activerecord: models: - one: calendar - other: calendars + calendar: + one: calendar + other: calendars attributes: calendar: name: Name diff --git a/config/locales/calendars.fr.yml b/config/locales/calendars.fr.yml index fddb47d64..fc895bf89 100644 --- a/config/locales/calendars.fr.yml +++ b/config/locales/calendars.fr.yml @@ -56,8 +56,9 @@ fr: end: Fin activerecord: models: - one: "calendrier" - other: "calendriers" + calendar: + one: "calendrier" + other: "calendriers" attributes: calendar: name: Nom -- cgit v1.2.3 From eeaa2876f46e77c337fa30ab4b299acff3a29d09 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 19 Dec 2017 14:44:00 +0100 Subject: Remove update & create links Refs #5307 --- app/decorators/referential_line_decorator.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb index 55acf7ed9..654f68bf5 100644 --- a/app/decorators/referential_line_decorator.rb +++ b/app/decorators/referential_line_decorator.rb @@ -24,21 +24,6 @@ class ReferentialLineDecorator < Draper::Decorator ) ) - if h.policy(Chouette::Line).create? && - context[:referential].organisation == context[:current_organisation] - links << Link.new( - content: h.t('actions.new'), - href: h.new_referential_line_path(context[:referential]) - ) - end - - if h.policy(object).update? - links << Link.new( - content: h.t('actions.edit'), - href: h.edit_referential_line_path(context[:referential], object) - ) - end - if h.policy(object).destroy? links << Link.new( content: h.destroy_link_content('actions.destroy'), -- cgit v1.2.3 From 4b9eebda5bb81a214c87351c01c720c0cb0cf2e8 Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 19 Dec 2017 16:10:15 +0100 Subject: Refs #5287; Uniformize actions --- app/decorators/stop_area_decorator.rb | 9 --------- config/locales/stop_areas.en.yml | 2 +- config/locales/stop_areas.fr.yml | 2 +- spec/views/stop_areas/index.html.slim_spec.rb | 4 ++-- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 4e777292d..8b2ebf490 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -7,15 +7,6 @@ class StopAreaDecorator < Draper::Decorator links = [] stop_area ||= object - if h.policy(Chouette::StopArea).new? - links << Link.new( - content: h.t('stop_areas.actions.new'), - href: h.new_stop_area_referential_stop_area_path( - stop_area.stop_area_referential - ) - ) - end - if h.policy(stop_area).update? links << Link.new( content: h.t('stop_areas.actions.edit'), diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml index 324294892..54a5ebae5 100644 --- a/config/locales/stop_areas.en.yml +++ b/config/locales/stop_areas.en.yml @@ -15,7 +15,7 @@ en: actions: new: "Add a new stop" edit: "Edit this stop" - destroy: "Remove this stop" + destroy: "Remove" deleted_at: "Activated" destroy_confirm: "Are you sure you want destroy this stop and all of his children ?" select_parent: "Create or modify the relation child -> parent" diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml index bf4dd832f..f96a2e564 100644 --- a/config/locales/stop_areas.fr.yml +++ b/config/locales/stop_areas.fr.yml @@ -15,7 +15,7 @@ fr: actions: new: "Ajouter un arrêt" edit: "Editer cet arrêt" - destroy: "Supprimer cet arrêt" + destroy: "Supprimer" deleted_at: "Activé" destroy_confirm: "Etes vous sûr de supprimer cet arrêt ainsi que tous ses fils?" select_parent: "Créer ou éditer la relation enfant -> parent" diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb index e0c50685c..64c958879 100644 --- a/spec/views/stop_areas/index.html.slim_spec.rb +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -40,8 +40,8 @@ describe "/stop_areas/index", :type => :view do with_permission "stop_areas.create" do it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } - it { should have_the_right_number_of_links(stop_areas, 2) } + it { should_not have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } + it { should have_the_right_number_of_links(stop_areas, 1) } end with_permission "stop_areas.update" do -- cgit v1.2.3 From 2736ff5e010586266176a9a0fb0ac8dc6e227f63 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:01:49 +0100 Subject: Ref #5291@2h; Specs setup - Refactor specs helper to be more generic - Write missing specs for the Workbenches#show view We now have failing tests highlighting the bug --- app/helpers/table_builder_helper.rb | 20 +++++++---- spec/support/integration_spec_helper.rb | 30 ++++++++++++++++ spec/views/offer_workbenches/show.html.erb_spec.rb | 41 ++++++++++++++++++++-- spec/views/stop_areas/index.html.slim_spec.rb | 27 +++----------- 4 files changed, 87 insertions(+), 31 deletions(-) diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 64bec6bae..59906dc87 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -95,6 +95,18 @@ module TableBuilderHelper class: cls end + def self.item_row_class_name collection + if collection.respond_to?(:model) + model_name = collection.model.name + elsif collection.respond_to?(:first) + model_name = collection.first.class.name + else + model_name = "item" + end + + model_name.split("::").last.parameterize + end + private def thead(collection, columns, sortable, selectable, has_links, overhead, model ) @@ -188,15 +200,11 @@ module TableBuilderHelper end def tbody(collection, columns, selectable, links, overhead) - if collection.respond_to?(:model) - model_name = collection.model.name.split("::").last - else - model_name = "item" - end + model_name = TableBuilderHelper.item_row_class_name collection content_tag :tbody do collection.map do |item| - klass = "#{model_name.parameterize}-#{item.id}" + klass = "#{model_name}-#{item.id}" content_tag :tr, class: klass do bcont = [] diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 182cadf24..5bcf0bd3a 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -4,9 +4,39 @@ module IntegrationSpecHelper let(:permissions){ [permission] } context('', &block) if block_given? end + + def paginate_collection klass, decorator, page=1 + ModelDecorator.decorate( klass.page(page), with: decorator ) + end + + def build_paginated_collection factory, decorator, opts={} + count = opts.delete(:count) || 2 + page = opts.delete(:page) || 1 + klass = nil + count.times { klass ||= create(factory, opts).class } + paginate_collection klass, decorator, page + end end end RSpec.configure do |config| config.extend IntegrationSpecHelper, type: :view end + +RSpec::Matchers.define :have_link_for_each_item do |collection, name, href| + match do |actual| + collection.each do |item| + expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a[href='#{href.call(item)}']", count: 1) + end + end + description { "have #{name} link for each item" } +end + +RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| + match do |actual| + collection.each do |item| + expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a", count: count) + end + end + description { "have #{count} links for each item" } +end diff --git a/spec/views/offer_workbenches/show.html.erb_spec.rb b/spec/views/offer_workbenches/show.html.erb_spec.rb index 40b09268a..597335166 100644 --- a/spec/views/offer_workbenches/show.html.erb_spec.rb +++ b/spec/views/offer_workbenches/show.html.erb_spec.rb @@ -1,5 +1,42 @@ -require 'rails_helper' +require 'spec_helper' -RSpec.describe "workbenches/show.html.erb", :type => :view do +describe "workbenches/show", :type => :view do + let!(:ids) { ['STIF:CODIFLIGNE:Line:C00840', 'STIF:CODIFLIGNE:Line:C00086'] } + let!(:lines) { + ids.map do |id| + 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)] } + let!(:referentials){ + same_organisation_referential && different_organisation_referential + assign :wbench_refs, paginate_collection(Referential, ReferentialDecorator) + } + 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 + 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 + render + 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) + 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) + end end diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb index 64c958879..294acfe1a 100644 --- a/spec/views/stop_areas/index.html.slim_spec.rb +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -1,29 +1,10 @@ require 'spec_helper' -RSpec::Matchers.define :have_link_for_each_stop_area do |stop_areas, name, href| - match do |actual| - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a[href='#{href.call(stop_area)}']", count: 1) - end - end - description { "have #{name} link for each stop area" } -end - -RSpec::Matchers.define :have_the_right_number_of_links do |stop_areas, count| - match do |actual| - stop_areas.each do |stop_area| - expect(rendered).to have_selector("tr.stoparea-#{stop_area.id} .actions a", count: count) - end - end - description { "have #{count} links for each stop area" } -end - describe "/stop_areas/index", :type => :view do let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } let!(:stop_areas) do - 2.times { create(:stop_area, stop_area_referential: stop_area_referential) } - assign :stop_areas, ModelDecorator.decorate( Chouette::StopArea.page(1), with: StopAreaDecorator ) + assign :stop_areas, build_paginated_collection(:stop_area, StopAreaDecorator, stop_area_referential: stop_area_referential) end let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } @@ -35,7 +16,7 @@ describe "/stop_areas/index", :type => :view do render end - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } it { should have_the_right_number_of_links(stop_areas, 1) } with_permission "stop_areas.create" do @@ -45,8 +26,8 @@ describe "/stop_areas/index", :type => :view do end with_permission "stop_areas.update" do - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should have_link_for_each_stop_area(stop_areas, "edit", -> (stop_area){ view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should have_link_for_each_item(stop_areas, "edit", -> (stop_area){ view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } it { should have_the_right_number_of_links(stop_areas, 2) } end -- cgit v1.2.3 From 926c0a338e86c7f0e1f651ba507e8120fb26ad17 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:54:31 +0100 Subject: Refs: #5291@1h; Update TableBuilderHelper Update TableBuilderHelper to allow the `selectable` param to be a lambda, thus allowing us to have row-based granularity. --- app/helpers/table_builder_helper.rb | 131 +++++++++++---------- spec/helpers/table_builder_helper_spec.rb | 81 +++++++++++++ spec/views/offer_workbenches/show.html.erb_spec.rb | 2 - 3 files changed, 149 insertions(+), 65 deletions(-) diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 59906dc87..de78e903d 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -199,88 +199,92 @@ module TableBuilderHelper end end - def tbody(collection, columns, selectable, links, overhead) - model_name = TableBuilderHelper.item_row_class_name collection - - content_tag :tbody do - collection.map do |item| - klass = "#{model_name}-#{item.id}" - content_tag :tr, class: klass do - bcont = [] - - if selectable - bcont << content_tag( - :td, - checkbox(id_name: item.try(:id), value: item.try(:id)) - ) - end - - columns.each do |column| - value = column.value(item) - - if column.linkable? - path = column.link_to(item) - link = link_to(value, path) + def tr item, columns, selectable, links, overhead, model_name + klass = "#{model_name}-#{item.id}" + content_tag :tr, class: klass do + bcont = [] + if selectable + disabled = selectable.respond_to?(:call) && !selectable.call(item) + bcont << content_tag( + :td, + checkbox(id_name: item.try(:id), value: item.try(:id), disabled: disabled) + ) + end - if overhead.empty? - bcont << content_tag(:td, link, title: 'Voir') + columns.each do |column| + value = column.value(item) - else - i = columns.index(column) + if column.linkable? + path = column.link_to(item) + link = link_to(value, path) - if overhead[i].blank? - if (i > 0) && (overhead[i - 1][:width] > 1) - clsArrayAlt = overhead[i - 1][:cls].split + if overhead.empty? + bcont << content_tag(:td, link, title: 'Voir') - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) + else + i = columns.index(column) - else - bcont << content_tag(:td, link, title: 'Voir') - end + if overhead[i].blank? + if (i > 0) && (overhead[i - 1][:width] > 1) + clsArrayAlt = overhead[i - 1][:cls].split - else - clsArray = overhead[columns.index(column)][:cls].split + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt)) - bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) - end + else + bcont << content_tag(:td, link, title: 'Voir') end else - if overhead.empty? - bcont << content_tag(:td, value) + clsArray = overhead[columns.index(column)][:cls].split - else - i = columns.index(column) + bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray)) + end + end - if overhead[i].blank? - if (i > 0) && (overhead[i - 1][:width] > 1) - clsArrayAlt = overhead[i - 1][:cls].split + else + if overhead.empty? + bcont << content_tag(:td, value) - bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) + else + i = columns.index(column) - else - bcont << content_tag(:td, value) - end + if overhead[i].blank? + if (i > 0) && (overhead[i - 1][:width] > 1) + clsArrayAlt = overhead[i - 1][:cls].split - else - clsArray = overhead[i][:cls].split + bcont << content_tag(:td, value, class: td_cls(clsArrayAlt)) - bcont << content_tag(:td, value, class: td_cls(clsArray)) - end + else + bcont << content_tag(:td, value) end + + else + clsArray = overhead[i][:cls].split + + bcont << content_tag(:td, value, class: td_cls(clsArray)) end end + end + end - if links.any? || item.try(:action_links).try(:any?) - bcont << content_tag( - :td, - build_links(item, links), - class: 'actions' - ) - end + if links.any? || item.try(:action_links).try(:any?) + bcont << content_tag( + :td, + build_links(item, links), + class: 'actions' + ) + end - bcont.join.html_safe - end + bcont.join.html_safe + end + end + + def tbody(collection, columns, selectable, links, overhead) + model_name = TableBuilderHelper.item_row_class_name collection + + content_tag :tbody do + collection.map do |item| + tr item, columns, selectable, links, overhead, model_name end.join.html_safe end end @@ -355,13 +359,14 @@ module TableBuilderHelper end end - def checkbox(id_name:, value:) + def checkbox(id_name:, value:, disabled: false) content_tag :div, '', class: 'checkbox' do - check_box_tag(id_name, value).concat( + check_box_tag(id_name, value, nil, disabled: disabled).concat( content_tag(:label, '', for: id_name) ) end end + def gear_menu_link(link) content_tag( :li, diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 3b3504c60..83b746d4b 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 -- cgit v1.2.3 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. --- app/views/workbenches/show.html.slim | 2 +- 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 -- cgit v1.2.3 From 74da4b28490d0b8822e74ddf8a7e897d1fc24588 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 09:11:03 +0100 Subject: Refs #5291@0.1h; Add missing styles Add missing styles for disabled checkboxes --- app/assets/stylesheets/base/_config.sass | 1 + app/assets/stylesheets/components/_forms.sass | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/app/assets/stylesheets/base/_config.sass b/app/assets/stylesheets/base/_config.sass index 65444479f..ec1c43e7f 100644 --- a/app/assets/stylesheets/base/_config.sass +++ b/app/assets/stylesheets/base/_config.sass @@ -16,6 +16,7 @@ $blue: #007fbb $darkgrey: #4b4b4b $grey: #a4a4a4 +$lightgrey: rgba($grey, 0.15) $green: #70b12b $red: #da2f36 diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index 9a363ab97..47faf19b1 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -229,6 +229,13 @@ $cbx-size-xs: 15px &[type='checkbox']:checked + label:before background-color: $blue + &[type='checkbox']:disabled + label + &:before + border-color: $grey + background-color: $lightgrey + cursor: not-allowed + &:after + display: none // Table adjustments table, .table .td, td, .th, th -- cgit v1.2.3 From c3ce5e25c3596329bd1ff9542d73354e1a2bb368 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:01:49 +0100 Subject: Ref #5291@2h; Specs setup - Refactor specs helper to be more generic - Write missing specs for the Workbenches#show view We now have failing tests highlighting the bug --- spec/support/integration_spec_helper.rb | 36 +++++++++++++--------- spec/views/offer_workbenches/show.html.erb_spec.rb | 1 - 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 5bcf0bd3a..6edec2a05 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -1,26 +1,32 @@ module IntegrationSpecHelper - def with_permission permission, &block - context "with permission #{permission}" do - let(:permissions){ [permission] } - context('', &block) if block_given? - end + def paginate_collection klass, decorator, page=1 + ModelDecorator.decorate( klass.page(page), with: decorator ) + end - def paginate_collection klass, decorator, page=1 - ModelDecorator.decorate( klass.page(page), with: decorator ) - end + def build_paginated_collection factory, decorator, opts={} + count = opts.delete(:count) || 2 + page = opts.delete(:page) || 1 + klass = nil + count.times { klass ||= create(factory, opts).class } + paginate_collection klass, decorator, page + end - def build_paginated_collection factory, decorator, opts={} - count = opts.delete(:count) || 2 - page = opts.delete(:page) || 1 - klass = nil - count.times { klass ||= create(factory, opts).class } - paginate_collection klass, decorator, page + module Methods + def with_permission permission, &block + context "with permission #{permission}" do + let(:permissions){ [permission] } + context('', &block) if block_given? + end end end + + def self.included into + into.extend Methods + end end RSpec.configure do |config| - config.extend IntegrationSpecHelper, type: :view + config.include IntegrationSpecHelper, type: :view end RSpec::Matchers.define :have_link_for_each_item do |collection, name, href| diff --git a/spec/views/offer_workbenches/show.html.erb_spec.rb b/spec/views/offer_workbenches/show.html.erb_spec.rb index cc01c9d0e..138a1560d 100644 --- a/spec/views/offer_workbenches/show.html.erb_spec.rb +++ b/spec/views/offer_workbenches/show.html.erb_spec.rb @@ -53,5 +53,4 @@ describe "workbenches/show", :type => :view do expect(rendered).to have_box_for_item different_organisation_referential, true end end - end -- cgit v1.2.3 From 12924f238cc02a671a4c535b49320cd3b0ce7302 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 09:34:15 +0100 Subject: Refs #5291@0.1h; Fix rebase Fix integration_spec_helper after rebase --- spec/support/integration_spec_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 6edec2a05..78efb9027 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -1,4 +1,5 @@ module IntegrationSpecHelper + def paginate_collection klass, decorator, page=1 ModelDecorator.decorate( klass.page(page), with: decorator ) end -- cgit v1.2.3 From 818bacf718594441052820ea0e7b33b9491a5b71 Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 11:53:16 +0100 Subject: Refs #5325@0.5h; Use policies for calendar sharing Use policies to determine if a user is allowed to share a calendar, instead of a hardcoded string --- app/models/user.rb | 2 +- app/policies/calendar_policy.rb | 17 +++++++---------- lib/stif/permission_translator.rb | 13 +++++++++---- spec/lib/stif/permission_translator_spec.rb | 14 ++++++++++++++ spec/policies/calendar_policy_spec.rb | 3 +++ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 37d35209a..1342f60ed 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -36,7 +36,7 @@ class User < ActiveRecord::Base self.name = extra[:full_name] self.email = extra[:email] self.organisation = Organisation.sync_update extra[:organisation_code], extra[:organisation_name], extra[:functional_scope] - self.permissions = Stif::PermissionTranslator.translate(extra[:permissions]) + self.permissions = Stif::PermissionTranslator.translate(extra[:permissions], self.organisation) end def self.portail_api_request diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb index 074c41d8d..3ba708ec9 100644 --- a/app/policies/calendar_policy.rb +++ b/app/policies/calendar_policy.rb @@ -5,18 +5,15 @@ class CalendarPolicy < ApplicationPolicy end end - def create? + def create? !archived? && user.has_permission?('calendars.create') end - def destroy? - !archived? & organisation_match? && user.has_permission?('calendars.destroy') - end - def update? - !archived? && organisation_match? && user.has_permission?('calendars.update') - end + def destroy?; instance_permission("destroy") end + def update?; instance_permission("update") end + def share?; instance_permission("share") end - def share? - user.organisation.name == 'STIF' # FIXME + private + def instance_permission permission + !archived? & organisation_match? && user.has_permission?("calendars.#{permission}") end - end diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index 2d267bc7b..4a1c3ec8c 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -1,11 +1,11 @@ module Stif module PermissionTranslator extend self - def translate(sso_extra_permissions) - sso_extra_permissions - .sort + def translate(sso_extra_permissions, organisation=nil) + permissions = sso_extra_permissions.sort .flat_map(&method(:extra_permission_translation)) - .uniq + permissions += extra_organisation_permissions(organisation) + permissions.uniq end private @@ -49,5 +49,10 @@ module Stif "boiv:edit-offer" => all_destructive_permissions + %w{sessions.create}, } end + + def extra_organisation_permissions organisation + return %w(calendars.share) if organisation&.name&.downcase == "stif" + [] + end end end diff --git a/spec/lib/stif/permission_translator_spec.rb b/spec/lib/stif/permission_translator_spec.rb index ae1a2d1d5..355b0e336 100644 --- a/spec/lib/stif/permission_translator_spec.rb +++ b/spec/lib/stif/permission_translator_spec.rb @@ -42,4 +42,18 @@ RSpec.describe Stif::PermissionTranslator do ).to match_array(Support::Permissions.all_permissions) end end + + context "For the STIF organisation" do + let(:organisation){ build_stubbed :organisation, name: "STIF" } + it "adds the calendars.share permission" do + expect( described_class.translate([], organisation) ).to eq(%w{calendars.share}) + end + + context "with the case changed" do + let(:organisation){ build_stubbed :organisation, name: "StiF" } + it "adds the calendars.share permission" do + expect( described_class.translate([], organisation) ).to eq(%w{calendars.share}) + end + end + end end diff --git a/spec/policies/calendar_policy_spec.rb b/spec/policies/calendar_policy_spec.rb index 294be8198..8b1facc71 100644 --- a/spec/policies/calendar_policy_spec.rb +++ b/spec/policies/calendar_policy_spec.rb @@ -7,6 +7,9 @@ RSpec.describe CalendarPolicy, type: :policy do permissions :create? do it_behaves_like 'permitted policy', 'calendars.create', archived: true end + permissions :share? do + it_behaves_like 'permitted policy and same organisation', 'calendars.share', archived: true + end permissions :destroy? do it_behaves_like 'permitted policy and same organisation', 'calendars.destroy', archived: true end -- cgit v1.2.3 From 180a1c709a54f76438903af9ea5c361cc365d3e0 Mon Sep 17 00:00:00 2001 From: Zog Date: Fri, 15 Dec 2017 17:01:49 +0100 Subject: Ref #5291@2h; Specs setup - Refactor specs helper to be more generic - Write missing specs for the Workbenches#show view We now have failing tests highlighting the bug --- spec/support/integration_spec_helper.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index 78efb9027..b4d8a8283 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -19,6 +19,18 @@ module IntegrationSpecHelper context('', &block) if block_given? end end + + def paginate_collection klass, decorator, page=1 + ModelDecorator.decorate( klass.page(page), with: decorator ) + end + + def build_paginated_collection factory, decorator, opts={} + count = opts.delete(:count) || 2 + page = opts.delete(:page) || 1 + klass = nil + count.times { klass ||= create(factory, opts).class } + paginate_collection klass, decorator, page + end end def self.included into @@ -47,3 +59,21 @@ RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| end description { "have #{count} links for each item" } end + +RSpec::Matchers.define :have_link_for_each_item do |collection, name, href| + match do |actual| + collection.each do |item| + expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a[href='#{href.call(item)}']", count: 1) + end + end + description { "have #{name} link for each item" } +end + +RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| + match do |actual| + collection.each do |item| + expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a", count: count) + end + end + description { "have #{count} links for each item" } +end -- cgit v1.2.3 From 071095ab33d0d90d184296ee22bb28ab9aeaf76b Mon Sep 17 00:00:00 2001 From: Zog Date: Mon, 18 Dec 2017 09:34:15 +0100 Subject: Refs #5291@0.1h; Fix rebase Fix integration_spec_helper after rebase --- spec/support/integration_spec_helper.rb | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb index b4d8a8283..78efb9027 100644 --- a/spec/support/integration_spec_helper.rb +++ b/spec/support/integration_spec_helper.rb @@ -19,18 +19,6 @@ module IntegrationSpecHelper context('', &block) if block_given? end end - - def paginate_collection klass, decorator, page=1 - ModelDecorator.decorate( klass.page(page), with: decorator ) - end - - def build_paginated_collection factory, decorator, opts={} - count = opts.delete(:count) || 2 - page = opts.delete(:page) || 1 - klass = nil - count.times { klass ||= create(factory, opts).class } - paginate_collection klass, decorator, page - end end def self.included into @@ -59,21 +47,3 @@ RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| end description { "have #{count} links for each item" } end - -RSpec::Matchers.define :have_link_for_each_item do |collection, name, href| - match do |actual| - collection.each do |item| - expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a[href='#{href.call(item)}']", count: 1) - end - end - description { "have #{name} link for each item" } -end - -RSpec::Matchers.define :have_the_right_number_of_links do |collection, count| - match do |actual| - collection.each do |item| - expect(rendered).to have_selector("tr.#{TableBuilderHelper.item_row_class_name(collection)}-#{item.id} .actions a", count: count) - end - end - description { "have #{count} links for each item" } -end -- cgit v1.2.3 From 6d5ca1fe9782f4e43b38079a920ab0770e2d1cce Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 19 Dec 2017 13:16:03 +0100 Subject: Refs #5325; Fix calendat policy Remove the "!archived?" condition which makes no sense here. --- app/policies/calendar_policy.rb | 4 ++-- spec/policies/calendar_policy_spec.rb | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb index 3ba708ec9..c2da8c924 100644 --- a/app/policies/calendar_policy.rb +++ b/app/policies/calendar_policy.rb @@ -6,7 +6,7 @@ class CalendarPolicy < ApplicationPolicy end def create? - !archived? && user.has_permission?('calendars.create') + user.has_permission?('calendars.create') end def destroy?; instance_permission("destroy") end def update?; instance_permission("update") end @@ -14,6 +14,6 @@ class CalendarPolicy < ApplicationPolicy private def instance_permission permission - !archived? & organisation_match? && user.has_permission?("calendars.#{permission}") + organisation_match? && user.has_permission?("calendars.#{permission}") end end diff --git a/spec/policies/calendar_policy_spec.rb b/spec/policies/calendar_policy_spec.rb index 8b1facc71..5fd1eca47 100644 --- a/spec/policies/calendar_policy_spec.rb +++ b/spec/policies/calendar_policy_spec.rb @@ -5,21 +5,21 @@ RSpec.describe CalendarPolicy, type: :policy do permissions :create? do - it_behaves_like 'permitted policy', 'calendars.create', archived: true + it_behaves_like 'permitted policy', 'calendars.create' end permissions :share? do - it_behaves_like 'permitted policy and same organisation', 'calendars.share', archived: true + it_behaves_like 'permitted policy and same organisation', 'calendars.share' end permissions :destroy? do - it_behaves_like 'permitted policy and same organisation', 'calendars.destroy', archived: true + it_behaves_like 'permitted policy and same organisation', 'calendars.destroy' end permissions :edit? do - it_behaves_like 'permitted policy and same organisation', 'calendars.update', archived: true + it_behaves_like 'permitted policy and same organisation', 'calendars.update' end permissions :new? do - it_behaves_like 'permitted policy', 'calendars.create', archived: true + it_behaves_like 'permitted policy', 'calendars.create' end permissions :update? do - it_behaves_like 'permitted policy and same organisation', 'calendars.update', archived: true + it_behaves_like 'permitted policy and same organisation', 'calendars.update' end end -- cgit v1.2.3 From e1cfb02bf25e636303824b57194713a2db08ea1f Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 19 Dec 2017 19:30:12 +0100 Subject: Replace have_link_for_each_stop_area by have_link_for_each_item as espected. Refs #5291 @5m --- spec/views/stop_areas/index.html.slim_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb index 294acfe1a..8daa5eb4b 100644 --- a/spec/views/stop_areas/index.html.slim_spec.rb +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -20,8 +20,8 @@ describe "/stop_areas/index", :type => :view do it { should have_the_right_number_of_links(stop_areas, 1) } with_permission "stop_areas.create" do - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should_not have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } + it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should_not have_link_for_each_item(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } it { should have_the_right_number_of_links(stop_areas, 1) } end -- cgit v1.2.3 From 1c60dcca735efc72b9218353ac255a50aad4e74b Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Tue, 19 Dec 2017 23:27:26 +0100 Subject: Use stop_areas count and not size to display stop_area counter --- app/views/stop_area_referentials/show.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim index d43333fd9..b562df5d5 100644 --- a/app/views/stop_area_referentials/show.html.slim +++ b/app/views/stop_area_referentials/show.html.slim @@ -7,7 +7,7 @@ .col-lg-12.text-right = link_to stop_area_referential_stop_areas_path(@stop_area_referential), class: 'btn btn-primary' do = Referential.human_attribute_name(:stop_areas) - em.small = " (#{@stop_area_referential.stop_areas.size})" + em.small = " (#{@stop_area_referential.stop_areas.count})" - page_header_content_for @stop_area_referential .page_content -- cgit v1.2.3 From 2a496d69c8425a98f500e91facc18c303ae395c5 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Tue, 19 Dec 2017 23:32:05 +0100 Subject: Fix i18n for compliance_check_sets --- app/decorators/compliance_check_set_decorator.rb | 9 --------- app/views/compliance_check_sets/index.html.slim | 4 +--- config/locales/compliance_check_sets.fr.yml | 4 ++-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/app/decorators/compliance_check_set_decorator.rb b/app/decorators/compliance_check_set_decorator.rb index 096596b19..c58e14d88 100644 --- a/app/decorators/compliance_check_set_decorator.rb +++ b/app/decorators/compliance_check_set_decorator.rb @@ -3,15 +3,6 @@ class ComplianceCheckSetDecorator < Draper::Decorator def action_links links = [] - - links << Link.new( - content: h.destroy_link_content, - href: h.workbench_compliance_check_sets_path(object.id), - method: :delete, - data: {confirm: h.t('imports.actions.destroy_confirm')} - ) - - links end def lines_status diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim index f5d1bd777..f109845b4 100644 --- a/app/views/compliance_check_sets/index.html.slim +++ b/app/views/compliance_check_sets/index.html.slim @@ -12,7 +12,7 @@ [ \ TableBuilderHelper::Column.new( \ key: :ref, \ - attribute: 'compliance_check_set_id' \ + attribute: 'id' \ ), \ TableBuilderHelper::Column.new( \ key: :creation_date, \ @@ -41,5 +41,3 @@ .row.mt-xs .col-lg-12 = replacement_msg t('compliance_check_sets.search_no_results') - - diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml index 8f1c066e7..8c4561ae9 100644 --- a/config/locales/compliance_check_sets.fr.yml +++ b/config/locales/compliance_check_sets.fr.yml @@ -10,7 +10,7 @@ fr: name_compliance_control_set: Indiquez le nom d'un jeu de contrôle error_period_filter: La date de fin doit être supérieure ou égale à la date de début0 index: - title: "Liste des jeux de contrôles" + title: "Liste des rapports de contrôles" search_no_results: Aucun rapport de contrôle ne correspond à votre recherche executed: title: Jeu de contrôles exécutés %{name} @@ -24,7 +24,7 @@ fr: activerecord: attributes: compliance_check_set: - ref: réf + ref: Ref creation_date: Date et heure de création associated_object: Objet associé assigned_to: Affectation -- cgit v1.2.3 From e7bece2f871d51ad71ee2ee258afd985bf8d8485 Mon Sep 17 00:00:00 2001 From: Luc Donnet Date: Tue, 19 Dec 2017 23:59:24 +0100 Subject: Fix compliance check set feature to use the correct title --- spec/features/compliance_check_sets_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/features/compliance_check_sets_spec.rb b/spec/features/compliance_check_sets_spec.rb index 7ba64b6b8..6b7d7a4f8 100644 --- a/spec/features/compliance_check_sets_spec.rb +++ b/spec/features/compliance_check_sets_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "ComplianceCheckSets", type: :feature do it 'we can see the expected content' do # Breadcrumbs - expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des jeux de contrôles" + expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des rapports de contrôles" # Headline expect( page ).to have_content("Jeu de contrôles exécutés #{compliance_check_set.name}") @@ -49,10 +49,10 @@ RSpec.describe "ComplianceCheckSets", type: :feature do # Direct Children within(:xpath, xpath_for_div_of_block) do direct_checks.each do | direct_check | - expect( page ).to have_content( direct_check.code ) - expect( page ).to have_content( direct_check.name ) - expect( page ).to have_content( direct_check.criticity ) - expect( page ).to have_content( direct_check.comment ) + expect( page ).to have_content( direct_check.code ) + expect( page ).to have_content( direct_check.name ) + expect( page ).to have_content( direct_check.criticity ) + expect( page ).to have_content( direct_check.comment ) end end @@ -60,10 +60,10 @@ RSpec.describe "ComplianceCheckSets", type: :feature do compliance_check_set.compliance_check_blocks.each do | block | within(:xpath, xpath_for_div_of_block(block)) do block.compliance_checks.each do | check | - expect( page ).to have_content( check.code ) - expect( page ).to have_content( check.name ) - expect( page ).to have_content( check.criticity ) - expect( page ).to have_content( check.comment ) + expect( page ).to have_content( check.code ) + expect( page ).to have_content( check.name ) + expect( page ).to have_content( check.criticity ) + expect( page ).to have_content( check.comment ) end end end @@ -86,7 +86,7 @@ RSpec.describe "ComplianceCheckSets", type: :feature do all_checks.each do | check | expect( page ).to have_content(check.code) end - + end end -- cgit v1.2.3 From 49a515b474cf64b02f6dfc7a449f3a45aa21e7ca Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 20 Dec 2017 08:12:20 +0100 Subject: Fix spec after rebase --- spec/views/stop_areas/index.html.slim_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb index 294acfe1a..8daa5eb4b 100644 --- a/spec/views/stop_areas/index.html.slim_spec.rb +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -20,8 +20,8 @@ describe "/stop_areas/index", :type => :view do it { should have_the_right_number_of_links(stop_areas, 1) } with_permission "stop_areas.create" do - it { should have_link_for_each_stop_area(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } - it { should_not have_link_for_each_stop_area(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } + it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } + it { should_not have_link_for_each_item(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } it { should have_the_right_number_of_links(stop_areas, 1) } end -- cgit v1.2.3