aboutsummaryrefslogtreecommitdiffstats
path: root/spec/features/time_tables_spec.rb
blob: de0d33a9d63183e89b5a6f068a7df9e958b8a0d1 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
require 'spec_helper'

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

  let!(:time_tables) { Array.new(2) { create(:time_table) } }
  let(:time_table) { time_tables.first }
  subject { time_tables.first }

  describe "index" do
    before(:each) { visit referential_time_tables_path(referential) }

    it "displays time_tables" do
      expect(page).to have_content(time_tables.first.comment)
      expect(page).to have_content(time_tables.last.comment)
    end

    context 'user has permission to create time tables' do
      it 'shows a create link for time tables' do
        expect(page).to have_content(I18n.t('time_tables.actions.new'))
      end
    end

    context 'user does not have permission to create time tables' do
      it 'does not show a create link for time tables' do
        @user.update_attribute(:permissions, [])
        visit referential_time_tables_path(referential)
        expect(page).not_to have_content(I18n.t('time_tables.actions.new'))
      end
    end

    context 'user has permission to edit time tables' do
      it 'shows an edit button for time tables' do
        expect(page).to have_css('span.fa.fa-pencil')
      end
    end

    context 'user does not have permission to edit time tables' do
      it 'does not show a edit link for time tables' do
        @user.update_attribute(:permissions, [])
        visit referential_time_tables_path(referential)
        expect(page).not_to have_css('span.fa.fa-pencil')
      end
    end

    context 'user has permission to destroy time tables' do
      it 'shows a destroy button for time tables' do
        expect(page).to have_css('span.fa.fa-trash-o')
      end
    end

    context 'user does not have permission to destroy time tables' do
      it 'does not show a destroy button for time tables' do
        @user.update_attribute(:permissions, [])
        visit referential_time_tables_path(referential)
        expect(page).not_to have_css('span.fa.fa-trash-o')
      end
    end

  end

  describe "show" do
    before(:each) { visit referential_time_table_path(referential, time_table) }

    it "displays time_table" do
      expect(page).to have_content(time_tables.first.comment)
    end

    context 'user has permission to create time tables' do
      it 'shows a create link for time tables' do
        expect(page).to have_content(I18n.t('time_tables.actions.new'))
      end

      it 'does not show link to duplicate the time table' do
        expect(page).to have_content(I18n.t('time_tables.actions.duplicate'))
      end
    end

    context 'user does not have permission to create time tables' do
      it 'does not show a create link for time tables' do
        @user.update_attribute(:permissions, [])
        visit referential_time_table_path(referential, time_table)
        expect(page).not_to have_content(I18n.t('time_tables.actions.new'))
      end

      it 'does not show link to duplicate the time table' do
        @user.update_attribute(:permissions, [])
        visit referential_time_table_path(referential, time_table)
        expect(page).not_to have_content(I18n.t('time_tables.actions.duplicate'))
      end
    end

    context 'user has permission to edit time tables' do
      it 'shows the edit link for time table' do
        expect(page).to have_content(I18n.t('time_tables.actions.edit'))
      end
    end

    context 'user does not have permission to edit time tables' do
      it 'does not show the edit link for time table' do
        @user.update_attribute(:permissions, [])
        visit referential_time_table_path(referential, time_table)
        expect(page).not_to have_content(I18n.t('time_tables.actions.edit'))
      end
    end

    context 'user has permission to destroy time tables' do
      it 'shows the destroy link for time table' do
        expect(page).to have_content(I18n.t('time_tables.actions.destroy'))
      end
    end

    context 'user does not have permission to destroy time tables' do
      it 'does not show a destroy link for time table' do
        @user.update_attribute(:permissions, [])
        visit referential_time_table_path(referential, time_table)
        expect(page).not_to have_content(I18n.t('time_tables.actions.destroy'))
      end
    end
  end

  describe "new" do
    it "creates time_table and return to show" do
      visit referential_time_tables_path(referential)
      click_link "Ajouter un calendrier"
      fill_in "Nom", :with => "TimeTable 1"
      fill_in "Identifiant Neptune", :with => "test:Timetable:1"
      click_button("Créer calendrier")
      expect(page).to have_content("TimeTable 1")
    end
  end

  describe "edit and return to show" do
    it "edit time_table" do
      visit referential_time_table_path(referential, subject)
      click_link "Modifier ce calendrier"
      fill_in "Nom", :with => "TimeTable Modified"
      click_button("Modifier calendrier")
      expect(page).to have_content("TimeTable Modified")
    end
  end

end