aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorAlban Peignier2017-12-20 09:41:53 +0100
committerAlban Peignier2017-12-20 09:42:07 +0100
commit38ab26f1ea40b7ab5774ff0c18fba54204767b88 (patch)
tree6cac0527da202aae01664e8cda4e5c4649164add /spec
parent023fdab6840c7bb2d87d8ffee2df478574158d6e (diff)
parent0a5c1fd25403c327593a5cbe10c7c58be6128c89 (diff)
downloadchouette-core-38ab26f1ea40b7ab5774ff0c18fba54204767b88.tar.bz2
Merge branch 'master' into 5333-add-policies-for-referentials-sharing5333-add-policies-for-referentials-sharing
Diffstat (limited to 'spec')
-rw-r--r--spec/features/compliance_check_sets_spec.rb20
-rw-r--r--spec/helpers/table_builder_helper_spec.rb6
-rw-r--r--spec/lib/stif/permission_translator_spec.rb5
-rw-r--r--spec/policies/calendar_policy_spec.rb13
-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/offer_workbenches/show.html.erb_spec.rb1
-rw-r--r--spec/views/stop_areas/index.html.erb_spec.rb25
-rw-r--r--spec/views/stop_areas/index.html.slim_spec.rb4
10 files changed, 41 insertions, 96 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
diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb
index 8c77bd465..83b746d4b 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/lib/stif/permission_translator_spec.rb b/spec/lib/stif/permission_translator_spec.rb
index 04fc1c6f3..9771af187 100644
--- a/spec/lib/stif/permission_translator_spec.rb
+++ b/spec/lib/stif/permission_translator_spec.rb
@@ -1,3 +1,4 @@
+# coding: utf-8
RSpec.describe Stif::PermissionTranslator do
context "No SSO Permissions" do
@@ -46,13 +47,13 @@ RSpec.describe Stif::PermissionTranslator do
context "For the STIF organisation" do
let(:organisation){ build_stubbed :organisation, name: "STIF" }
let(:permissions){ %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize}.sort }
- it "adds the calendars.share permission" do
+ it "adds the STIF permission" do
expect(described_class.translate([], organisation).sort).to eq permissions
end
context "with the case changed" do
let(:organisation){ build_stubbed :organisation, name: "StiF" }
- it "adds the calendars.share permission" do
+ it "adds the STIF permission" do
expect(described_class.translate([], organisation).sort).to eq permissions
end
end
diff --git a/spec/policies/calendar_policy_spec.rb b/spec/policies/calendar_policy_spec.rb
index 8b1facc71..a881d0e80 100644
--- a/spec/policies/calendar_policy_spec.rb
+++ b/spec/policies/calendar_policy_spec.rb
@@ -5,21 +5,24 @@ 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'
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
+ 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
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/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
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
index ecd76fb03..8daa5eb4b 100644
--- a/spec/views/stop_areas/index.html.slim_spec.rb
+++ b/spec/views/stop_areas/index.html.slim_spec.rb
@@ -21,8 +21,8 @@ describe "/stop_areas/index", :type => :view do
with_permission "stop_areas.create" do
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, "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_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
with_permission "stop_areas.update" do