diff options
| author | Robert | 2017-05-15 17:38:38 +0200 | 
|---|---|---|
| committer | Robert | 2017-05-18 18:42:22 +0200 | 
| commit | bfec2b6e73747193052639ee2bbf4340409510dc (patch) | |
| tree | 0d37ba9564781b5db7ba2edf7f8de53a06c91b33 /spec/features/lines_permissions_spec.rb | |
| parent | 8872c4707b806ff4ae412de99a561495c20fbc51 (diff) | |
| download | chouette-core-bfec2b6e73747193052639ee2bbf4340409510dc.tar.bz2 | |
Refs: #3144; calendar, line_footnotes and routes speced (spec/features)
Diffstat (limited to 'spec/features/lines_permissions_spec.rb')
| -rw-r--r-- | spec/features/lines_permissions_spec.rb | 66 | 
1 files changed, 66 insertions, 0 deletions
| 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 | 
