| 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
 | require 'rails_helper'
RSpec.describe AutocompleteStopAreasController, type: :controller do
  login_user
  let(:referential) { Referential.first }
  let(:other_referential) { create :referential }
  let!(:stop_area) { create :stop_area, name: 'écolà militaire', referential: referential }
  let!(:other_referential_stop_area) { create :stop_area, name: 'écolà militaire', referential: other_referential }
  let!(:zdep_stop_area) { create :stop_area, area_type: "zdep", referential: referential }
  let!(:not_zdep_stop_area) { create :stop_area, area_type: "lda", referential: referential }
  describe 'GET #index' do
    it 'should be successful' do
      get :index, referential_id: referential.id
      expect(response).to be_success
    end
    it "should filter stop areas based on referential" do
      get :index, referential_id: referential.id
      expect(assigns(:stop_areas)).to include(stop_area)
      expect(assigns(:stop_areas)).to_not include(other_referential_stop_area)
    end
    context 'search by name' do
      it 'should be successful' do
        get :index, referential_id: referential.id, q: 'écolà', :format => :json
        expect(response).to be_success
        expect(assigns(:stop_areas)).to eq([stop_area])
      end
      it 'should be accent insensitive' do
        get :index, referential_id: referential.id, q: 'ecola', :format => :json
        expect(response).to be_success
        expect(assigns(:stop_areas)).to eq([stop_area])
      end
    end
  end
  context "when searching from the route editor" do
    let(:scope) { :route_editor }
    let(:request){
      get :index, referential_id: referential.id, scope: scope
    }
    it "should filter stop areas based on type" do
      request
      expect(assigns(:stop_areas)).to include(zdep_stop_area)
      expect(assigns(:stop_areas)).to_not include(not_zdep_stop_area)
    end
    with_feature :route_stop_areas_all_types do
      it "should not filter stop areas based on type" do
        request
        expect(assigns(:stop_areas)).to include(zdep_stop_area)
        expect(assigns(:stop_areas)).to include(not_zdep_stop_area)
      end
    end
  end
end
 |