aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-07-03 17:15:49 +0200
committerXinhui2017-07-03 17:15:49 +0200
commit433c498ac44aac684f0165265e3da437cafa3243 (patch)
tree725c097f40a6948e10671068369c8fb852c50e98
parentadc8e323d6f76baf50d649b47bf83f08468681c0 (diff)
downloadchouette-core-433c498ac44aac684f0165265e3da437cafa3243.tar.bz2
Workbench#show filtering restore q_for_result
-rw-r--r--app/controllers/workbenches_controller.rb29
-rw-r--r--app/views/workbenches/_filters.html.slim2
-rw-r--r--spec/features/workbenches_spec.rb43
3 files changed, 44 insertions, 30 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index a53e21269..30b98eec0 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -10,20 +10,10 @@ class WorkbenchesController < BreadcrumbController
scope = ransack_periode(scope)
scope = ransack_status(scope)
- # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
- # We clone params[:q] so we can delete fake ransack filter arguments before calling search method,
- # which will allow us to preserve params[:q] for sorting
- ransack_params = params[:q].clone
- ransack_params.delete('associated_lines_id_eq')
- ransack_params.delete('archived_at_not_null')
- ransack_params.delete('archived_at_null')
-
- @q = scope.ransack(ransack_params)
- @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30)
- @wbench_refs = ModelDecorator.decorate(
- @wbench_refs,
- with: ReferentialDecorator
- )
+ @q_for_form = scope.ransack(params[:q])
+ @q_for_result = scope.ransack(ransack_params)
+ @wbench_refs = sort_result(@q_for_result.result).paginate(page: params[:page], per_page: 30)
+ @wbench_refs = ModelDecorator.decorate(@wbench_refs, with: ReferentialDecorator)
show! do
build_breadcrumb :show
@@ -101,4 +91,15 @@ class WorkbenchesController < BreadcrumbController
scope = scope.where("archived_at is not null") if archived
scope
end
+
+ # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
+ # We clone params[:q] so we can delete fake ransack filter arguments before calling search method,
+ # which will allow us to preserve params[:q] for sorting
+ def ransack_params
+ copy_params = params[:q].clone
+ copy_params.delete('associated_lines_id_eq')
+ copy_params.delete('archived_at_not_null')
+ copy_params.delete('archived_at_null')
+ copy_params
+ end
end
diff --git a/app/views/workbenches/_filters.html.slim b/app/views/workbenches/_filters.html.slim
index 4eaf910c0..d7ac79577 100644
--- a/app/views/workbenches/_filters.html.slim
+++ b/app/views/workbenches/_filters.html.slim
@@ -1,4 +1,4 @@
-= search_form_for @q, url: workbench_path(@workbench.id), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f|
+= search_form_for @q_for_form, url: workbench_path(@workbench.id), builder: SimpleForm::FormBuilder, class: 'form form-filter' do |f|
.ffg-row
.input-group.search_bar
= f.search_field :name_cont, class: 'form-control', placeholder: 'Indiquez un nom de référentiel...'
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
index 3c7d03bcb..2f453389d 100644
--- a/spec/features/workbenches_spec.rb
+++ b/spec/features/workbenches_spec.rb
@@ -42,24 +42,31 @@ describe 'Workbenches', type: :feature do
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'
+ 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
+ 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'
+ 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
+ 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
@@ -89,6 +96,12 @@ describe 'Workbenches', type: :feature do
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
end