aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/views/access_link_pairs/_access_link_pair.html.slim1
-rw-r--r--app/views/group_of_lines/_group_of_line.html.slim10
-rw-r--r--app/views/referential_lines/show.html.slim1
-rw-r--r--app/views/routes/show.html.slim2
-rw-r--r--spec/features/calendars_permissions_spec.rb55
-rw-r--r--spec/features/group_of_lines_permissions_spec.rb43
-rw-r--r--spec/features/group_of_lines_spec.rb2
-rw-r--r--spec/features/line_footnotes_permissions_spec.rb40
-rw-r--r--spec/features/line_footnotes_spec.rb14
-rw-r--r--spec/features/lines_permissions_spec.rb66
-rw-r--r--spec/features/referential_lines_permissions_spec.rb44
-rw-r--r--spec/features/routes_permissions_spec.rb42
-rw-r--r--spec/features/routes_spec.rb9
-rw-r--r--spec/support/helpers.rb4
-rw-r--r--spec/support/helpers/session_helpers.rb3
15 files changed, 305 insertions, 31 deletions
diff --git a/app/views/access_link_pairs/_access_link_pair.html.slim b/app/views/access_link_pairs/_access_link_pair.html.slim
index c313f9044..3eebfd7f6 100644
--- a/app/views/access_link_pairs/_access_link_pair.html.slim
+++ b/app/views/access_link_pairs/_access_link_pair.html.slim
@@ -1,4 +1,5 @@
tr
+ - require 'pry'; binding.pry
td
.link
.access_point
diff --git a/app/views/group_of_lines/_group_of_line.html.slim b/app/views/group_of_lines/_group_of_line.html.slim
index fb9f95894..e33201f74 100644
--- a/app/views/group_of_lines/_group_of_line.html.slim
+++ b/app/views/group_of_lines/_group_of_line.html.slim
@@ -2,11 +2,11 @@
.panel-heading
.panel-title.clearfix
span.pull-right
- - if edit && policy(group_of_line).update?
- = link_to edit_line_referential_group_of_line_path(@line_referential, group_of_line), class: 'btn btn-default btn-sm' do
- span.fa.fa-pencil
- - if delete && policy(group_of_line).destroy?
- = link_to('<span class="fa fa-trash-o"></span>'.html_safe, line_referential_group_of_line_path(@line_referential, group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm')
+ / - if edit && policy(group_of_line).update?
+ = link_to edit_line_referential_group_of_line_path(@line_referential, group_of_line), class: 'btn btn-default btn-sm' do
+ span.fa.fa-pencil
+ / - if delete && policy(group_of_line).destroy?
+ = link_to('<span class="fa fa-trash-o"></span>'.html_safe, line_referential_group_of_line_path(@line_referential, group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')}, class: 'btn btn-danger btn-sm')
h5
= link_to [@line_referential, group_of_line], :class => "preview", :title => "#{Chouette::GroupOfLine.model_name.human.capitalize} #{group_of_line.name}" do
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index 1e24f0f15..4c8b09ab2 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -22,6 +22,7 @@
span.fa.fa-trash
span = t('lines.actions.destroy')
+ - require 'pry'; binding.pry
- if !@line.hub_restricted? || (@line.hub_restricted? && @line.routes.size < 2)
- if policy(Chouette::Route).create? && @referential.organisation == current_organisation
= link_to t('routes.actions.new'), new_referential_line_route_path(@referential, @line), class: 'btn btn-primary'
diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim
index 5aebae055..d994e3861 100644
--- a/app/views/routes/show.html.slim
+++ b/app/views/routes/show.html.slim
@@ -20,7 +20,7 @@
span.fa.fa-trash
span = t('actions.destroy')
-/ PägeContent
+/ PageContent
.page_content
.container-fluid
.row
diff --git a/spec/features/calendars_permissions_spec.rb b/spec/features/calendars_permissions_spec.rb
new file mode 100644
index 000000000..6eb0ea08e
--- /dev/null
+++ b/spec/features/calendars_permissions_spec.rb
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+require 'spec_helper'
+
+describe 'Calendars', type: :feature do
+ login_user
+
+ let(:calendar) { create :calendar, organisation_id: 1 }
+
+ describe 'permissions' do
+ before do
+ allow_any_instance_of(CalendarPolicy).to receive(:edit?).and_return permission
+ allow_any_instance_of(CalendarPolicy).to receive(:destroy?).and_return permission
+ allow_any_instance_of(CalendarPolicy).to receive(:share?).and_return permission
+ visit path
+ end
+
+ context 'on show view' do
+ let( :path ){ calendar_path(calendar) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+ it 'view shows the corresponding buttons' do
+ expect(page).to have_css('a.btn.btn-default', text: 'Editer')
+ expect(page).to have_css('a.btn.btn-primary', text: 'Supprimer')
+ end
+ end
+
+ context 'if absent → ' do
+ let( :permission ){ false }
+ it 'view does not show the corresponding buttons' do
+ expect(page).not_to have_css('a.btn.btn-default', text: 'Editer')
+ expect(page).not_to have_css('a.btn.btn-primary', text: 'Supprimer')
+ end
+ end
+ end
+
+ context 'on edit view' do
+ let( :path ){ edit_calendar_path(calendar) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+ it 'view shows the corresponding checkbox' do
+ expect( page ).to have_css('div.has_switch label.boolean[for=calendar_shared]')
+ end
+ end
+
+ context 'if absent → ' do
+ let( :permission ){ false }
+ it 'view does not show the corresponding checkbox' do
+ expect( page ).not_to have_css('div.has_switch label.boolean[for=calendar_shared]')
+ end
+ end
+ end
+ end
+end
diff --git a/spec/features/group_of_lines_permissions_spec.rb b/spec/features/group_of_lines_permissions_spec.rb
new file mode 100644
index 000000000..5c03481ec
--- /dev/null
+++ b/spec/features/group_of_lines_permissions_spec.rb
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+
+describe "Group of lines", :type => :feature do
+ skip 'delete param of view seems to be constantly false' do
+ login_user
+
+ let(:line) { create(:line_with_stop_areas, :network => network, :company => company) }
+
+ let(:line_referential) { create :line_referential }
+ let(:network) { create(:network) }
+ let(:company) { create(:company) }
+
+ let(:group_of_line) { create :group_of_line, line_referential: line_referential }
+
+ describe 'permissions' do
+ before do
+ group_of_line.lines << line
+ allow_any_instance_of(LinePolicy).to receive(:destroy?).and_return permission
+ visit path
+ end
+
+ context 'on show view' do
+ let( :path ){ line_referential_group_of_line_path(line_referential, group_of_line, delete: true) }
+
+ context 'if permissions present → ' do
+ let( :permission ){ true }
+
+ it 'shows the appropriate buttons' do
+ expected_url = line_referential_line_path(line.line_referential, line)
+ expect( page ).to have_link('Supprimer', href: expected_url)
+ end
+ end
+ context 'if permissions absent → ' do
+ let( :permission ){ false }
+
+ it 'shows the appropriate buttons' do
+ expect( page ).not_to have_link('Supprimer')
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/features/group_of_lines_spec.rb b/spec/features/group_of_lines_spec.rb
index 79500fe33..59101ccd5 100644
--- a/spec/features/group_of_lines_spec.rb
+++ b/spec/features/group_of_lines_spec.rb
@@ -37,7 +37,7 @@ describe "Group of lines", :type => :feature do
describe "show" do
it "displays group of line" do
visit line_referential_group_of_lines_path(line_referential)
- click_link "#{subject.name}"
+ click_link subject.name
expect(page).to have_content(subject.name)
end
diff --git a/spec/features/line_footnotes_permissions_spec.rb b/spec/features/line_footnotes_permissions_spec.rb
new file mode 100644
index 000000000..4de2a6137
--- /dev/null
+++ b/spec/features/line_footnotes_permissions_spec.rb
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+
+describe 'Line Footnotes', type: :feature do
+ login_user
+
+ let!(:line) { create :line_with_stop_areas, network: network, company: company, line_referential: line_referential }
+ let(:referential) { Referential.first }
+ let( :line_referential ){ referential.line_referential }
+ let(:network) { create(:network) }
+ let(:company) { create(:company) }
+
+
+ describe 'permissions' do
+ before do
+ allow_any_instance_of(LinePolicy).to receive(:update_footnote?).and_return permission
+ visit path
+ end
+
+ describe 'on show view' do
+ let( :path ){ referential_line_footnotes_path(line_referential, line) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+
+ it 'displays the corresponding button' do
+ expect( page ).to have_link('Editer', href: edit_referential_line_footnotes_path(line_referential, line))
+ end
+ end
+
+ context 'if absent → ' do
+ let( :permission ){ false }
+
+ it 'does not display the corresponding button' do
+ expect( page ).not_to have_link('Editer', href: edit_referential_line_footnotes_path(line_referential, line))
+ end
+ end
+ end
+
+ end
+end
diff --git a/spec/features/line_footnotes_spec.rb b/spec/features/line_footnotes_spec.rb
index 0273ee288..4d77cba41 100644
--- a/spec/features/line_footnotes_spec.rb
+++ b/spec/features/line_footnotes_spec.rb
@@ -27,18 +27,6 @@ describe 'Line Footnotes', type: :feature do
expect(page).not_to have_content(I18n.t('actions.add'))
end
- context 'user has permission to edit footnotes' do
- it 'shows edit link for footnotes' do
- expect(page).to have_content(I18n.t('actions.edit'))
- end
- end
-
- context 'user does not have permission to edit footnotes' do
- it 'does not show edit link for footnotes' do
- @user.update_attribute(:permissions, [])
- visit referential_line_footnotes_path(referential.line_referential, line)
- expect(page).not_to have_content(I18n.t('lines.actions.edit_footnotes'))
- end
- end
end
+
end
diff --git a/spec/features/lines_permissions_spec.rb b/spec/features/lines_permissions_spec.rb
new file mode 100644
index 000000000..5d53d6568
--- /dev/null
+++ b/spec/features/lines_permissions_spec.rb
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+
+describe "Lines", :type => :feature do
+ login_user
+
+ let(:line_referential) { create :line_referential }
+
+ let(:network) { create(:network) }
+ let(:company) { create(:company) }
+ let(:line) { create :line_with_stop_areas, network: network, company: company, line_referential: line_referential }
+ context 'permissions' do
+ before do
+ create :group_of_line
+ line_referential.lines << line
+ line_referential.organisations << Organisation.first
+ allow_any_instance_of(LinePolicy).to receive(:create?).and_return permission
+ allow_any_instance_of(LinePolicy).to receive(:destroy?).and_return permission
+ visit path
+ end
+
+ context 'on index view' do
+ let( :path ){ line_referential_lines_path(line_referential) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+
+ it 'displays the corresponding button' do
+ expected_href = new_line_referential_line_path(line_referential)
+ expect( page ).to have_link('Ajouter une ligne', href: expected_href)
+ end
+ end
+
+ context 'if absent → ' do
+ let( :permission ){ false }
+
+ it 'does not display the corresponding button' do
+ expect( page ).not_to have_link('Ajouter une ligne')
+ end
+ end
+ end
+
+ context 'on show view' do
+ skip 'policies always false' do
+ let( :path ){ line_referential_line_path(line_referential, line) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+
+ it 'displays the corresponding buttons' do
+ expected_href = new_line_referential_line_path(line_referential)
+ expect( page ).to have_link('Ajouter une ligne', href: expected_href)
+ end
+ end
+
+ context 'if absent → ' do
+ let( :permission ){ false }
+
+ it 'does not display the corresponding button' do
+ expect( page ).not_to have_link('Ajouter une ligne')
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/features/referential_lines_permissions_spec.rb b/spec/features/referential_lines_permissions_spec.rb
new file mode 100644
index 000000000..0d156f0d6
--- /dev/null
+++ b/spec/features/referential_lines_permissions_spec.rb
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+
+describe 'ReferentialLines', type: :feature do
+ login_user
+ let!(:referential_metadata) { create :referential_metadata, referential: referential }
+ let( :line ){ referential.lines.first }
+
+ context 'permissions' do
+ before do
+ allow_any_instance_of(RoutePolicy).to receive(:create?).and_return permission
+ visit path
+ end
+
+ context 'on show view' do
+ let( :path ){ referential_line_path(referential, line) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+ it 'shows the corresponding button' do
+ expected_href = new_referential_line_route_path(referential, line)
+ expect( page ).to have_link("Ajouter un itinéraire", href: expected_href)
+ end
+ end
+ context 'if absent → ' do
+ let( :permission ){ false }
+ it 'does not show the corresponding button' do
+ expect( page ).not_to have_link("Ajouter un itinéraire")
+ end
+ end
+ end
+
+ end
+
+ # describe 'show' do
+ # it 'displays referential line' do
+ # visit referential_line_path(referential, referential.lines.first)
+ # expect(page).to have_content(referential.lines.first.name)
+ # end
+ # it 'displays referential line' do
+ # visit referential_line_path(referential, referential.lines.first, sort: "stop_points")
+ # expect(page).to have_content(referential.lines.first.name)
+ # end
+ # end
+end
diff --git a/spec/features/routes_permissions_spec.rb b/spec/features/routes_permissions_spec.rb
new file mode 100644
index 000000000..36c13b24a
--- /dev/null
+++ b/spec/features/routes_permissions_spec.rb
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+require 'spec_helper'
+
+describe "Routes", :type => :feature do
+ login_user
+
+ let(:line) { create :line }
+ let(:route) { create(:route, :line => line) }
+
+
+ describe 'permissions' do
+ before do
+ @user.update(organisation: referential.organisation)
+ allow_any_instance_of(RoutePolicy).to receive(:edit?).and_return permission
+ allow_any_instance_of(RoutePolicy).to receive(:destroy?).and_return permission
+ visit path
+ end
+
+ describe 'on show view' do
+ let( :path ){ referential_line_route_path(referential, line, route) }
+
+ context 'if present → ' do
+ let( :permission ){ true }
+ it 'view shows the corresponding buttons' do
+ expected_edit_url = edit_referential_line_route_path(referential, line, route)
+ expected_delete_url = referential_line_route_path(referential, line, route)
+ expect( page ).to have_link('Editer', href: expected_edit_url)
+ expect( page ).to have_link('Supprimer', href: expected_delete_url)
+ end
+ end
+
+ context 'if absent → ' do
+ let( :permission ){ false }
+ it 'view does not show the corresponding buttons' do
+ expect( page ).not_to have_link('Editer')
+ expect( page ).not_to have_link('Supprimer')
+ end
+ end
+ end
+
+ end
+end
diff --git a/spec/features/routes_spec.rb b/spec/features/routes_spec.rb
index 4b90a6ec6..89d368479 100644
--- a/spec/features/routes_spec.rb
+++ b/spec/features/routes_spec.rb
@@ -47,6 +47,7 @@ describe "Routes", :type => :feature do
xit "Puts (http) an update request" do
#visit edit_boarding_alighting_referential_line_route_path(referential, line, route)
visit referential_line_route_path(referential, line, route)
+
click_link I18n.t('routes.actions.edit_boarding_alighting')
#select('', :from => '')
# Changes the boarding of the first stop
@@ -62,7 +63,7 @@ describe "Routes", :type => :feature do
context 'user has permission to edit journey patterns' do
it 'shows edit links for journey patterns' do
- expect(page).to have_content(I18n.t('actions.edit'))
+ expect(page).to have_link(I18n.t('actions.edit'), href: edit_referential_line_route_journey_pattern_path(referential, line, route, journey_pattern))
end
end
@@ -126,12 +127,6 @@ describe "Routes", :type => :feature do
end
end
- context 'user has permission to destroy routes' do
- it 'shows destroy buttons for routes' do
- expect(page).to have_content(I18n.t('actions.edit'))
- end
- end
-
context 'user does not have permission to destroy routes' do
it 'does not show destroy buttons for routes' do
@user.update_attribute(:permissions, [])
diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb
deleted file mode 100644
index 5e1becafb..000000000
--- a/spec/support/helpers.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'support/helpers/session_helpers'
-RSpec.configure do |config|
- config.include Features::SessionHelpers, type: :feature
-end
diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb
index b92c5f0a1..c2bb3a04a 100644
--- a/spec/support/helpers/session_helpers.rb
+++ b/spec/support/helpers/session_helpers.rb
@@ -22,3 +22,6 @@ module Features
end
end
end
+RSpec.configure do |config|
+ config.include Features::SessionHelpers, type: :feature
+end