aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-04-13 16:01:27 +0200
committerZog2018-04-13 16:01:27 +0200
commit90efaf80b029cb33495c637ded5eeb65cf1601c4 (patch)
tree38d40e6389b94a61c3fafa157ba5cfeaaa644f99
parent94090e82bfb5f875f70aa1e8bffb8a51724eb760 (diff)
downloadchouette-core-6458-fix-timetable-autocomplete.tar.bz2
Refs #6458; Fix Timetables autocompletion6458-fix-timetable-autocomplete
-rw-r--r--app/models/chouette/time_table.rb2
-rw-r--r--spec/controllers/autocomplete_time_tables_controller_spec.rb29
2 files changed, 28 insertions, 3 deletions
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index b59c95665..648a0c5ea 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -16,7 +16,7 @@ module Chouette
end
ransacker :unaccented_comment, formatter: ->(val){ val.parameterize } do
- Arel.sql('unaccent(comment)')
+ Arel.sql('unaccent(time_tables.comment)')
end
has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney'
diff --git a/spec/controllers/autocomplete_time_tables_controller_spec.rb b/spec/controllers/autocomplete_time_tables_controller_spec.rb
index 85a8eb714..02bf83b6e 100644
--- a/spec/controllers/autocomplete_time_tables_controller_spec.rb
+++ b/spec/controllers/autocomplete_time_tables_controller_spec.rb
@@ -8,6 +8,11 @@ RSpec.describe AutocompleteTimeTablesController, type: :controller do
let!(:time_table) { create :time_table, comment: 'écolà militaire' }
let!(:blargh) { create :time_table, comment: 'écolàë militaire' }
let!(:other_time_table) { create :time_table, comment: 'foo bar baz' }
+ let(:route){ create :route }
+
+ before do
+ create :vehicle_journey, time_tables: [time_table, blargh, other_time_table], journey_pattern: route.full_journey_pattern
+ end
describe 'GET #index' do
it 'should be successful' do
@@ -17,7 +22,7 @@ RSpec.describe AutocompleteTimeTablesController, type: :controller do
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
+ 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 include(time_table)
expect(assigns(:time_tables)).to include(blargh)
@@ -25,13 +30,33 @@ RSpec.describe AutocompleteTimeTablesController, type: :controller do
end
it 'should be accent insensitive' do
- get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'ecola'}, :format => :json
+ 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 include(time_table)
expect(assigns(:time_tables)).to include(blargh)
expect(assigns(:time_tables)).to_not include(other_time_table)
end
end
+
+ context "within a route" do
+ context 'search by name' do
+ it 'should be successful' do
+ get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'écolà'}, route_id: route.id, format: :json
+ expect(response).to be_success
+ expect(assigns(:time_tables)).to include(time_table)
+ expect(assigns(:time_tables)).to include(blargh)
+ expect(assigns(:time_tables)).to_not include(other_time_table)
+ end
+
+ it 'should be accent insensitive' do
+ get :index, referential_id: referential.id, q: {unaccented_comment_or_objectid_cont_any: 'ecola'}, route_id: route.id, format: :json
+ expect(response).to be_success
+ expect(assigns(:time_tables)).to include(time_table)
+ expect(assigns(:time_tables)).to include(blargh)
+ expect(assigns(:time_tables)).to_not include(other_time_table)
+ end
+ end
+ end
end
end