blob: ea3bc1fe19ce4c17e708045f08f01fc544dbe20e (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  | 
require 'spec_helper'
describe "referentials/show", type: :view do
  let!(:referential) do
    referential = create(:referential, organisation: organisation)
    assign :referential, referential.decorate(context: {
      current_organisation: referential.organisation
    })
  end
  let(:permissions){ [] }
  let(:current_organisation) { organisation }
  let(:current_offer_workbench) { create :workbench, organisation: organisation}
  let(:current_workgroup) { current_offer_workbench.workgroup }
  let(:readonly){ false }
  before :each do
    assign :reflines, []
    allow(view).to receive(:current_offer_workbench).and_return(current_offer_workbench)
    allow(view).to receive(:current_organisation).and_return(current_organisation)
    allow(view).to receive(:current_workgroup).and_return(current_workgroup)
    allow(view).to receive(:current_user).and_return(current_user)
    allow(view).to receive(:resource).and_return(referential)
    allow(view).to receive(:has_feature?).and_return(true)
    allow(view).to receive(:user_signed_in?).and_return true
    controller.request.path_parameters[:id] = referential.id
    allow(view).to receive(:params).and_return({action: :show})
    allow(referential).to receive(:referential_read_only?){ readonly }
  end
  describe "action links" do
    set_invariant "referential.object.full_name", "referential_full_name"
    set_invariant "referential.object.updated_at", "01/01/2000 00:00".to_time
    set_invariant "referential.object.id", "99"
    before(:each){
      render template: "referentials/show", layout: "layouts/application"
    }
    context "with a readonly referential" do
      let(:readonly){ true }
      it { should match_actions_links_snapshot "referentials/show_readonly" }
      %w(create destroy update).each do |p|
        with_permission "referentials.#{p}" do
          it { should match_actions_links_snapshot "referentials/show_readonly_#{p}" }
        end
      end
    end
    context "with a non-readonly referential" do
      it { should match_actions_links_snapshot "referentials/show" }
      %w(create destroy update).each do |p|
        with_permission "referentials.#{p}" do
          it { should match_actions_links_snapshot "referentials/show_#{p}" }
        end
      end
    end
    %w(purchase_windows referential_vehicle_journeys).each do |f|
      with_feature f do
        it { should match_actions_links_snapshot "referentials/show_#{f}" }
        %w(create update destroy).each do |p|
          with_permission "referentials.#{p}" do
            it { should match_actions_links_snapshot "referentials/show_#{f}_#{p}" }
          end
        end
      end
    end
  end
end
  |