diff options
| -rw-r--r-- | app/controllers/calendars_controller.rb | 14 | ||||
| -rw-r--r-- | app/views/calendars/_filters.html.slim | 5 | ||||
| -rw-r--r-- | spec/features/calendars_spec.rb | 31 |
3 files changed, 30 insertions, 20 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index 3e7a05231..c33aa9373 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,7 +1,7 @@ class CalendarsController < BreadcrumbController include PolicyChecker defaults resource_class: Calendar - + before_action :ransack_contains_date, only: [:index] respond_to :html respond_to :js, only: :index @@ -39,5 +39,17 @@ class CalendarsController < BreadcrumbController calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction @calendars = calendars.paginate(page: params[:page]) end + + def ransack_contains_date + # 3 parts to date object, in order to use in ransackable_scopes + if params[:q] && !params[:q]['contains_date(1i)'].empty? + date =[] + ['contains_date(1i)', 'contains_date(2i)', 'contains_date(3i)'].each do |key| + date << params[:q][key] + params[:q].delete(key) + end + params[:q]['contains_date'] = Date.parse(date.join('-')) + end + end end diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim index 4fc11b5c7..d8707ba0f 100644 --- a/app/views/calendars/_filters.html.slim +++ b/app/views/calendars/_filters.html.slim @@ -9,12 +9,11 @@ .ffg-row .form-group.has_switch style='width: 260px' = f.label Calendar.human_attribute_name(:shared), class: 'col-sm-4 control-label' - = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, '', class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8' } + = f.input :shared_true, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, '', class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8' } .form-group = f.label Calendar.human_attribute_name(:date), class: 'control-label' - = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date' }, class: 'form-control' - + = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date' }, class: 'form-control', include_blank: true .actions = link_to 'Effacer', calendars_path, class: 'btn btn-link' = f.submit 'Filtrer', id: 'filter_btn', class: 'btn btn-default' diff --git a/spec/features/calendars_spec.rb b/spec/features/calendars_spec.rb index bb30cff0f..d4234fc50 100644 --- a/spec/features/calendars_spec.rb +++ b/spec/features/calendars_spec.rb @@ -18,23 +18,22 @@ describe 'Calendars', type: :feature do end context 'filtering' do - # Fixme ! - # it 'supports filtering by short name' do - # fill_in 'q[short_name_cont]', with: calendars.first.short_name - # click_button 'search_btn' - # expect(page).to have_content(calendars.first.short_name) - # expect(page).not_to have_content(calendars.last.short_name) - # end + it 'supports filtering by short name' do + fill_in 'q[short_name_cont]', with: calendars.first.short_name + click_button 'search_btn' + expect(page).to have_content(calendars.first.short_name) + expect(page).not_to have_content(calendars.last.short_name) + end - # it 'supports filtering by shared' do - # shared_calendar = create :calendar, organisation_id: 1, shared: true - # visit calendars_path - # # select I18n.t('true'), from: 'q[shared]' - # find(:css, '#q_shared').set(true) - # click_button 'filter_btn' - # expect(page).to have_content(shared_calendar.short_name) - # expect(page).not_to have_content(calendars.first.short_name) - # end + it 'supports filtering by shared' do + shared_calendar = create :calendar, organisation_id: 1, shared: true + visit calendars_path + # select I18n.t('true'), from: 'q[shared]' + find(:css, '#q_shared_true').set(true) + click_button 'filter_btn' + expect(page).to have_content(shared_calendar.short_name) + expect(page).not_to have_content(calendars.first.short_name) + end # wip # it 'supports filtering by date' do |
