aboutsummaryrefslogtreecommitdiffstats
path: root/spec/factories/chouette_journey_pattern.rb
blob: d96302e7f9cafa303e4f1cc2c67ea44f1eb754ce (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
FactoryGirl.define do

  factory :journey_pattern_common, :class => Chouette::JourneyPattern do
    sequence(:name) { |n| "jp name #{n}" }
    sequence(:published_name) { |n| "jp publishedname #{n}" }
    sequence(:comment) { |n| "jp comment #{n}" }
    sequence(:registration_number) { |n| "jp registration_number #{n}" }
    sequence(:objectid) { |n| "organisation:JourneyPattern:lineId-#{n}:LOC" }
    association :route, :factory => :route

    factory :journey_pattern do
      after(:create) do |j|
        j.stop_point_ids = j.route.stop_points.map(&:id)
        j.departure_stop_point_id = j.route.stop_points.first.id
        j.arrival_stop_point_id = j.route.stop_points.last.id
        j.costs = {
          "1-2": {
            distance: 10,
            time: 10
          }
        }
      end
    end

    factory :journey_pattern_odd do
      after(:create) do |j|
        j.stop_point_ids = j.route.stop_points.select { |sp| sp.position%2==0}.map(&:id)
        j.departure_stop_point_id = j.stop_point_ids.first
        j.arrival_stop_point_id = j.stop_point_ids.last
      end
    end

    factory :journey_pattern_even do
      after(:create) do |j|
        j.stop_point_ids = j.route.stop_points.select { |sp| sp.position%2==1}.map(&:id)
        j.departure_stop_point_id = j.stop_point_ids.first
        j.arrival_stop_point_id = j.stop_point_ids.last
      end
    end

  end

end