aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/referentials_permissions_spec.rb
blob: c37dff5b93b47d29d529da62b745513cfa48074c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-

describe "Referentials", :type => :feature do

  login_user
  let(:referential) { Referential.first }

  let( :edit_link_text ){ I18n.t('actions.edit') }
  let( :destroy_link_text ){ I18n.t('actions.destroy') }


  context 'permissions' do
    before do
      allow_any_instance_of(ReferentialPolicy).to receive(:organisation_match?).and_return organisation_match
      visit path
    end

    context 'on show view with common lines' do
      let( :path ){ referential_path(referential) }
      before do
        allow_any_instance_of(ReferentialPolicy).to receive(:common_lines?).and_return common_lines
      end

      context 'if organisations match →' do
        let( :organisation_match ){ true }
        let( :common_lines ){ false }

        it 'shows the edit button' do
          expected_href = edit_referential_path(referential)
          expect( page ).to have_link(edit_link_text, href: expected_href)
        end
        it 'shows the delete button' do
          expected_href = referential_path(referential)
          expect( page ).to have_css(%{a[href=#{expected_href.inspect}]}, text: destroy_link_text)
        end
      end

      context 'if organisations do not match →' do
        let( :organisation_match ){ false }
        let( :common_lines ){ true }

        it 'does not show the delete button' do
          expected_href = edit_referential_path(referential)
          expect( page ).not_to have_link(edit_link_text, href: expected_href)
        end
        it 'does not show the delete button' do
          expected_href = referential_path(referential)
          expect( page ).not_to have_css(%{a[href=#{expected_href.inspect}] span}, text: destroy_link_text)
        end
      end
    end

  end
end