aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-07-03 15:26:33 +0200
committerXinhui2017-07-03 16:35:51 +0200
commit69723fff92b21b4fff722cefe1ca169ed308f5b2 (patch)
tree7aa5ee4e7a84a1767b80549dad7f958b8ebfa395
parent38df58eb13f8a36f6be73c1624744a0d03e1e1a3 (diff)
downloadchouette-core-69723fff92b21b4fff722cefe1ca169ed308f5b2.tar.bz2
Refactoring workbench spec features
-rw-r--r--spec/factories/referentials.rb1
-rw-r--r--spec/features/workbenches_spec.rb96
2 files changed, 71 insertions, 26 deletions
diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb
index dd5bf1c2e..5348ad96b 100644
--- a/spec/factories/referentials.rb
+++ b/spec/factories/referentials.rb
@@ -8,5 +8,6 @@ FactoryGirl.define do
association :line_referential
association :stop_area_referential
time_zone "Europe/Paris"
+ ready { true }
end
end
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
index 953eb2bf5..0d05711ca 100644
--- a/spec/features/workbenches_spec.rb
+++ b/spec/features/workbenches_spec.rb
@@ -3,50 +3,94 @@
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(:line_ref) { create :line_referential }
+ let(:line) { create :line, line_referential: line_ref }
+ let(:ref_metadata) { create(:referential_metadata, lines: [line]) }
- let(:referential_metadatas) { Array.new(2) { |i| 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
- let!(:ready_referential) { create :referential, workbench: workbench, metadatas: referential_metadatas, ready: true, organisation: @user.organisation }
- let!(:unready_referential) { create :referential, workbench: workbench }
+ 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
- before(:each) { visit workbench_path(workbench) }
+ 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}
- 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
+ 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: workbenches.first))
+ 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
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))
+ 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
- visit workbench_path(workbench)
+ referential.destroy
+ visit workbench_path(workbench)
click_link I18n.t('actions.add')
-
- fill_in "referential[name]", with: "Referential to test creation" # Nom du JDD
- select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]' # Lignes
+ 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")