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

  factory :line, :class => Chouette::Line do
    sequence(:name) { |n| "Line #{n}" }
    sequence(:objectid) { |n| "STIF:CODIFLIGNE:Line:#{n}" }
    sequence(:transport_mode) { |n| "bus" }
    sequence(:number, 1)

    association :network, :factory => :network
    association :company, :factory => :company

    before(:create) do |line|
      line.line_referential ||= LineReferential.find_by! name: "first"
    end

    sequence(:registration_number) { |n| "test-#{n}" }

    factory :line_with_stop_areas do

      transient do
        routes_count 2
        stop_areas_count 5
      end

      after(:create) do |line, evaluator|
        create_list(:route, evaluator.routes_count, :line => line) do |route|
          create_list(:stop_area, evaluator.stop_areas_count, area_type: "zdep") do |stop_area|
            create(:stop_point, :stop_area => stop_area, :route => route)
          end
        end
      end

      factory :line_with_stop_areas_having_parent do

        after(:create) do |line|
          line.routes.each do |route|
            route.stop_points.each do |stop_point|
              comm = create(:stop_area, :area_type => "gdl")
              stop_point.stop_area.update_attributes(:parent_id => comm.id)
            end
          end
        end
      end

    end

    factory :line_with_after_commit do |line|
      line.run_callbacks(:commit)

    end

  end

end