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,204 @@
|
|
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),
|
134
|
+
Factory.build(:time_table_date, :date => 2.days.ago.to_date)])
|
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
|
+
end
|
204
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
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 'database_cleaner'
|
12
|
+
require 'geo_ruby'
|
13
|
+
|
14
|
+
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
15
|
+
|
16
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
17
|
+
# in spec/support/ and its subdirectories.
|
18
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "spec/support/**/*.rb")].each {|f| require f }
|
19
|
+
Dir[File.join(ENGINE_RAILS_ROOT, "lib/factories/**/*.rb")].each {|f| require f }
|
20
|
+
|
21
|
+
RSpec.configure do |config|
|
22
|
+
DatabaseCleaner.logger = Rails.logger
|
23
|
+
# == Mock Framework
|
24
|
+
#
|
25
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
26
|
+
#
|
27
|
+
# config.mock_with :mocha
|
28
|
+
# config.mock_with :flexmock
|
29
|
+
# config.mock_with :rr
|
30
|
+
config.mock_with :rspec
|
31
|
+
|
32
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
33
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
34
|
+
|
35
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
36
|
+
# examples within a transaction, remove the following line or assign false
|
37
|
+
# instead of true.
|
38
|
+
config.use_transactional_fixtures = true
|
39
|
+
|
40
|
+
# If true, the base class of anonymous controllers will be inferred
|
41
|
+
# automatically. This will be the default behavior in future versions of
|
42
|
+
# rspec-rails.
|
43
|
+
config.infer_base_class_for_anonymous_controllers = false
|
44
|
+
|
45
|
+
config.before(:suite) do
|
46
|
+
DatabaseCleaner.strategy = :transaction
|
47
|
+
#DatabaseCleaner.clean_with( :truncation, {:except => %w[spatial_ref_sys geometry_columns]} )
|
48
|
+
|
49
|
+
Chouette::ActiveRecord.logger = Logger.new("log/test.log")
|
50
|
+
end
|
51
|
+
|
52
|
+
config.before(:each) do
|
53
|
+
DatabaseCleaner.start
|
54
|
+
end
|
55
|
+
|
56
|
+
config.after(:each) do
|
57
|
+
DatabaseCleaner.clean
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
|