ninoxe 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/chouette/vehicle_journey_at_stop.rb +5 -5
- data/lib/ninoxe/version.rb +1 -1
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +19 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/locales/fr.yml +23 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/db/schema.rb +490 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/chouette_access_links.rb +13 -0
- data/spec/factories/chouette_access_points.rb +12 -0
- data/spec/factories/chouette_companies.rb +9 -0
- data/spec/factories/chouette_connection_links.rb +13 -0
- data/spec/factories/chouette_footnotes.rb +10 -0
- data/spec/factories/chouette_group_of_lines.rb +9 -0
- data/spec/factories/chouette_journey_pattern.rb +40 -0
- data/spec/factories/chouette_lines.rb +44 -0
- data/spec/factories/chouette_networks.rb +9 -0
- data/spec/factories/chouette_routes.rb +26 -0
- data/spec/factories/chouette_stop_areas.rb +12 -0
- data/spec/factories/chouette_stop_points.rb +10 -0
- data/spec/factories/chouette_time_table.rb +37 -0
- data/spec/factories/chouette_vehicle_journey.rb +66 -0
- data/spec/factories/chouette_vehicle_journey_at_stop.rb +8 -0
- data/spec/models/chouette/access_link_spec.rb +82 -0
- data/spec/models/chouette/access_point_spec.rb +269 -0
- data/spec/models/chouette/active_record_spec.rb +121 -0
- data/spec/models/chouette/area_type_spec.rb +53 -0
- data/spec/models/chouette/company_spec.rb +48 -0
- data/spec/models/chouette/connection_link_spec.rb +60 -0
- data/spec/models/chouette/direction_spec.rb +60 -0
- data/spec/models/chouette/exporter_spec.rb +28 -0
- data/spec/models/chouette/file_validator_spec.rb +28 -0
- data/spec/models/chouette/footnote_spec.rb +9 -0
- data/spec/models/chouette/group_of_line_spec.rb +31 -0
- data/spec/models/chouette/journey_pattern_spec.rb +64 -0
- data/spec/models/chouette/line_spec.rb +120 -0
- data/spec/models/chouette/loader_spec.rb +69 -0
- data/spec/models/chouette/network_spec.rb +19 -0
- data/spec/models/chouette/object_id_spec.rb +149 -0
- data/spec/models/chouette/route_spec.rb +238 -0
- data/spec/models/chouette/stop_area_spec.rb +443 -0
- data/spec/models/chouette/stop_point_spec.rb +41 -0
- data/spec/models/chouette/time_table_period_spec.rb +66 -0
- data/spec/models/chouette/time_table_spec.rb +1266 -0
- data/spec/models/chouette/transport_mode_spec.rb +64 -0
- data/spec/models/chouette/trident_active_record_spec.rb +115 -0
- data/spec/models/chouette/vehicle_journey_at_stop_spec.rb +47 -0
- data/spec/models/chouette/vehicle_journey_spec.rb +223 -0
- data/spec/presenters/chouette/geometry/general_presenter.rb +1 -0
- data/spec/presenters/chouette/geometry/line_presenter_spec.rb +13 -0
- data/spec/spec_helper.rb +58 -0
- metadata +178 -10
- data/config/database.yml.me +0 -11
- data/lib/ninoxe.rb~ +0 -7
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::Loader, :type => :model do
|
4
|
+
|
5
|
+
subject { Chouette::Loader.new("test") }
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
allow(subject).to receive_messages :execute! => true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#load_dump" do
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#import" do
|
16
|
+
|
17
|
+
let(:chouette_command) { double :run! => true }
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
allow(subject).to receive_messages :chouette_command => chouette_command
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should use specified file in -inputFile option" do
|
24
|
+
expect(chouette_command).to receive(:run!).with(hash_including(:input_file => File.expand_path('file')))
|
25
|
+
subject.import "file"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should use specified format in -format option" do
|
29
|
+
expect(chouette_command).to receive(:run!).with(hash_including(:format => 'DUMMY'))
|
30
|
+
subject.import "file", :format => "dummy"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#create" do
|
36
|
+
|
37
|
+
it "should quote schema name" do
|
38
|
+
expect(subject).to receive(:execute!).with(/"test"/)
|
39
|
+
subject.create
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#drop" do
|
45
|
+
|
46
|
+
it "should quote schema name" do
|
47
|
+
expect(subject).to receive(:execute!).with(/"test"/)
|
48
|
+
subject.drop
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#backup" do
|
54
|
+
|
55
|
+
let(:file) { "/dev/null" }
|
56
|
+
|
57
|
+
it "should call pg_dump" do
|
58
|
+
expect(subject).to receive(:execute!).with(/^pg_dump/)
|
59
|
+
subject.backup file
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should dump in specified file" do
|
63
|
+
expect(subject).to receive(:execute!).with(/-f #{file}/)
|
64
|
+
subject.backup file
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::Network, :type => :model do
|
4
|
+
|
5
|
+
subject { create(:network) }
|
6
|
+
|
7
|
+
it { is_expected.to validate_presence_of :name }
|
8
|
+
|
9
|
+
# it { should validate_presence_of :objectid }
|
10
|
+
it { is_expected.to validate_uniqueness_of :objectid }
|
11
|
+
|
12
|
+
describe "#stop_areas" do
|
13
|
+
let!(:line){create(:line, :network => subject)}
|
14
|
+
let!(:route){create(:route, :line => line)}
|
15
|
+
it "should retrieve route's stop_areas" do
|
16
|
+
expect(subject.stop_areas.count).to eq(route.stop_points.count)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::ObjectId, :type => :model do
|
4
|
+
|
5
|
+
def objectid(value = "abc:StopArea:abc123")
|
6
|
+
Chouette::ObjectId.new value
|
7
|
+
end
|
8
|
+
|
9
|
+
subject { objectid }
|
10
|
+
|
11
|
+
context "when invalid" do
|
12
|
+
|
13
|
+
subject { objectid("abc") }
|
14
|
+
|
15
|
+
it { is_expected.not_to be_valid }
|
16
|
+
|
17
|
+
describe '#parts' do
|
18
|
+
subject { super().parts }
|
19
|
+
it { is_expected.to be_nil }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#system_id' do
|
23
|
+
subject { super().system_id }
|
24
|
+
it { is_expected.to be_nil }
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when with spaces in last part" do
|
30
|
+
|
31
|
+
subject { objectid("abc:Line:Aze toto") }
|
32
|
+
|
33
|
+
it { is_expected.not_to be_valid }
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
context "when with spaces in first part" do
|
39
|
+
|
40
|
+
subject { objectid("ae abc:Line:Aze") }
|
41
|
+
|
42
|
+
it { is_expected.not_to be_valid }
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when with spaces in middle part" do
|
48
|
+
|
49
|
+
subject { objectid("aeabc:Li ne:Aze") }
|
50
|
+
|
51
|
+
it { is_expected.not_to be_valid }
|
52
|
+
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when invalid in first part" do
|
57
|
+
|
58
|
+
subject { objectid("Abc_+19:Line:Abc") }
|
59
|
+
|
60
|
+
it { is_expected.not_to be_valid }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when invalid in middle part" do
|
64
|
+
|
65
|
+
subject { objectid("Abc_19:Li56ne:Abc") }
|
66
|
+
|
67
|
+
it { is_expected.not_to be_valid }
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when invalid in last part" do
|
71
|
+
|
72
|
+
subject { objectid("Abc_19:Line:Ab+c") }
|
73
|
+
|
74
|
+
it { is_expected.not_to be_valid }
|
75
|
+
end
|
76
|
+
context "when valid" do
|
77
|
+
|
78
|
+
subject { objectid("Abc_19:Line:Abc_12-") }
|
79
|
+
|
80
|
+
it { is_expected.to be_valid }
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#parts" do
|
84
|
+
|
85
|
+
it "should be the 3 parts of the ObjectId" do
|
86
|
+
expect(objectid("abc:StopArea:abc123").parts).to eq(%w{abc StopArea abc123})
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#system_id" do
|
92
|
+
|
93
|
+
it "should be the first ObjectId parts" do
|
94
|
+
expect(objectid("first:second:third").system_id).to eq("first")
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#object_type" do
|
100
|
+
|
101
|
+
it "should be the second ObjectId parts" do
|
102
|
+
expect(objectid("first:second:third").object_type).to eq("second")
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#local_id" do
|
108
|
+
|
109
|
+
it "should be the third ObjectId parts" do
|
110
|
+
expect(objectid("first:second:third").local_id).to eq("third")
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should be valid when parts are found" do
|
116
|
+
allow(subject).to receive_messages :parts => "dummy"
|
117
|
+
expect(subject).to be_valid
|
118
|
+
end
|
119
|
+
|
120
|
+
describe ".create" do
|
121
|
+
|
122
|
+
let(:given_system_id) { "systemId" }
|
123
|
+
let(:given_object_type) { "objectType" }
|
124
|
+
let(:given_local_id) { "localId" }
|
125
|
+
|
126
|
+
subject { Chouette::ObjectId.create(given_system_id, given_object_type, given_local_id) }
|
127
|
+
|
128
|
+
it "should return ObjectId attributes" do
|
129
|
+
expect(subject.send(:system_id)).to eq(given_system_id)
|
130
|
+
expect(subject.send(:object_type)).to eq(given_object_type)
|
131
|
+
expect(subject.send(:local_id)).to eq(given_local_id)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
describe ".new" do
|
137
|
+
|
138
|
+
it "should return an existing ObjectId" do
|
139
|
+
expect(Chouette::ObjectId.new(objectid)).to eq(objectid)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should create an empty ObjectId with nil" do
|
143
|
+
expect(Chouette::ObjectId.new(nil)).to be_empty
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::Route, :type => :model do
|
4
|
+
subject { create(:route) }
|
5
|
+
|
6
|
+
it { is_expected.to validate_uniqueness_of :objectid }
|
7
|
+
|
8
|
+
describe '#objectid' do
|
9
|
+
subject { super().objectid }
|
10
|
+
it { is_expected.to be_kind_of(Chouette::ObjectId) }
|
11
|
+
end
|
12
|
+
|
13
|
+
#it { is_expected.to validate_presence_of :name }
|
14
|
+
it { is_expected.to validate_presence_of :line }
|
15
|
+
#it { is_expected.to validate_presence_of :wayback_code }
|
16
|
+
#it { is_expected.to validate_presence_of :direction_code }
|
17
|
+
|
18
|
+
context "reordering methods" do
|
19
|
+
let( :bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}}
|
20
|
+
let( :ident){subject.stop_points.map(&:id)}
|
21
|
+
let( :first_last_swap){ [ident.last] + ident[1..-2] + [ident.first]}
|
22
|
+
|
23
|
+
describe "#reorder!" do
|
24
|
+
context "invalid stop_point_ids" do
|
25
|
+
let( :new_stop_point_ids) { bad_stop_point_ids}
|
26
|
+
it { expect(subject.reorder!( new_stop_point_ids)).to be_falsey}
|
27
|
+
end
|
28
|
+
|
29
|
+
context "swaped last and first stop_point_ids" do
|
30
|
+
let!( :new_stop_point_ids) { first_last_swap}
|
31
|
+
let!( :old_stop_point_ids) { subject.stop_points.map(&:id) }
|
32
|
+
let!( :old_stop_area_ids) { subject.stop_areas.map(&:id) }
|
33
|
+
|
34
|
+
it "should keep stop_point_ids order unchanged" do
|
35
|
+
expect(subject.reorder!( new_stop_point_ids)).to be_truthy
|
36
|
+
expect(subject.stop_points.map(&:id)).to eq( old_stop_point_ids)
|
37
|
+
end
|
38
|
+
it "should have changed stop_area_ids order" do
|
39
|
+
expect(subject.reorder!( new_stop_point_ids)).to be_truthy
|
40
|
+
subject.reload
|
41
|
+
expect(subject.stop_areas.map(&:id)).to eq( [old_stop_area_ids.last] + old_stop_area_ids[1..-2] + [old_stop_area_ids.first])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#stop_point_permutation?" do
|
47
|
+
context "invalid stop_point_ids" do
|
48
|
+
let( :new_stop_point_ids) { bad_stop_point_ids}
|
49
|
+
it { is_expected.not_to be_stop_point_permutation( new_stop_point_ids)}
|
50
|
+
end
|
51
|
+
context "unchanged stop_point_ids" do
|
52
|
+
let( :new_stop_point_ids) { ident}
|
53
|
+
it { is_expected.to be_stop_point_permutation( new_stop_point_ids)}
|
54
|
+
end
|
55
|
+
context "swaped last and first stop_point_ids" do
|
56
|
+
let( :new_stop_point_ids) { first_last_swap}
|
57
|
+
it { is_expected.to be_stop_point_permutation( new_stop_point_ids)}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "#stop_points_attributes=" do
|
63
|
+
let( :journey_pattern) { create( :journey_pattern, :route => subject )}
|
64
|
+
let( :vehicle_journey) { create( :vehicle_journey, :journey_pattern => journey_pattern)}
|
65
|
+
def subject_stop_points_attributes
|
66
|
+
{}.tap do |hash|
|
67
|
+
subject.stop_points.each_with_index { |sp,index| hash[ index.to_s ] = sp.attributes }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "route having swapped a new stop" do
|
71
|
+
let( :new_stop_point ){build( :stop_point, :route => subject)}
|
72
|
+
def added_stop_hash
|
73
|
+
subject_stop_points_attributes.tap do |h|
|
74
|
+
h["4"] = new_stop_point.attributes.merge( "position" => "4", "_destroy" => "" )
|
75
|
+
end
|
76
|
+
end
|
77
|
+
let!( :new_route_size ){ subject.stop_points.size+1 }
|
78
|
+
|
79
|
+
it "should have added stop_point in route" do
|
80
|
+
subject.update_attributes( :stop_points_attributes => added_stop_hash)
|
81
|
+
expect(Chouette::Route.find( subject.id ).stop_points.size).to eq(new_route_size)
|
82
|
+
end
|
83
|
+
it "should have added stop_point in route's journey pattern" do
|
84
|
+
subject.update_attributes( :stop_points_attributes => added_stop_hash)
|
85
|
+
expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.size).to eq(new_route_size)
|
86
|
+
end
|
87
|
+
it "should have added stop_point in route's vehicle journey at stop" do
|
88
|
+
subject.update_attributes( :stop_points_attributes => added_stop_hash)
|
89
|
+
expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.size).to eq(new_route_size)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
context "route having swapped stop" do
|
93
|
+
def swapped_stop_hash
|
94
|
+
subject_stop_points_attributes.tap do |h|
|
95
|
+
h[ "1" ][ "position" ] = "3"
|
96
|
+
h[ "3" ][ "position" ] = "1"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
let!( :new_stop_id_list ){ subject.stop_points.map(&:id).tap {|array| array.insert( 1, array.delete_at(3)); array.insert( 3, array.delete_at(2) )} }
|
100
|
+
|
101
|
+
it "should have swap stop_points from route" do
|
102
|
+
subject.update_attributes( :stop_points_attributes => swapped_stop_hash)
|
103
|
+
expect(Chouette::Route.find( subject.id ).stop_points.map(&:id)).to eq(new_stop_id_list)
|
104
|
+
end
|
105
|
+
it "should have swap stop_points from route's journey pattern" do
|
106
|
+
subject.update_attributes( :stop_points_attributes => swapped_stop_hash)
|
107
|
+
expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.map(&:id)).to eq(new_stop_id_list)
|
108
|
+
end
|
109
|
+
it "should have swap stop_points from route's vehicle journey at stop" do
|
110
|
+
subject.update_attributes( :stop_points_attributes => swapped_stop_hash)
|
111
|
+
expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.map(&:stop_point_id)).to match_array(new_stop_id_list)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context "route having a deleted stop" do
|
115
|
+
def removed_stop_hash
|
116
|
+
subject_stop_points_attributes.tap do |h|
|
117
|
+
h[ "1" ][ "_destroy" ] = "1"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
let!( :new_stop_id_list ){ subject.stop_points.map(&:id).tap {|array| array.delete_at(1) } }
|
121
|
+
|
122
|
+
it "should ignore deleted stop_point from route" do
|
123
|
+
subject.update_attributes( :stop_points_attributes => removed_stop_hash)
|
124
|
+
expect(Chouette::Route.find( subject.id ).stop_points.map(&:id)).to eq(new_stop_id_list)
|
125
|
+
end
|
126
|
+
it "should ignore deleted stop_point from route's journey pattern" do
|
127
|
+
subject.update_attributes( :stop_points_attributes => removed_stop_hash)
|
128
|
+
expect(Chouette::JourneyPattern.find( journey_pattern.id ).stop_points.map(&:id)).to eq(new_stop_id_list)
|
129
|
+
end
|
130
|
+
it "should ignore deleted stop_point from route's vehicle journey at stop" do
|
131
|
+
subject.update_attributes( :stop_points_attributes => removed_stop_hash)
|
132
|
+
expect(Chouette::VehicleJourney.find( vehicle_journey.id ).vehicle_journey_at_stops.map(&:stop_point_id)).to match_array(new_stop_id_list)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#stop_points" do
|
138
|
+
context "#find_by_stop_area" do
|
139
|
+
context "when arg is first quay id" do
|
140
|
+
let(:first_stop_point) { subject.stop_points.first}
|
141
|
+
it "should return first quay" do
|
142
|
+
expect(subject.stop_points.find_by_stop_area( first_stop_point.stop_area_id)).to eq( first_stop_point)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
describe "#stop_areas" do
|
148
|
+
let(:line){ create(:line)}
|
149
|
+
let(:route_1){ create(:route, :line => line)}
|
150
|
+
let(:route_2){ create(:route, :line => line)}
|
151
|
+
it "should retreive all stop_area on route" do
|
152
|
+
route_1.stop_areas.each do |sa|
|
153
|
+
expect(sa.stop_points.map(&:route_id).uniq).to eq([route_1.id])
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "when route is looping: last and first stop area are the same" do
|
158
|
+
it "should retreive same stop_area one last and first position" do
|
159
|
+
route_loop = create(:route, :line => line)
|
160
|
+
first_stop = Chouette::StopPoint.where( :route_id => route_loop.id, :position => 0).first
|
161
|
+
last_stop = create(:stop_point, :route => route_loop, :position => 4, :stop_area => first_stop.stop_area)
|
162
|
+
|
163
|
+
expect(route_loop.stop_areas.size).to eq(6)
|
164
|
+
expect(route_loop.stop_areas.select {|s| s.id == first_stop.stop_area.id}.size).to eq(2)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "#direction_code" do
|
170
|
+
def self.legacy_directions
|
171
|
+
%w{A R ClockWise CounterClockWise North NorthWest West SouthWest
|
172
|
+
South SouthEast East NorthEast}
|
173
|
+
end
|
174
|
+
legacy_directions.each do |direction|
|
175
|
+
context "when direction is #{direction}" do
|
176
|
+
direction_code = Chouette::Direction.new( Chouette::Route.direction_binding[ direction])
|
177
|
+
it "should be #{direction_code}" do
|
178
|
+
subject.direction = direction
|
179
|
+
expect(subject.direction_code).to eq(direction_code)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
context "when direction is nil" do
|
184
|
+
it "should be nil" do
|
185
|
+
subject.direction = nil
|
186
|
+
expect(subject.direction_code).to be_nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
describe "#direction_code=" do
|
191
|
+
context "when unknown direction is provided" do
|
192
|
+
it "should change direction to nil" do
|
193
|
+
subject.direction_code = "dummy"
|
194
|
+
expect(subject.direction).to be_nil
|
195
|
+
end
|
196
|
+
end
|
197
|
+
context "when an existing direction (west) is provided" do
|
198
|
+
it "should change direction Direction.west" do
|
199
|
+
subject.direction_code = "west"
|
200
|
+
expect(subject.direction).to eq("West")
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
describe "#wayback_code" do
|
205
|
+
def self.legacy_waybacks
|
206
|
+
%w{A R}
|
207
|
+
end
|
208
|
+
legacy_waybacks.each do |wayback|
|
209
|
+
context "when wayback is #{wayback}" do
|
210
|
+
wayback_code = Chouette::Wayback.new( Chouette::Route.wayback_binding[ wayback])
|
211
|
+
it "should be #{wayback_code}" do
|
212
|
+
subject.wayback = wayback
|
213
|
+
expect(subject.wayback_code).to eq(wayback_code)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
context "when wayback is nil" do
|
218
|
+
it "should be nil" do
|
219
|
+
subject.wayback = nil
|
220
|
+
expect(subject.wayback_code).to be_nil
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
describe "#wayback_code=" do
|
225
|
+
context "when unknown wayback is provided" do
|
226
|
+
it "should change wayback to nil" do
|
227
|
+
subject.wayback_code = "dummy"
|
228
|
+
expect(subject.wayback).to be_nil
|
229
|
+
end
|
230
|
+
end
|
231
|
+
context "when an existing wayback (straight_forward) is provided" do
|
232
|
+
it "should change wayback Wayback.straight_forward" do
|
233
|
+
subject.wayback_code = "straight_forward"
|
234
|
+
expect(subject.wayback).to eq("A")
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|