ninoxe 0.1.1 → 0.1.2
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.
- data/app/models/chouette/time_table.rb +74 -22
- data/app/models/chouette/vehicle_journey.rb +2 -5
- data/db/migrate/20130410063411_add_shortcut_to_time_table.rb +6 -0
- data/db/migrate/20130410100706_set_shortcut_to_existing_time_table.rb +10 -0
- data/db/migrate/20130410143542_resize_chouette_columns.rb +5 -0
- data/lib/factories/chouette_time_table.rb +1 -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} +0 -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/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 +222 -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/group_of_line_spec.rb +31 -0
- data/spec/models/chouette/journey_pattern_spec.rb +62 -0
- data/spec/models/chouette/line_spec.rb +106 -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 +159 -0
- data/spec/models/chouette/stop_area_spec.rb +382 -0
- data/spec/models/chouette/stop_point_spec.rb +39 -0
- data/spec/models/chouette/time_table_spec.rb +350 -0
- data/spec/models/chouette/transport_mode_spec.rb +64 -0
- data/spec/models/chouette/vehicle_journey_at_stop_spec.rb +46 -0
- data/spec/models/chouette/vehicle_journey_spec.rb +204 -0
- data/spec/spec_helper.rb +62 -0
- metadata +445 -272
- data/db/migrate/20130204141720_add_foreign_keys.rb~ +0 -277
- data/lib/ninoxe.rb~ +0 -7
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::StopPoint do
|
4
|
+
let!(:vehicle_journey) { Factory(:vehicle_journey)}
|
5
|
+
subject { Chouette::Route.find( vehicle_journey.route_id).stop_points.first }
|
6
|
+
|
7
|
+
it { should validate_uniqueness_of :objectid }
|
8
|
+
it { should validate_presence_of :stop_area }
|
9
|
+
it { should validate_presence_of :route }
|
10
|
+
|
11
|
+
its(:objectid) { should be_kind_of(Chouette::ObjectId) }
|
12
|
+
|
13
|
+
describe "#destroy" do
|
14
|
+
before(:each) do
|
15
|
+
@vehicle = Factory(:vehicle_journey)
|
16
|
+
@stop_point = Chouette::Route.find( @vehicle.route_id).stop_points.first
|
17
|
+
end
|
18
|
+
def vjas_stop_point_ids( vehicle_id)
|
19
|
+
Chouette::VehicleJourney.find( vehicle_id).vehicle_journey_at_stops.map(&:stop_point_id)
|
20
|
+
end
|
21
|
+
def jpsp_stop_point_ids( journey_id)
|
22
|
+
Chouette::JourneyPattern.find( journey_id).stop_points.map(&:id)
|
23
|
+
end
|
24
|
+
it "should remove dependent vehicle_journey_at_stop" do
|
25
|
+
vjas_stop_point_ids(@vehicle.id).should include(@stop_point.id)
|
26
|
+
|
27
|
+
@stop_point.destroy
|
28
|
+
|
29
|
+
vjas_stop_point_ids(@vehicle.id).should_not include(@stop_point.id)
|
30
|
+
end
|
31
|
+
it "should remove dependent journey_pattern_stop_point" do
|
32
|
+
jpsp_stop_point_ids(@vehicle.journey_pattern_id).should include(@stop_point.id)
|
33
|
+
|
34
|
+
@stop_point.destroy
|
35
|
+
|
36
|
+
jpsp_stop_point_ids(@vehicle.journey_pattern_id).should_not include(@stop_point.id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,350 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Chouette::TimeTable do
|
4
|
+
|
5
|
+
subject { Factory(:time_table) }
|
6
|
+
|
7
|
+
it { should validate_presence_of :comment }
|
8
|
+
it { should validate_uniqueness_of :objectid }
|
9
|
+
|
10
|
+
describe "#periods_max_date" do
|
11
|
+
context "when all period extends from 04/10/2013 to 04/15/2013," do
|
12
|
+
before(:each) do
|
13
|
+
p1 = Chouette::TimeTablePeriod.new( :period_start => Date.parse("04/10/2013"), :period_end => Date.parse("04/12/2013"))
|
14
|
+
p2 = Chouette::TimeTablePeriod.new( :period_start => Date.parse("04/13/2013"), :period_end => Date.parse("04/15/2013"))
|
15
|
+
subject.periods = [ p1, p2]
|
16
|
+
subject.save
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should retreive 04/15/2013" do
|
20
|
+
subject.periods_max_date.should == Date.parse("04/15/2013")
|
21
|
+
end
|
22
|
+
context "when day_types select only sunday and saturday," do
|
23
|
+
before(:each) do
|
24
|
+
# jeudi, vendredi
|
25
|
+
subject.update_attributes( :int_day_types => (2**(1+6) + 2**(1+7)))
|
26
|
+
end
|
27
|
+
it "should retreive 04/14/2013" do
|
28
|
+
subject.periods_max_date.should == Date.parse("04/14/2013")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
context "when day_types select only friday," do
|
32
|
+
before(:each) do
|
33
|
+
# jeudi, vendredi
|
34
|
+
subject.update_attributes( :int_day_types => (2**(1+6)))
|
35
|
+
end
|
36
|
+
it "should retreive 04/12/2013" do
|
37
|
+
subject.periods_max_date.should == Date.parse("04/13/2013")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
context "when day_types select only thursday," do
|
41
|
+
before(:each) do
|
42
|
+
# mardi
|
43
|
+
subject.update_attributes( :int_day_types => (2**(1+2)))
|
44
|
+
end
|
45
|
+
it "should retreive 04/12/2013" do
|
46
|
+
# 04/15/2013 is monday !
|
47
|
+
subject.periods_max_date.should be_nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
describe "#periods_min_date" do
|
53
|
+
context "when all period extends from 04/10/2013 to 04/15/2013," do
|
54
|
+
before(:each) do
|
55
|
+
p1 = Chouette::TimeTablePeriod.new( :period_start => Date.parse("04/10/2013"), :period_end => Date.parse("04/12/2013"))
|
56
|
+
p2 = Chouette::TimeTablePeriod.new( :period_start => Date.parse("04/13/2013"), :period_end => Date.parse("04/15/2013"))
|
57
|
+
subject.periods = [ p1, p2]
|
58
|
+
subject.save
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should retreive 04/10/2013" do
|
62
|
+
subject.periods_min_date.should == Date.parse("04/10/2013")
|
63
|
+
end
|
64
|
+
context "when day_types select only tuesday and friday," do
|
65
|
+
before(:each) do
|
66
|
+
# jeudi, vendredi
|
67
|
+
subject.update_attributes( :int_day_types => (2**(1+4) + 2**(1+5)))
|
68
|
+
end
|
69
|
+
it "should retreive 04/11/2013" do
|
70
|
+
subject.periods_min_date.should == Date.parse("04/11/2013")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
context "when day_types select only friday," do
|
74
|
+
before(:each) do
|
75
|
+
# jeudi, vendredi
|
76
|
+
subject.update_attributes( :int_day_types => (2**(1+5)))
|
77
|
+
end
|
78
|
+
it "should retreive 04/12/2013" do
|
79
|
+
subject.periods_min_date.should == Date.parse("04/12/2013")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
context "when day_types select only thursday," do
|
83
|
+
before(:each) do
|
84
|
+
# mardi
|
85
|
+
subject.update_attributes( :int_day_types => (2**(1+2)))
|
86
|
+
end
|
87
|
+
it "should retreive 04/12/2013" do
|
88
|
+
# 04/15/2013 is monday !
|
89
|
+
subject.periods_min_date.should be_nil
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
describe "#periods.build" do
|
95
|
+
it "should add a new instance of period, and periods_max_date should not raise error" do
|
96
|
+
period = subject.periods.build
|
97
|
+
subject.periods_max_date
|
98
|
+
period.period_start.should be_nil
|
99
|
+
period.period_end.should be_nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
describe "#periods" do
|
103
|
+
context "when a period is added," do
|
104
|
+
before(:each) do
|
105
|
+
subject.periods << Chouette::TimeTablePeriod.new( :period_start => (subject.bounding_dates.min - 1), :period_end => (subject.bounding_dates.max + 1))
|
106
|
+
subject.save
|
107
|
+
end
|
108
|
+
it "should update shortcut" do
|
109
|
+
subject.start_date.should == subject.bounding_dates.min
|
110
|
+
subject.end_date.should == subject.bounding_dates.max
|
111
|
+
end
|
112
|
+
end
|
113
|
+
context "when a period is removed," do
|
114
|
+
before(:each) do
|
115
|
+
subject.dates = []
|
116
|
+
subject.periods = []
|
117
|
+
subject.periods << Chouette::TimeTablePeriod.new(
|
118
|
+
:period_start => 4.days.since.to_date,
|
119
|
+
:period_end => 6.days.since.to_date)
|
120
|
+
subject.periods << Chouette::TimeTablePeriod.new(
|
121
|
+
:period_start => 1.days.since.to_date,
|
122
|
+
:period_end => 10.days.since.to_date)
|
123
|
+
subject.save
|
124
|
+
subject.periods = subject.periods - [subject.periods.last]
|
125
|
+
end
|
126
|
+
def read_tm
|
127
|
+
Chouette::TimeTable.find subject.id
|
128
|
+
end
|
129
|
+
it "should update shortcut" do
|
130
|
+
tm = read_tm
|
131
|
+
subject.start_date.should == subject.bounding_dates.min
|
132
|
+
subject.start_date.should == tm.bounding_dates.min
|
133
|
+
subject.start_date.should == 4.days.since.to_date
|
134
|
+
subject.end_date.should == subject.bounding_dates.max
|
135
|
+
subject.end_date.should == tm.bounding_dates.max
|
136
|
+
subject.end_date.should == 6.days.since.to_date
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
describe "#dates" do
|
141
|
+
context "when a date is added," do
|
142
|
+
before(:each) do
|
143
|
+
subject.dates << Chouette::TimeTableDate.new( :date => (subject.bounding_dates.max + 1))
|
144
|
+
subject.save
|
145
|
+
end
|
146
|
+
it "should update shortcut" do
|
147
|
+
subject.start_date.should == subject.bounding_dates.min
|
148
|
+
subject.end_date.should == subject.bounding_dates.max
|
149
|
+
end
|
150
|
+
end
|
151
|
+
context "when a date is removed," do
|
152
|
+
before(:each) do
|
153
|
+
subject.periods = []
|
154
|
+
subject.dates = subject.dates - [subject.bounding_dates.max + 1]
|
155
|
+
end
|
156
|
+
it "should update shortcut" do
|
157
|
+
subject.start_date.should == subject.bounding_dates.min
|
158
|
+
subject.end_date.should == subject.bounding_dates.max
|
159
|
+
end
|
160
|
+
end
|
161
|
+
context "when all the dates and periods are removed," do
|
162
|
+
before(:each) do
|
163
|
+
subject.periods = []
|
164
|
+
subject.dates = []
|
165
|
+
end
|
166
|
+
it "should update shortcut" do
|
167
|
+
subject.start_date.should be_nil
|
168
|
+
subject.end_date.should be_nil
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "#valid_days" do
|
174
|
+
it "should begin with position 0" do
|
175
|
+
subject.int_day_types = 128
|
176
|
+
subject.valid_days.should == [6]
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "#include_day?" do
|
181
|
+
it "should return true if a date equal day" do
|
182
|
+
time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1")
|
183
|
+
time_table_date = Factory(:time_table_date, :date => Date.today, :time_table_id => time_table.id)
|
184
|
+
time_table.include_day?(Date.today).should == true
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should return true if a period include day" do
|
188
|
+
time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1")
|
189
|
+
time_table_period = Factory(:time_table_period, :period_start => Date.yesterday,:period_end => Date.tomorrow, :time_table_id => time_table.id)
|
190
|
+
time_table.include_day?(Date.today).should == true
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe "#include_in_dates?" do
|
195
|
+
it "should return true if a date equal day" do
|
196
|
+
time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1")
|
197
|
+
time_table_date = Factory(:time_table_date, :date => Date.today, :time_table_id => time_table.id)
|
198
|
+
time_table.include_in_dates?(Date.today).should == true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "#include_in_periods?" do
|
203
|
+
it "should return true if a period include day" do
|
204
|
+
time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1", :int_day_types => 4)
|
205
|
+
time_table_period = Factory(:time_table_period, :period_start => Date.new(2012, 1, 1),:period_end => Date.new(2012, 01, 30), :time_table_id => time_table.id)
|
206
|
+
time_table.include_in_periods?(Date.new(2012, 1, 2)).should == true
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "#include_in_overlap_dates?" do
|
211
|
+
it "should return true if a day is included in overlap dates" do
|
212
|
+
time_table = Chouette::TimeTable.create!(:comment => "Test", :objectid => "test:Timetable:1", :int_day_types => 4)
|
213
|
+
time_table_period = Factory(:time_table_period, :period_start => Date.new(2012, 1, 1),:period_end => Date.new(2012, 01, 30), :time_table_id => time_table.id)
|
214
|
+
time_table_date = Factory(:time_table_date, :date => Date.new(2012, 1, 2), :time_table_id => time_table.id)
|
215
|
+
time_table.include_in_overlap_dates?(Date.new(2012, 1, 2)).should == true
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe "#dates" do
|
220
|
+
it "should have with position 0" do
|
221
|
+
subject.dates.first.position.should == 0
|
222
|
+
end
|
223
|
+
context "when first date has been removed" do
|
224
|
+
before do
|
225
|
+
subject.dates.first.destroy
|
226
|
+
end
|
227
|
+
it "should begin with position 0" do
|
228
|
+
subject.dates.first.position.should == 0
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
describe "#validity_out_between?" do
|
233
|
+
let(:empty_tm) {Factory.build(:time_table)}
|
234
|
+
it "should be false if empty calendar" do
|
235
|
+
empty_tm.validity_out_between?( Date.today, Date.today + 7.day).should be_false
|
236
|
+
end
|
237
|
+
it "should be true if caldendar is out during start_date and end_date period" do
|
238
|
+
start_date = subject.bounding_dates.max - 2.day
|
239
|
+
end_date = subject.bounding_dates.max + 2.day
|
240
|
+
subject.validity_out_between?( start_date, end_date).should be_true
|
241
|
+
end
|
242
|
+
it "should be false if calendar is out on start date" do
|
243
|
+
start_date = subject.bounding_dates.max
|
244
|
+
end_date = subject.bounding_dates.max + 2.day
|
245
|
+
subject.validity_out_between?( start_date, end_date).should be_false
|
246
|
+
end
|
247
|
+
it "should be false if calendar is out on end date" do
|
248
|
+
start_date = subject.bounding_dates.max - 2.day
|
249
|
+
end_date = subject.bounding_dates.max
|
250
|
+
subject.validity_out_between?( start_date, end_date).should be_true
|
251
|
+
end
|
252
|
+
it "should be false if calendar is out after start_date" do
|
253
|
+
start_date = subject.bounding_dates.max + 2.day
|
254
|
+
end_date = subject.bounding_dates.max + 4.day
|
255
|
+
subject.validity_out_between?( start_date, end_date).should be_false
|
256
|
+
end
|
257
|
+
end
|
258
|
+
describe "#validity_out_from_on?" do
|
259
|
+
let(:empty_tm) {Factory.build(:time_table)}
|
260
|
+
it "should be false if empty calendar" do
|
261
|
+
empty_tm.validity_out_from_on?( Date.today).should be_false
|
262
|
+
end
|
263
|
+
it "should be true if caldendar ends on expected date" do
|
264
|
+
expected_date = subject.bounding_dates.max
|
265
|
+
subject.validity_out_from_on?( expected_date).should be_true
|
266
|
+
end
|
267
|
+
it "should be true if calendar ends before expected date" do
|
268
|
+
expected_date = subject.bounding_dates.max + 30.day
|
269
|
+
subject.validity_out_from_on?( expected_date).should be_true
|
270
|
+
end
|
271
|
+
it "should be false if calendars ends after expected date" do
|
272
|
+
expected_date = subject.bounding_dates.max - 30.day
|
273
|
+
subject.validity_out_from_on?( expected_date).should be_false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
describe "#bounding_dates" do
|
277
|
+
context "when timetable contains only periods" do
|
278
|
+
before do
|
279
|
+
subject.dates = []
|
280
|
+
subject.save
|
281
|
+
end
|
282
|
+
it "should retreive periods.period_start.min and periods.period_end.max" do
|
283
|
+
subject.bounding_dates.min.should == subject.periods.map(&:period_start).min
|
284
|
+
subject.bounding_dates.max.should == subject.periods.map(&:period_end).max
|
285
|
+
end
|
286
|
+
end
|
287
|
+
context "when timetable contains only dates" do
|
288
|
+
before do
|
289
|
+
subject.periods = []
|
290
|
+
subject.save
|
291
|
+
end
|
292
|
+
it "should retreive dates.min and dates.max" do
|
293
|
+
subject.bounding_dates.min.should == subject.dates.map(&:date).min
|
294
|
+
subject.bounding_dates.max.should == subject.dates.map(&:date).max
|
295
|
+
end
|
296
|
+
end
|
297
|
+
it "should contains min date" do
|
298
|
+
min_date = subject.bounding_dates.min
|
299
|
+
subject.dates.each do |tm_date|
|
300
|
+
(min_date <= tm_date.date).should be_true
|
301
|
+
end
|
302
|
+
subject.periods.each do |tm_period|
|
303
|
+
(min_date <= tm_period.period_start).should be_true
|
304
|
+
end
|
305
|
+
|
306
|
+
end
|
307
|
+
it "should contains max date" do
|
308
|
+
max_date = subject.bounding_dates.max
|
309
|
+
subject.dates.each do |tm_date|
|
310
|
+
(tm_date.date <= max_date).should be_true
|
311
|
+
end
|
312
|
+
subject.periods.each do |tm_period|
|
313
|
+
(tm_period.period_end <= max_date).should be_true
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
317
|
+
end
|
318
|
+
describe "#periods" do
|
319
|
+
it "should begin with position 0" do
|
320
|
+
subject.periods.first.position.should == 0
|
321
|
+
end
|
322
|
+
context "when first period has been removed" do
|
323
|
+
before do
|
324
|
+
subject.periods.first.destroy
|
325
|
+
end
|
326
|
+
it "should begin with position 0" do
|
327
|
+
subject.periods.first.position.should == 0
|
328
|
+
end
|
329
|
+
end
|
330
|
+
it "should have period_start before period_end" do
|
331
|
+
period = Chouette::TimeTablePeriod.new
|
332
|
+
period.period_start = Date.today
|
333
|
+
period.period_end = Date.today + 10
|
334
|
+
period.valid?.should be_true
|
335
|
+
end
|
336
|
+
it "should not have period_start after period_end" do
|
337
|
+
period = Chouette::TimeTablePeriod.new
|
338
|
+
period.period_start = Date.today
|
339
|
+
period.period_end = Date.today - 10
|
340
|
+
period.valid?.should be_false
|
341
|
+
end
|
342
|
+
it "should not have period_start equal to period_end" do
|
343
|
+
period = Chouette::TimeTablePeriod.new
|
344
|
+
period.period_start = Date.today
|
345
|
+
period.period_end = Date.today
|
346
|
+
period.valid?.should be_false
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
end
|
@@ -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,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
|