From bfec2b6e73747193052639ee2bbf4340409510dc Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 15 May 2017 17:38:38 +0200 Subject: Refs: #3144; calendar, line_footnotes and routes speced (spec/features) --- spec/features/lines_permissions_spec.rb | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 spec/features/lines_permissions_spec.rb (limited to 'spec/features/lines_permissions_spec.rb') 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 -- cgit v1.2.3