aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2017-12-19 16:16:36 +0100
committerGitHub2017-12-19 16:16:36 +0100
commit5df065c68770756ecf8ddde53b133927d7584835 (patch)
treeb82f4c685bef58509b5649559d2519f8791849ba
parentf33fba57cd0b793ec0d484ef3e16db2324099aa1 (diff)
parent4b9eebda5bb81a214c87351c01c720c0cb0cf2e8 (diff)
downloadchouette-core-5df065c68770756ecf8ddde53b133927d7584835.tar.bz2
Merge pull request #152 from af83/5287-clean-links-in-stop-areas-index
5287 clean links in stop areas index
-rw-r--r--app/assets/stylesheets/components/_panels.sass1
-rw-r--r--app/decorators/stop_area_decorator.rb9
-rw-r--r--app/helpers/table_builder_helper.rb10
-rw-r--r--app/views/dashboards/_dashboard.html.slim2
-rw-r--r--app/views/stop_areas/index.html.slim4
-rw-r--r--config/locales/calendars.en.yml5
-rw-r--r--config/locales/calendars.fr.yml5
-rw-r--r--config/locales/stop_areas.en.yml2
-rw-r--r--config/locales/stop_areas.fr.yml2
-rw-r--r--spec/helpers/table_builder_helper_spec.rb6
-rw-r--r--spec/support/integration_spec_helper.rb12
-rw-r--r--spec/support/pundit/pundit_view_policy.rb20
-rw-r--r--spec/views/connection_links/index.html.erb_spec.rb8
-rw-r--r--spec/views/connection_links/show.html.erb_spec.rb35
-rw-r--r--spec/views/connection_links/show.html.slim_spec.rb32
-rw-r--r--spec/views/stop_areas/index.html.erb_spec.rb25
-rw-r--r--spec/views/stop_areas/index.html.slim_spec.rb53
17 files changed, 135 insertions, 96 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/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/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/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/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim
index c4d880081..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 \
) \
@@ -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'
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
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/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
</tr>
</thead>
<tbody>
- <tr>
+ <tr class="referential-#{referential.id}">
<td>
<div class="checkbox"><input type="checkbox" name="#{referential.id}" id="#{referential.id}" value="#{referential.id}" /><label for="#{referential.id}"></label></div>
</td>
@@ -213,7 +213,7 @@ describe TableBuilderHelper, type: :helper do
</tr>
</thead>
<tbody>
- <tr>
+ <tr class="company-#{company.id}">
<td>#{company.get_objectid.local_id}</td>
<td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td>
<td></td>
@@ -326,7 +326,7 @@ describe TableBuilderHelper, type: :helper do
</tr>
</thead>
<tbody>
- <tr>
+ <tr class="company-#{company.id}">
<td>#{company.get_objectid.local_id}</td>
<td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td>
<td></td>
diff --git a/spec/support/integration_spec_helper.rb b/spec/support/integration_spec_helper.rb
new file mode 100644
index 000000000..182cadf24
--- /dev/null
+++ b/spec/support/integration_spec_helper.rb
@@ -0,0 +1,12 @@
+module IntegrationSpecHelper
+ 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.extend IntegrationSpecHelper, type: :view
+end
diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb
index b8434cac0..91be0624c 100644
--- a/spec/support/pundit/pundit_view_policy.rb
+++ b/spec/support/pundit/pundit_view_policy.rb
@@ -1,16 +1,16 @@
module Pundit
module PunditViewPolicy
- extend ActiveSupport::Concern
+ 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 }
- included do
- 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(:policy) do |instance|
+ ::Pundit.policy pundit_user, instance
end
end
end
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
deleted file mode 100644
index c04a4f3f1..000000000
--- a/spec/views/connection_links/show.html.erb_spec.rb
+++ /dev/null
@@ -1,35 +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 => '<div id="map"/>'.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
-
-# 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)}']")
- 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']")
- 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 => '<div id="map"/>'.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 2dfae1bfd..000000000
--- a/spec/views/stop_areas/index.html.erb_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-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!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) }
-
- before :each do
- allow(view).to receive(:link_with_search).and_return("#")
- 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
-
-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..64c958879
--- /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_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
+ 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