aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/purchase_windows_permission_spec.rb
blob: 9f155a1e82200ec56517b45c1d1d07111051b0d0 (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
55
56
57
58
59
# -*- coding: utf-8 -*-
require 'spec_helper'

describe "PurchaseWindows", :type => :feature do
  login_user

  before do
    @user.organisation.update features: %w{purchase_windows}
  end

  let(:purchase_window) { create :purchase_window, referential: first_referential}

  describe 'permissions' do
    before do
      allow_any_instance_of(PurchaseWindowPolicy).to receive(:create?).and_return permission
      allow_any_instance_of(PurchaseWindowPolicy).to receive(:destroy?).and_return permission
      allow_any_instance_of(PurchaseWindowPolicy).to receive(:update?).and_return permission
      visit path
    end

    context 'on show view' do
      let( :path ){ referential_purchase_window_path(first_referential, purchase_window) }

      context 'if present → ' do
        let( :permission ){ true }
        it 'view shows the corresponding buttons' do
          expect(page).to have_content(I18n.t('purchase_windows.actions.edit'))
          expect(page).to have_content(I18n.t('purchase_windows.actions.destroy'))
        end
      end

      context 'if absent → ' do
        let( :permission ){ false }
        it 'view does not show the corresponding buttons' do
          expect(page).not_to have_content(I18n.t('purchase_windows.actions.edit'))
          expect(page).not_to have_content(I18n.t('purchase_windows.actions.destroy'))
        end
      end
    end

    context 'on index view' do
      let( :path ){ referential_purchase_windows_path(first_referential) }

      context 'if present → ' do
        let( :permission ){ true }
        it 'index shows an edit button' do
          expect(page).to have_content(I18n.t('purchase_windows.actions.new'))
        end
      end

      context 'if absent → ' do
        let( :permission ){ false }
        it 'index does not show any edit button' do
          expect(page).not_to have_content(I18n.t('purchase_windows.actions.new'))
        end
      end
    end
  end
end