| 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
63
64
65
66
67
68
69
70
71
72
73
 | RSpec.describe StopAreasController, :type => :controller do
  login_user
  let(:stop_area_referential) { create :stop_area_referential, member: @user.organisation }
  let(:stop_area) { create :stop_area, stop_area_referential: stop_area_referential }
  describe "GET index" do
    it "filters by registration number" do
      registration_number = 'E34'
      matched = create(
        :stop_area,
        stop_area_referential: stop_area_referential,
        registration_number: registration_number
      )
      create(
        :stop_area,
        stop_area_referential: stop_area_referential,
        registration_number: "doesn't match"
      )
      get :index,
        stop_area_referential_id: stop_area_referential.id,
        q: {
          name_or_objectid_or_registration_number_cont: registration_number
        }
      expect(assigns(:stop_areas)).to eq([matched])
    end
    it "doesn't filter when the name filter is empty" do
      get :index,
        stop_area_referential_id: stop_area_referential.id,
        q: {
          name_or_objectid_or_registration_number_cont: ''
        }
      expect(assigns(:stop_areas)).to eq([stop_area])
    end
  end
  describe 'PUT deactivate' do
    let(:request){ put :deactivate, id: stop_area.id, stop_area_referential_id: stop_area_referential.id }
    it 'should respond with 403' do
      expect(request).to have_http_status 403
    end
    with_permission "stop_areas.change_status" do
      it 'returns HTTP success' do
        expect(request).to redirect_to [stop_area_referential, stop_area]
        expect(stop_area.reload).to be_deactivated
      end
    end
  end
  describe 'PUT activate' do
    let(:request){ put :activate, id: stop_area.id, stop_area_referential_id: stop_area_referential.id }
    before(:each){
      stop_area.deactivate!
    }
    it 'should respond with 403' do
      expect(request).to have_http_status 403
    end
    with_permission "stop_areas.change_status" do
      it 'returns HTTP success' do
        expect(request).to redirect_to [stop_area_referential, stop_area]
        expect(stop_area.reload).to be_activated
      end
    end
  end
end
 |