aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/chouette/routing_constraint_zone_spec.rb
blob: 321b41b7bba03d4f37c7a316b1b76a88f9a1ede1 (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
require 'spec_helper'

describe Chouette::RoutingConstraintZone, type: :model do

  subject { create(:routing_constraint_zone) }

  it { is_expected.to validate_presence_of :name }
  it { is_expected.to validate_presence_of :route_id }
  # shoulda matcher to validate length of array ?
  xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) }
  

  describe 'checksum' do
    it_behaves_like 'checksum support'
  end

  describe 'validations' do
    it 'validates the presence of stop_point_ids' do
      expect {
        subject.update!(stop_point_ids: [])
      }.to raise_error(ActiveRecord::RecordInvalid)
    end

    it 'validates that stop points belong to the route' do
      route = create(:route)
      expect {
        subject.update!(route_id: route.id)
      }.to raise_error(ActiveRecord::RecordInvalid)
    end

    xit 'validates that not all stop points from the route are selected' do
      routing_constraint_zone.stop_points = routing_constraint_zone.route.stop_points
      expect {
        subject.save!
      }.to raise_error(ActiveRecord::RecordInvalid)
    end
  end

  describe 'deleted stop areas' do
    it 'does not have them in stop_area_ids' do
      stop_point = subject.route.stop_points.last
      subject.stop_points << stop_point
      subject.save!
      subject.route.stop_points.last.destroy!
      expect(subject.stop_points.map(&:id)).not_to include(stop_point.id)
    end
  end

end