aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/workbenches_spec.rb
blob: 717be96fa5341cbc2591a87b4b6e08b2b331e475 (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
# coding: utf-8
require 'spec_helper'

describe 'Workbenches', type: :feature do
  login_user

  #let!(:organisations) { Array.new(2) { create :organisation } }
  #let!(:referentials) { Array.new(2) { create :referential, ready: true } }
  let(:line_referential) { create :line_referential }
  let(:workbenches) { Array.new(2) { create :workbench, line_referential: line_referential, organisation: @user.organisation } }
  let(:workbench) { workbenches.first }
  let!(:line) { create :line, line_referential: line_referential }

  let(:referential_metadatas) { Array.new(2) { |i| create :referential_metadata, lines: [line] } }

  describe 'show' do

    let!(:ready_referential) { create :referential, workbench: workbench, metadatas: referential_metadatas, ready: true, organisation: @user.organisation }
    let!(:unready_referential) { create :referential, workbench: workbench }

    before(:each) { visit workbench_path(workbench) }

    it 'shows ready referentials belonging to that workbench by default' do
      expect(page).to have_content(ready_referential.name)
      expect(page).not_to have_content(unready_referential.name)
    end

    context 'user has the permission to create referentials' do
      it 'shows the link for a new referetnial' do
        expect(page).to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbenches.first))
      end
    end

    context 'user does not have the permission to create referentials' do
      it 'does not show the clone link for referetnial' do
        @user.update_attribute(:permissions, [])
        visit referential_path(referential)
        expect(page).not_to have_link(I18n.t('actions.add'), href: new_referential_path(workbench_id: workbenches.first))
      end
    end
  end

  describe 'create new Referential' do
    it "create a new Referential with a specifed line and period" do
      visit workbench_path(workbench)

      click_link I18n.t('actions.add')

      fill_in "referential[name]", with: "Referential to test creation" # Nom du JDD
      fill_in "referential[slug]", with: "test" # Code
      fill_in "referential[prefix]", with: "test" # Prefix Neptune
      select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]' # Lignes

      click_button "Valider"
      expect(page).to have_css("h1", text: "Referential to test creation")
    end
  end
end