aboutsummaryrefslogtreecommitdiffstats
path: root/spec/controllers/autocomplete_time_tables_controller_spec.rb
blob: 02bf83b6e8122471fad98173912765d0f036e840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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' }
  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
      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 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'}, 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