diff options
Diffstat (limited to 'spec/features')
| -rw-r--r-- | spec/features/calendars_permissions_spec.rb | 55 | ||||
| -rw-r--r-- | spec/features/group_of_lines_permissions_spec.rb | 43 | ||||
| -rw-r--r-- | spec/features/group_of_lines_spec.rb | 2 | ||||
| -rw-r--r-- | spec/features/line_footnotes_permissions_spec.rb | 40 | ||||
| -rw-r--r-- | spec/features/line_footnotes_spec.rb | 14 | ||||
| -rw-r--r-- | spec/features/lines_permissions_spec.rb | 66 | ||||
| -rw-r--r-- | spec/features/referential_lines_permissions_spec.rb | 44 | ||||
| -rw-r--r-- | spec/features/routes_permissions_spec.rb | 42 | ||||
| -rw-r--r-- | spec/features/routes_spec.rb | 9 |
9 files changed, 294 insertions, 21 deletions
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, []) |
