diff options
6 files changed, 40 insertions, 5 deletions
| diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb index 0a9f51ced..dded24a36 100644 --- a/app/controllers/autocomplete_time_tables_controller.rb +++ b/app/controllers/autocomplete_time_tables_controller.rb @@ -23,7 +23,7 @@ class AutocompleteTimeTablesController < ChouetteController    end    def split_params! search -    params[:q][search] = params[:q][search].split(" ") if params[:q][search] +    params[:q][search] = params[:q][search].split(" ") if params[:q] && params[:q][search]    end    def collection diff --git a/app/javascript/vehicle_journeys/components/Filters.js b/app/javascript/vehicle_journeys/components/Filters.js index f8697c930..ae3ab3476 100644 --- a/app/javascript/vehicle_journeys/components/Filters.js +++ b/app/javascript/vehicle_journeys/components/Filters.js @@ -36,7 +36,7 @@ export default function Filters({filters, pagination, missions, onFilter, onRese                  onSelect2Timetable={onSelect2Timetable}                  hasRoute={true}                  chunkURL={("/autocomplete_time_tables.json?route_id=" + String(window.route_id))} -                searchKey={"comment_or_objectid_cont_any"} +                searchKey={"unaccented_comment_or_objectid_cont_any"}                  filters={filters}                  isFilter={true}                  /> diff --git a/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js index e2fcd27d5..f21480563 100644 --- a/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/TimetablesEditVehicleJourney.js @@ -99,7 +99,7 @@ export default class TimetablesEditVehicleJourney extends Component {                                        <TimetableSelect2                                          onSelect2Timetable={this.props.onSelect2Timetable}                                          chunkURL={'/autocomplete_time_tables.json'} -                                        searchKey={"comment_or_objectid_cont_any"} +                                        searchKey={"unaccented_comment_or_objectid_cont_any"}                                          isFilter={false}                                        />                                      </div> diff --git a/app/models/chouette/time_table_date.rb b/app/models/chouette/time_table_date.rb index b3b2fd561..6f6722426 100644 --- a/app/models/chouette/time_table_date.rb +++ b/app/models/chouette/time_table_date.rb @@ -11,6 +11,10 @@ module Chouette      scope :in_dates, -> { where(in_out: true) } +    ransacker :unaccented_comment do +      Arel.sql('unaccent(comment)') +    end +      def self.model_name        ActiveModel::Name.new Chouette::TimeTableDate, Chouette, "TimeTableDate"      end @@ -20,4 +24,4 @@ module Chouette        self.slice(*attrs).values      end    end -end
\ No newline at end of file +end diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim index 426624ee3..6a0fda01e 100644 --- a/app/views/time_table_combinations/_form.html.slim +++ b/app/views/time_table_combinations/_form.html.slim @@ -7,7 +7,7 @@            abbr title='Champ requis' *          = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' } -      = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont_any', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''} +      = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'unaccented_comment_or_objectid_cont_any', url: referential_autocomplete_time_tables_path(@referential, format: :json, :source_id => @combination.source_id)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}        = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''} diff --git a/spec/controllers/autocomplete_time_tables_controller_spec.rb b/spec/controllers/autocomplete_time_tables_controller_spec.rb new file mode 100644 index 000000000..5cc0eced0 --- /dev/null +++ b/spec/controllers/autocomplete_time_tables_controller_spec.rb @@ -0,0 +1,31 @@ +require 'rails_helper' + +RSpec.describe AutocompleteTimeTablesController, type: :controller do +  login_user + +  let(:referential) { Referential.first } +  let(:other_referential) { create :referential } +  let!(:time_table) { create :time_table, comment: 'écolà militaire' } + +  describe 'GET #index' do +    it 'should be successful' do +      get :index, referential_id: referential.id +      expect(response).to be_success +    end + +    context 'search by name' do +      it 'should be successful' do +        get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'écolà'}, :format => :json +        expect(response).to be_success +        expect(assigns(:time_tables)).to eq([time_table]) +      end + +      it 'should be accent insensitive' do +        get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'ecola'}, :format => :json +        expect(response).to be_success +        expect(assigns(:time_tables)).to eq([time_table]) +      end +    end +  end + +end | 
