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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# coding: utf-8
describe 'Workbenches', type: :feature do
login_user
let(:line_ref) { create :line_referential }
let(:line) { create :line, line_referential: line_ref }
let(:ref_metadata) { create(:referential_metadata, lines: [line]) }
let!(:workbench) { create(:workbench, line_referential: line_ref, organisation: @user.organisation) }
let!(:referential) { create :referential, workbench: workbench, metadatas: [ref_metadata], organisation: @user.organisation }
describe 'show' do
context 'ready' do
it 'should show ready referentials' do
visit workbench_path(workbench)
expect(page).to have_content(referential.name)
end
it 'should not show unready referentials' do
referential.update_attribute(:ready, false)
visit workbench_path(workbench)
expect(page).to_not have_content(referential.name)
end
end
context 'filtering' do
let(:another_organisation) { create :organisation }
let(:another_line) { create :line, line_referential: line_ref }
let(:another_ref_metadata) { create(:referential_metadata, lines: [another_line]) }
let!(:other_referential) { create :referential, workbench: workbench, metadatas: [another_ref_metadata], organisation: another_organisation}
before(:each) do
visit workbench_path(workbench)
end
context 'without any filter' do
it 'should have results' do
click_button 'Filtrer'
expect(page).to have_content(referential.name)
expect(page).to have_content(other_referential.name)
end
end
context 'filter by organisation' do
it 'should be possible to filter by organisation' do
find("#q_organisation_name_eq_any_#{@user.organisation.name.parameterize.underscore}").set(true)
click_button 'Filtrer'
expect(page).to have_content(referential.name)
expect(page).not_to have_content(other_referential.name)
end
it 'should be possible to filter by multiple organisation' do
find("#q_organisation_name_eq_any_#{@user.organisation.name.parameterize.underscore}").set(true)
find("#q_organisation_name_eq_any_#{another_organisation.name.parameterize.underscore}").set(true)
click_button 'Filtrer'
expect(page).to have_content(referential.name)
expect(page).to have_content(other_referential.name)
end
it 'should keep filter value on submit' do
box = "#q_organisation_name_eq_any_#{another_organisation.name.parameterize.underscore}"
find(box).set(true)
click_button 'Filtrer'
expect(find(box)).to be_checked
end
end
context 'filter by status' do
it 'should display archived referentials' do
other_referential.update_attribute(:archived_at, Date.today)
find("#q_archived_at_not_null").set(true)
click_button 'Filtrer'
expect(page).to have_content(other_referential.name)
expect(page).to_not have_content(referential.name)
end
it 'should display both archived and unarchived referentials' do
other_referential.update_attribute(:archived_at, Date.today)
find("#q_archived_at_not_null").set(true)
find("#q_archived_at_null").set(true)
click_button 'Filtrer'
expect(page).to have_content(referential.name)
expect(page).to have_content(other_referential.name)
end
it 'should display unarchived referentials' do
other_referential.update_attribute(:archived_at, Date.today)
find("#q_archived_at_null").set(true)
click_button 'Filtrer'
expect(page).to have_content(referential.name)
expect(page).to_not have_content(other_referential.name)
end
it 'should keep filter value on submit' do
find("#q_archived_at_null").set(true)
click_button 'Filtrer'
expect(find("#q_archived_at_null")).to be_checked
end
end
context 'filter by validity period' do
def fill_validity_field date, field
select date.year, :from => "q[validity_period][#{field}(1i)]"
select I18n.t("date.month_names")[date.month], :from => "q[validity_period][#{field}(2i)]"
select date.day, :from => "q[validity_period][#{field}(3i)]"
end
it 'should show results for referential in range' do
dates = referential.validity_period.to_a
fill_validity_field dates[0], 'begin_gteq'
fill_validity_field dates[1], 'end_lteq'
click_button 'Filtrer'
expect(page).to have_content(referential.name)
expect(page).to_not have_content(other_referential.name)
end
it 'should keep filtering on sort' do
dates = referential.validity_period.to_a
fill_validity_field dates[0], 'begin_gteq'
fill_validity_field dates[1], 'end_lteq'
click_button 'Filtrer'
find('a[href*="&sort=validity_period"]').click
expect(page).to have_content(referential.name)
expect(page).to_not have_content(other_referential.name)
end
it 'should not show results for out off range' do
fill_validity_field(Date.today - 2.year, 'begin_gteq')
fill_validity_field(Date.today - 1.year, 'end_lteq')
click_button 'Filtrer'
expect(page).to_not have_content(referential.name)
expect(page).to_not have_content(other_referential.name)
end
it 'should keep value on submit' do
dates = referential.validity_period.to_a
['begin_gteq', 'end_lteq'].each_with_index do |field, index|
fill_validity_field dates[index], field
end
click_button 'Filtrer'
['begin_gteq', 'end_lteq'].each_with_index do |field, index|
expect(find("#q_validity_period_#{field}_3i").value).to eq dates[index].day.to_s
expect(find("#q_validity_period_#{field}_2i").value).to eq dates[index].month.to_s
expect(find("#q_validity_period_#{field}_1i").value).to eq dates[index].year.to_s
end
end
end
end
context 'permissions' do
before(:each) do
visit workbench_path(workbench)
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: workbench.id))
end
end
context 'user does not have the permission to create referentials' do
it 'does not show the clone link for referential' 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: workbench.id))
end
end
end
end
describe 'create new Referential' do
it "create a new Referential with a specifed line and period" do
referential.destroy
visit workbench_path(workbench)
click_link I18n.t('actions.add')
fill_in "referential[name]", with: "Referential to test creation"
select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]'
click_button "Valider"
expect(page).to have_css("h1", text: "Referential to test creation")
end
end
end
|