ninoxe 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/app/models/chouette/footnote.rb +7 -0
- data/app/models/chouette/line.rb +6 -1
- data/app/models/chouette/vehicle_journey.rb +7 -4
- data/db/migrate/20150115153453_create_footnotes.rb +11 -0
- data/db/migrate/20150119160029_create_vehicle_journey_footnotes.rb +8 -0
- data/lib/factories/chouette_footnotes.rb +6 -0
- data/lib/ninoxe/version.rb +1 -1
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +56 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/{config/database.yml.me → spec/dummy/config/database.yml} +2 -2
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/active_record.rb +2 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/schema.rb +485 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/models/chouette/access_link_spec.rb +78 -0
- data/spec/models/chouette/access_point_spec.rb +266 -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 +51 -0
- data/spec/models/chouette/connection_link_spec.rb +56 -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 +62 -0
- data/spec/models/chouette/line_spec.rb +119 -0
- data/spec/models/chouette/loader_spec.rb +69 -0
- data/spec/models/chouette/network_spec.rb +22 -0
- data/spec/models/chouette/object_id_spec.rb +146 -0
- data/spec/models/chouette/route_spec.rb +234 -0
- data/spec/models/chouette/stop_area_spec.rb +440 -0
- data/spec/models/chouette/stop_point_spec.rb +38 -0
- data/spec/models/chouette/time_table_period_spec.rb +66 -0
- data/spec/models/chouette/time_table_spec.rb +1218 -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 +46 -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 +45 -0
- metadata +160 -33
- data/app/models/chouette/time_table_vehicle_journey.rb +0 -5
- data/lib/ninoxe.rb~ +0 -7
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::TransportMode do
|
4
|
+
|
5
|
+
def mode(text_code = "test", numerical_code = nil)
|
6
|
+
numerical_code ||= 1 if text_code == "test"
|
7
|
+
Chouette::TransportMode.new(text_code, numerical_code)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#to_i" do
|
11
|
+
|
12
|
+
it "should return numerical code" do
|
13
|
+
mode("test", 1).to_i.should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return true to #test? when text code is 'test'" do
|
19
|
+
mode("test").should be_test
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be equal when text codes are identical" do
|
23
|
+
mode("test",1).should == mode("test", 2)
|
24
|
+
end
|
25
|
+
|
26
|
+
describe ".new" do
|
27
|
+
|
28
|
+
it "should find numerical code from text code" do
|
29
|
+
mode("unknown").to_i.should == 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should find text code from numerical code" do
|
33
|
+
mode(0).should be_unknown
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should accept another mode" do
|
37
|
+
Chouette::TransportMode.new(mode("test")).should == mode("test")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#public_transport?" do
|
43
|
+
|
44
|
+
it "should return false for interchange" do
|
45
|
+
mode("interchange").should_not be_public_transport
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return true for other modes" do
|
49
|
+
mode("unknown").should be_public_transport
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe ".all" do
|
55
|
+
|
56
|
+
Chouette::TransportMode.definitions.each do |text_code, numerical_code|
|
57
|
+
it "should include a TransportMode #{text_code}" do
|
58
|
+
Chouette::TransportMode.all.should include(Chouette::TransportMode.new(text_code))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::TridentActiveRecord do
|
4
|
+
|
5
|
+
it { Chouette::TridentActiveRecord.ancestors.should include(Chouette::ActiveRecord) }
|
6
|
+
|
7
|
+
subject { Factory(:time_table) }
|
8
|
+
|
9
|
+
describe "#uniq_objectid" do
|
10
|
+
|
11
|
+
it "should rebuild objectid" do
|
12
|
+
tm = Factory(:time_table)
|
13
|
+
tm.objectid = subject.objectid
|
14
|
+
tm.uniq_objectid
|
15
|
+
tm.objectid.should == subject.objectid+"_1"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should rebuild objectid" do
|
19
|
+
tm = Factory(:time_table)
|
20
|
+
tm.objectid = subject.objectid
|
21
|
+
tm.uniq_objectid
|
22
|
+
tm.save
|
23
|
+
tm = Factory(:time_table)
|
24
|
+
tm.objectid = subject.objectid
|
25
|
+
tm.uniq_objectid
|
26
|
+
tm.objectid.should == subject.objectid+"_2"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#prepare_auto_columns" do
|
32
|
+
|
33
|
+
it "should left objectid" do
|
34
|
+
tm = Chouette::TimeTable.new :comment => "merge1" , :objectid => "NINOXE:Timetable:merge1"
|
35
|
+
tm.prepare_auto_columns
|
36
|
+
tm.objectid.should == "NINOXE:Timetable:merge1"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should add pending_id to objectid" do
|
40
|
+
tm = Chouette::TimeTable.new :comment => "merge1"
|
41
|
+
tm.prepare_auto_columns
|
42
|
+
tm.objectid.start_with?("NINOXE:Timetable:__pending_id__").should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set id to objectid" do
|
46
|
+
tm = Chouette::TimeTable.new :comment => "merge1"
|
47
|
+
tm.save
|
48
|
+
tm.objectid.should == "NINOXE:Timetable:"+tm.id.to_s
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should detect objectid conflicts" do
|
52
|
+
tm = Chouette::TimeTable.new :comment => "merge1"
|
53
|
+
tm.save
|
54
|
+
tm.objectid = "NINOXE:Timetable:"+(tm.id+1).to_s
|
55
|
+
tm.save
|
56
|
+
tm = Chouette::TimeTable.new :comment => "merge1"
|
57
|
+
tm.save
|
58
|
+
tm.objectid.should == "NINOXE:Timetable:"+tm.id.to_s+"_1"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "objectid" do
|
64
|
+
|
65
|
+
it "should build automatic objectid when empty" do
|
66
|
+
g1 = Chouette::GroupOfLine.new( :name => "g1")
|
67
|
+
g1.save
|
68
|
+
g1.objectid.should == "NINOXE:GroupOfLine:"+g1.id.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should build automatic objectid with fixed when only suffix given" do
|
72
|
+
g1 = Chouette::GroupOfLine.new( :name => "g1")
|
73
|
+
g1.objectid = "toto"
|
74
|
+
g1.save
|
75
|
+
g1.objectid.should == "NINOXE:GroupOfLine:toto"
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should build automatic objectid with extension when already exists" do
|
79
|
+
g1 = Chouette::GroupOfLine.new( :name => "g1")
|
80
|
+
g1.save
|
81
|
+
cnt = g1.id + 1
|
82
|
+
g1.objectid = "NINOXE:GroupOfLine:"+cnt.to_s
|
83
|
+
g1.save
|
84
|
+
g2 = Chouette::GroupOfLine.new( :name => "g2")
|
85
|
+
g2.save
|
86
|
+
g2.objectid.should == "NINOXE:GroupOfLine:"+g2.id.to_s+"_1"
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should build automatic objectid with extension when already exists" do
|
90
|
+
g1 = Chouette::GroupOfLine.new( :name => "g1")
|
91
|
+
g1.save
|
92
|
+
cnt = g1.id + 2
|
93
|
+
g1.objectid = "NINOXE:GroupOfLine:"+cnt.to_s
|
94
|
+
g1.save
|
95
|
+
g2 = Chouette::GroupOfLine.new( :name => "g2")
|
96
|
+
g2.objectid = "NINOXE:GroupOfLine:"+cnt.to_s+"_1"
|
97
|
+
g2.save
|
98
|
+
g3 = Chouette::GroupOfLine.new( :name => "g3")
|
99
|
+
g3.save
|
100
|
+
g3.objectid.should == "NINOXE:GroupOfLine:"+g3.id.to_s+"_2"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should build automatic objectid when id cleared" do
|
104
|
+
g1 = Chouette::GroupOfLine.new( :name => "g1")
|
105
|
+
g1.objectid = "NINOXE:GroupOfLine:xxxx"
|
106
|
+
g1.save
|
107
|
+
g1.objectid = nil
|
108
|
+
g1.save
|
109
|
+
g1.objectid.should == "NINOXE:GroupOfLine:"+g1.id.to_s
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::VehicleJourneyAtStop do
|
4
|
+
let!(:vehicle_journey){ Factory(:vehicle_journey_odd)}
|
5
|
+
subject { vehicle_journey.vehicle_journey_at_stops.first }
|
6
|
+
|
7
|
+
describe "#exceeds_gap?" do
|
8
|
+
it "should return false if gap < 1.hour" do
|
9
|
+
t1 = 1.minutes.ago
|
10
|
+
t2 = 1.minutes.ago + 3.hour
|
11
|
+
subject.exceeds_gap?(t1, t2).should be_true
|
12
|
+
end
|
13
|
+
it "should return false if gap > 2.hour" do
|
14
|
+
t1 = 1.minutes.ago
|
15
|
+
t2 = 1.minutes.ago + 3.minutes
|
16
|
+
subject.exceeds_gap?(t1, t2).should be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#increasing_times_validate" do
|
21
|
+
let(:vjas1){ vehicle_journey.vehicle_journey_at_stops[0]}
|
22
|
+
let(:vjas2){ vehicle_journey.vehicle_journey_at_stops[1]}
|
23
|
+
context "when vjas#arrival_time exceeds gap" do
|
24
|
+
it "should add errors on arrival_time" do
|
25
|
+
vjas1.arrival_time = vjas2.arrival_time - 3.hour
|
26
|
+
vjas2.increasing_times_validate(vjas1).should be_false
|
27
|
+
vjas2.errors.should_not be_empty
|
28
|
+
vjas2.errors[:arrival_time].should_not be_blank
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "when vjas#departure_time exceeds gap" do
|
32
|
+
it "should add errors on departure_time" do
|
33
|
+
vjas1.departure_time = vjas2.departure_time - 3.hour
|
34
|
+
vjas2.increasing_times_validate(vjas1).should be_false
|
35
|
+
vjas2.errors.should_not be_empty
|
36
|
+
vjas2.errors[:departure_time].should_not be_blank
|
37
|
+
end
|
38
|
+
end
|
39
|
+
context "when vjas does'nt exceed gap" do
|
40
|
+
it "should not add errors" do
|
41
|
+
vjas2.increasing_times_validate(vjas1).should be_true
|
42
|
+
vjas2.errors.should be_empty
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::VehicleJourney do
|
4
|
+
subject { Factory(:vehicle_journey_odd) }
|
5
|
+
|
6
|
+
describe "in_relation_to_a_journey_pattern methods" do
|
7
|
+
let!(:route) { Factory(:route)}
|
8
|
+
let!(:journey_pattern) { Factory(:journey_pattern, :route => route)}
|
9
|
+
let!(:journey_pattern_odd) { Factory(:journey_pattern_odd, :route => route)}
|
10
|
+
let!(:journey_pattern_even) { Factory(:journey_pattern_even, :route => route)}
|
11
|
+
|
12
|
+
context "when vehicle_journey is on odd stop whereas selected journey_pattern is on all stops" do
|
13
|
+
subject { Factory(:vehicle_journey, :route => route, :journey_pattern => journey_pattern_odd)}
|
14
|
+
describe "#extra_stops_in_relation_to_a_journey_pattern" do
|
15
|
+
it "should be empty" do
|
16
|
+
subject.extra_stops_in_relation_to_a_journey_pattern( journey_pattern).should be_empty
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe "#extra_vjas_in_relation_to_a_journey_pattern" do
|
20
|
+
it "should be empty" do
|
21
|
+
subject.extra_vjas_in_relation_to_a_journey_pattern( journey_pattern).should be_empty
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe "#missing_stops_in_relation_to_a_journey_pattern" do
|
25
|
+
it "should return even stops" do
|
26
|
+
result = subject.missing_stops_in_relation_to_a_journey_pattern( journey_pattern)
|
27
|
+
result.should == journey_pattern_even.stop_points
|
28
|
+
end
|
29
|
+
end
|
30
|
+
describe "#update_journey_pattern" do
|
31
|
+
it "should new_record for added vjas" do
|
32
|
+
subject.update_journey_pattern( journey_pattern)
|
33
|
+
subject.vehicle_journey_at_stops.select{ |vjas| vjas.new_record? }.each do |vjas|
|
34
|
+
journey_pattern_even.stop_points.should include( vjas.stop_point)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
it "should add vjas on each even stops" do
|
38
|
+
subject.update_journey_pattern( journey_pattern)
|
39
|
+
vehicle_stops = subject.vehicle_journey_at_stops.map(&:stop_point)
|
40
|
+
journey_pattern_even.stop_points.each do |sp|
|
41
|
+
vehicle_stops.should include(sp)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
it "should not mark any vjas as _destroy" do
|
45
|
+
subject.update_journey_pattern( journey_pattern)
|
46
|
+
subject.vehicle_journey_at_stops.any?{ |vjas| vjas._destroy }.should be_false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
context "when vehicle_journey is on all stops whereas selected journey_pattern is on odd stops" do
|
51
|
+
subject { Factory(:vehicle_journey, :route => route, :journey_pattern => journey_pattern)}
|
52
|
+
describe "#missing_stops_in_relation_to_a_journey_pattern" do
|
53
|
+
it "should be empty" do
|
54
|
+
subject.missing_stops_in_relation_to_a_journey_pattern( journey_pattern_odd).should be_empty
|
55
|
+
end
|
56
|
+
end
|
57
|
+
describe "#extra_stops_in_relation_to_a_journey_pattern" do
|
58
|
+
it "should return even stops" do
|
59
|
+
result = subject.extra_stops_in_relation_to_a_journey_pattern( journey_pattern_odd)
|
60
|
+
result.should == journey_pattern_even.stop_points
|
61
|
+
end
|
62
|
+
end
|
63
|
+
describe "#extra_vjas_in_relation_to_a_journey_pattern" do
|
64
|
+
it "should return vjas on even stops" do
|
65
|
+
result = subject.extra_vjas_in_relation_to_a_journey_pattern( journey_pattern_odd)
|
66
|
+
result.map(&:stop_point).should == journey_pattern_even.stop_points
|
67
|
+
end
|
68
|
+
end
|
69
|
+
describe "#update_journey_pattern" do
|
70
|
+
it "should add no new vjas" do
|
71
|
+
subject.update_journey_pattern( journey_pattern_odd)
|
72
|
+
subject.vehicle_journey_at_stops.any?{ |vjas| vjas.new_record? }.should be_false
|
73
|
+
end
|
74
|
+
it "should mark vehicle_journey_at_stops as _destroy on even stops" do
|
75
|
+
subject.update_journey_pattern( journey_pattern_odd)
|
76
|
+
subject.vehicle_journey_at_stops.each { |vjas|
|
77
|
+
vjas._destroy.should == journey_pattern_even.stop_points.include?(vjas.stop_point)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
context "when following departure times exceeds gap" do
|
85
|
+
describe "#increasing_times" do
|
86
|
+
before(:each) do
|
87
|
+
subject.vehicle_journey_at_stops[0].departure_time = subject.vehicle_journey_at_stops[1].departure_time - 2.hour
|
88
|
+
subject.vehicle_journey_at_stops[0].arrival_time = subject.vehicle_journey_at_stops[0].departure_time
|
89
|
+
subject.vehicle_journey_at_stops[1].arrival_time = subject.vehicle_journey_at_stops[1].departure_time
|
90
|
+
end
|
91
|
+
it "should make instance invalid" do
|
92
|
+
subject.increasing_times
|
93
|
+
subject.vehicle_journey_at_stops[1].errors[:departure_time].should_not be_blank
|
94
|
+
subject.should_not be_valid
|
95
|
+
end
|
96
|
+
end
|
97
|
+
describe "#update_attributes" do
|
98
|
+
let!(:params){ {"vehicle_journey_at_stops_attributes" => {
|
99
|
+
"0"=>{"id" => subject.vehicle_journey_at_stops[0].id ,"arrival_time" => 1.minutes.ago,"departure_time" => 1.minutes.ago},
|
100
|
+
"1"=>{"id" => subject.vehicle_journey_at_stops[1].id, "arrival_time" => (1.minutes.ago + 2.hour),"departure_time" => (1.minutes.ago + 2.hour)}
|
101
|
+
}}}
|
102
|
+
it "should return false" do
|
103
|
+
subject.update_attributes(params).should be_false
|
104
|
+
end
|
105
|
+
it "should make instance invalid" do
|
106
|
+
subject.update_attributes(params)
|
107
|
+
subject.should_not be_valid
|
108
|
+
end
|
109
|
+
it "should let first vjas without any errors" do
|
110
|
+
subject.update_attributes(params)
|
111
|
+
subject.vehicle_journey_at_stops[0].errors.should be_empty
|
112
|
+
end
|
113
|
+
it "should add an error on second vjas" do
|
114
|
+
subject.update_attributes(params)
|
115
|
+
subject.vehicle_journey_at_stops[1].errors[:departure_time].should_not be_blank
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "#time_table_tokens=" do
|
121
|
+
let!(:tm1){Factory(:time_table, :comment => "TM1")}
|
122
|
+
let!(:tm2){Factory(:time_table, :comment => "TM2")}
|
123
|
+
|
124
|
+
it "should return associated time table ids" do
|
125
|
+
subject.update_attributes :time_table_tokens => [tm1.id, tm2.id].join(',')
|
126
|
+
subject.time_tables.should include( tm1)
|
127
|
+
subject.time_tables.should include( tm2)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
describe "#bounding_dates" do
|
131
|
+
before(:each) do
|
132
|
+
tm1 = Factory.build(:time_table, :dates =>
|
133
|
+
[ Factory.build(:time_table_date, :date => 1.days.ago.to_date, :in_out => true),
|
134
|
+
Factory.build(:time_table_date, :date => 2.days.ago.to_date, :in_out => true)])
|
135
|
+
tm2 = Factory.build(:time_table, :periods =>
|
136
|
+
[ Factory.build(:time_table_period, :period_start => 4.days.ago.to_date, :period_end => 3.days.ago.to_date)])
|
137
|
+
tm3 = Factory.build(:time_table)
|
138
|
+
subject.time_tables = [ tm1, tm2, tm3]
|
139
|
+
end
|
140
|
+
it "should return min date from associated calendars" do
|
141
|
+
subject.bounding_dates.min.should == 4.days.ago.to_date
|
142
|
+
end
|
143
|
+
it "should return max date from associated calendars" do
|
144
|
+
subject.bounding_dates.max.should == 1.days.ago.to_date
|
145
|
+
end
|
146
|
+
end
|
147
|
+
context "#vehicle_journey_at_stops" do
|
148
|
+
it "should be ordered like stop_points on route" do
|
149
|
+
route = subject.route
|
150
|
+
vj_stop_ids = subject.vehicle_journey_at_stops.map(&:stop_point_id)
|
151
|
+
expected_order = route.stop_points.map(&:id).select {|s_id| vj_stop_ids.include?(s_id)}
|
152
|
+
|
153
|
+
vj_stop_ids.should == expected_order
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#transport_mode_name" do
|
159
|
+
|
160
|
+
def self.legacy_transport_modes
|
161
|
+
%w{Air Train LongDistanceTrain LocalTrain RapidTransit Metro Tramway Coach Bus Ferry Waterborne PrivateVehicle Walk Trolleybus Bicycle Shuttle Taxi VAL Other}
|
162
|
+
end
|
163
|
+
|
164
|
+
legacy_transport_modes.each do |transport_mode|
|
165
|
+
context "when transport_mode is #{transport_mode}" do
|
166
|
+
transport_mode_name = Chouette::TransportMode.new(transport_mode.underscore)
|
167
|
+
it "should be #{transport_mode_name}" do
|
168
|
+
subject.transport_mode = transport_mode
|
169
|
+
subject.transport_mode_name.should == transport_mode_name
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
context "when transport_mode is nil" do
|
174
|
+
it "should be nil" do
|
175
|
+
subject.transport_mode = nil
|
176
|
+
subject.transport_mode_name.should be_nil
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
describe "#transport_mode_name=" do
|
183
|
+
|
184
|
+
it "should change transport_mode with TransportMode#name" do
|
185
|
+
subject.transport_mode_name = "Test"
|
186
|
+
subject.transport_mode.should == "Test"
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
describe ".transport_mode_names" do
|
192
|
+
|
193
|
+
it "should not include unknown transport_mode_name" do
|
194
|
+
Chouette::VehicleJourney.transport_mode_names.should_not include(Chouette::TransportMode.new("unknown"))
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should not include interchange transport_mode" do
|
198
|
+
Chouette::VehicleJourney.transport_mode_names.should_not include(Chouette::TransportMode.new("interchange"))
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
203
|
+
describe "#footnote_ids=" do
|
204
|
+
context "when line have footnotes, " do
|
205
|
+
let!( :route) { Factory( :route ) }
|
206
|
+
let!( :line) { route.line }
|
207
|
+
let!( :footnote_first) {Factory( :footnote, :code => "1", :label => "dummy 1", :line => route.line)}
|
208
|
+
let!( :footnote_second) {Factory( :footnote, :code => "2", :label => "dummy 2", :line => route.line)}
|
209
|
+
|
210
|
+
|
211
|
+
it "should update vehicle's footnotes" do
|
212
|
+
Chouette::VehicleJourney.find(subject.id).footnotes.should be_empty
|
213
|
+
subject.footnote_ids = [ footnote_first.id ]
|
214
|
+
subject.save
|
215
|
+
Chouette::VehicleJourney.find(subject.id).footnotes.count.should == 1
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::Geometry::LinePresenter do
|
4
|
+
let!(:line) { Factory(:line_with_stop_areas_having_parent) }
|
5
|
+
subject { Chouette::Geometry::LinePresenter.new(line)}
|
6
|
+
|
7
|
+
describe "#routes_localized_commercials" do
|
8
|
+
it "should return 3 stop_areas" do
|
9
|
+
subject.routes_localized_commercials(line.routes.first).size.should == 5
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Configure Rails Envinronment
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
4
|
+
|
5
|
+
require 'rspec/rails'
|
6
|
+
require 'rspec/autorun'
|
7
|
+
|
8
|
+
require 'shoulda-matchers'
|
9
|
+
require 'factory_girl_rails'
|
10
|
+
|
11
|
+
require 'geo_ruby'
|
12
|
+
|
13
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
14
|
+
|
15
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
16
|
+
# in spec/support/ and its subdirectories.
|
17
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
18
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "lib/factories/**/*.rb")].each {|f| require f }
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
# == Mock Framework
|
22
|
+
#
|
23
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
24
|
+
#
|
25
|
+
# config.mock_with :mocha
|
26
|
+
# config.mock_with :flexmock
|
27
|
+
# config.mock_with :rr
|
28
|
+
config.mock_with :rspec
|
29
|
+
|
30
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
31
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
32
|
+
|
33
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
34
|
+
# examples within a transaction, remove the following line or assign false
|
35
|
+
# instead of true.
|
36
|
+
config.use_transactional_fixtures = true
|
37
|
+
|
38
|
+
# If true, the base class of anonymous controllers will be inferred
|
39
|
+
# automatically. This will be the default behavior in future versions of
|
40
|
+
# rspec-rails.
|
41
|
+
config.infer_base_class_for_anonymous_controllers = false
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|