{this.props.filters.toggleArrivals &&
--
cgit v1.2.3
From 5ee1bd5730e65575f1a7ea179565231b15ecff39 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 12:31:44 +0200
Subject: vehicle_journey_spec.rb: Fix whitespace
---
spec/models/chouette/vehicle_journey_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 4bca8f488..7ddb82b70 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -284,7 +284,7 @@ describe Chouette::VehicleJourney, :type => :model do
first stop that they make" do
journey_missing_stop = create(:vehicle_journey)
journey_early = create(
- :vehicle_journey,
+ :vehicle_journey,
route: journey_missing_stop.route,
journey_pattern: journey_missing_stop.journey_pattern
)
--
cgit v1.2.3
From 2b7c72e6ac639a8098a99295f5681f44a84859e1 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 12:34:04 +0200
Subject: VehicleJourney.with_stops: Fix SQL style
Match the style from the `joins` call above, quoting the table and
column name, for consistency.
---
app/models/chouette/vehicle_journey.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index c25978ab1..39dcafdeb 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -217,7 +217,7 @@ module Chouette
AND "vehicle_journey_at_stops"."stop_point_id" =
"journey_patterns"."departure_stop_point_id"
')
- .order("vehicle_journey_at_stops.departure_time")
+ .order('"vehicle_journey_at_stops"."departure_time"')
end
end
--
cgit v1.2.3
From ebb4281984bd16bf6ee16fad6d664b7793056d62 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 12:47:36 +0200
Subject: VehicleJourney factory: Move departure & arrival time to transient
attrs
Instead of hard-coding the departure and arrival times of the associated
`VehicleJourneyAtStop`s, put the times in transient attributes so that
they can be changed for tests that need different stop times.
Refs #3370
---
spec/factories/chouette_vehicle_journey.rb | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/spec/factories/chouette_vehicle_journey.rb b/spec/factories/chouette_vehicle_journey.rb
index 9ba660800..452909f23 100644
--- a/spec/factories/chouette_vehicle_journey.rb
+++ b/spec/factories/chouette_vehicle_journey.rb
@@ -11,13 +11,18 @@ FactoryGirl.define do
end
factory :vehicle_journey do
- after(:create) do |vehicle_journey|
+ transient do
+ stop_arrival_time '01:00:00'
+ stop_departure_time '03:00:00'
+ end
+
+ after(:create) do |vehicle_journey, evaluator|
vehicle_journey.journey_pattern.stop_points.each_with_index do |stop_point, index|
vehicle_journey.vehicle_journey_at_stops << create(:vehicle_journey_at_stop,
:vehicle_journey => vehicle_journey,
:stop_point => stop_point,
- :arrival_time => '2000-01-01 01:00:00 UTC',
- :departure_time => '2000-01-01 03:00:00 UTC')
+ :arrival_time => "2000-01-01 #{evaluator.stop_arrival_time} UTC",
+ :departure_time => "2000-01-01 #{evaluator.stop_departure_time} UTC")
end
end
--
cgit v1.2.3
From 0898f39c35f2f853e051269ae0945eafa475d483 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 16:14:41 +0200
Subject: VehicleJourney: Add `.departure_time_between` filter
A new class method that allows a vehicle journey collection to be
filtered by a departure time range.
This will eventually replace the
`VehicleJourneysController#ransack_periode_filter` method, moving the
filter out of Ransack and into this custom code.
The reason we're doing this is because when trying to filter, Ransack
inserts a duplicate `LEFT OUTER JOIN` on "vehicle_journey_at_stops" from
`VehicleJourneysController#collection`.
(`route.vehicle_journeys.with_stops` + the filter causes the duplicate
column error.)
For the moment, this method lives on its own. It needs more work to be
integrated such that we can chain it with the `.with_stops` method. In
particular, we still have the duplicate join problem.
Refs #3370
---
app/models/chouette/vehicle_journey.rb | 21 ++++++++++++++++++
spec/models/chouette/vehicle_journey_spec.rb | 32 ++++++++++++++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 39dcafdeb..5d7ddafd7 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -220,5 +220,26 @@ module Chouette
.order('"vehicle_journey_at_stops"."departure_time"')
end
+ # Example:
+ # .departure_time_between('08:00', '09:45')
+ def self.departure_time_between(start_time, end_time)
+ self
+ .select('DISTINCT "vehicle_journeys".*')
+ .joins('
+ LEFT JOIN "vehicle_journey_at_stops"
+ ON "vehicle_journey_at_stops"."vehicle_journey_id" =
+ "vehicle_journeys"."id"
+ ')
+ .where(
+ %Q(
+ "vehicle_journey_at_stops"."departure_time" >= ?
+ AND "vehicle_journey_at_stops"."departure_time" < ?
+ OR "vehicle_journey_at_stops"."id" IS NULL
+ ),
+ "2000-01-01 #{start_time}:00 UTC",
+ "2000-01-01 #{end_time}:00 UTC"
+ )
+ end
+
end
end
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 7ddb82b70..231cbfaaf 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -310,6 +310,38 @@ describe Chouette::VehicleJourney, :type => :model do
end
end
+ describe ".departure_time_between" do
+ it "selects vehicle journeys whose departure times are between the
+ specified range" do
+ journey_early = create(
+ :vehicle_journey,
+ stop_departure_time: '02:00:00'
+ )
+
+ route = journey_early.route
+ journey_pattern = journey_early.journey_pattern
+
+ journey_middle = create(
+ :vehicle_journey,
+ route: route,
+ journey_pattern: journey_pattern,
+ stop_departure_time: '03:00:00'
+ )
+ journey_late = create(
+ :vehicle_journey,
+ route: route,
+ journey_pattern: journey_pattern,
+ stop_departure_time: '04:00:00'
+ )
+
+ expect(route
+ .vehicle_journeys
+ .departure_time_between('02:30', '03:30')
+ .to_a
+ ).to eq([journey_middle])
+ end
+ end
+
subject { create(:vehicle_journey_odd) }
describe "in_relation_to_a_journey_pattern methods" do
let!(:route) { create(:route)}
--
cgit v1.2.3
From 7bf94bc6e6ce6558252252e68419e89a23213573 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 16:53:00 +0200
Subject: VehicleJourneysController#collection: Integrate
.departure_time_between
Add our custom departure time range filter to the query. We pass the
times sent from the frontend into the query in order to get the correct
vehicle journeys back.
Copied the `if params[:q]` check from `#ransack_periode_filter`, but
added an additional condition on the existence of
`:vehicle_journey_at_stops_departure_time_lteq` instead of blatantly
assuming it's there just because its `..._gteq` counterpart is.
Adding the filter necessitated some modifications to the
`VehicleJourneys.departure_time_between` method. We needed to remove the
`SELECT DISTINCT` and join parts of the query, reducing it to a simple
"where" condition.
These removals were due to the nature of the combination of this method
with `VehicleJourneys.with_stops`. The `.with_stops` method already does
a join on `vehicle_journey_at_stops`, and there's already a `SELECT
DISTINCT` applied to the controller's query.
Made the decision to limit this method's use to this specific use-case,
and thus expect DISTINCT and the necessary join to already be defined on
the `ActiveRecord` query object. We modify the test to implement this
requirement.
Finally, rename `.departure_time_between` to
`.where_departure_time_between` to further indicate that this is a
simple `where` condition, without the required extras.
Refs #3370
---
app/controllers/vehicle_journeys_controller.rb | 10 ++++++++++
app/models/chouette/vehicle_journey.rb | 19 +++++++++++--------
spec/models/chouette/vehicle_journey_spec.rb | 8 +++++++-
3 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index cca75af5b..c78613e99 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -78,6 +78,16 @@ class VehicleJourneysController < ChouetteController
protected
def collection
scope = route.vehicle_journeys.with_stops
+
+ if params[:q] &&
+ params[:q][:vehicle_journey_at_stops_departure_time_gteq] &&
+ params[:q][:vehicle_journey_at_stops_departure_time_lteq]
+ scope = scope.where_departure_time_between(
+ params[:q][:vehicle_journey_at_stops_departure_time_gteq],
+ params[:q][:vehicle_journey_at_stops_departure_time_lteq]
+ )
+ end
+
@q = scope.search filtered_ransack_params
# Fixme 3358
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 5d7ddafd7..0b4db3d9d 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -220,16 +220,19 @@ module Chouette
.order('"vehicle_journey_at_stops"."departure_time"')
end
+ # Requires a SELECT DISTINCT and a join with
+ # "vehicle_journey_at_stops".
+ #
# Example:
- # .departure_time_between('08:00', '09:45')
- def self.departure_time_between(start_time, end_time)
+ # .select('DISTINCT "vehicle_journeys".*')
+ # .joins('
+ # LEFT JOIN "vehicle_journey_at_stops"
+ # ON "vehicle_journey_at_stops"."vehicle_journey_id" =
+ # "vehicle_journeys"."id"
+ # ')
+ # .where_departure_time_between('08:00', '09:45')
+ def self.where_departure_time_between(start_time, end_time)
self
- .select('DISTINCT "vehicle_journeys".*')
- .joins('
- LEFT JOIN "vehicle_journey_at_stops"
- ON "vehicle_journey_at_stops"."vehicle_journey_id" =
- "vehicle_journeys"."id"
- ')
.where(
%Q(
"vehicle_journey_at_stops"."departure_time" >= ?
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 231cbfaaf..caa4af203 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -336,7 +336,13 @@ describe Chouette::VehicleJourney, :type => :model do
expect(route
.vehicle_journeys
- .departure_time_between('02:30', '03:30')
+ .select('DISTINCT "vehicle_journeys".*')
+ .joins('
+ LEFT JOIN "vehicle_journey_at_stops"
+ ON "vehicle_journey_at_stops"."vehicle_journey_id" =
+ "vehicle_journeys"."id"
+ ')
+ .where_departure_time_between('02:30', '03:30')
.to_a
).to eq([journey_middle])
end
--
cgit v1.2.3
From b11e7d792b2c3743ca95f7a2d6d5c7bdc4a39105 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 17:32:09 +0200
Subject: VehicleJourneysController: When filtering departure_time allow nil
stops
There's a `params[:q][:vehicle_journey_without_departure_time]`
parameter coming in from the frontend that's supposed to allow it to
decide whether or not to include vehicle journeys that have nil stops.
Allow this parameter to function for the
`VehicleJourney.where_departure_time_between` method by conditionally
checking an input parameter to determine whether to add the "OR"
condition onto the "WHERE" filter.
Refs #3370
---
app/controllers/vehicle_journeys_controller.rb | 4 +++-
app/models/chouette/vehicle_journey.rb | 12 ++++++++++--
spec/models/chouette/vehicle_journey_spec.rb | 17 +++++++++++++++++
3 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index c78613e99..eebcbb922 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -84,7 +84,9 @@ class VehicleJourneysController < ChouetteController
params[:q][:vehicle_journey_at_stops_departure_time_lteq]
scope = scope.where_departure_time_between(
params[:q][:vehicle_journey_at_stops_departure_time_gteq],
- params[:q][:vehicle_journey_at_stops_departure_time_lteq]
+ params[:q][:vehicle_journey_at_stops_departure_time_lteq],
+ allow_empty:
+ params[:q][:vehicle_journey_without_departure_time] == 'true'
)
end
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 0b4db3d9d..852139625 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -231,13 +231,21 @@ module Chouette
# "vehicle_journeys"."id"
# ')
# .where_departure_time_between('08:00', '09:45')
- def self.where_departure_time_between(start_time, end_time)
+ def self.where_departure_time_between(
+ start_time,
+ end_time,
+ allow_empty: false
+ )
self
.where(
%Q(
"vehicle_journey_at_stops"."departure_time" >= ?
AND "vehicle_journey_at_stops"."departure_time" < ?
- OR "vehicle_journey_at_stops"."id" IS NULL
+ #{
+ if allow_empty
+ 'OR "vehicle_journey_at_stops"."id" IS NULL'
+ end
+ }
),
"2000-01-01 #{start_time}:00 UTC",
"2000-01-01 #{end_time}:00 UTC"
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index caa4af203..7f2305134 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -346,6 +346,23 @@ describe Chouette::VehicleJourney, :type => :model do
.to_a
).to eq([journey_middle])
end
+
+ it "can include vehicle journeys that have nil stops" do
+ journey = create(:vehicle_journey_empty)
+ route = journey.route
+
+ expect(route
+ .vehicle_journeys
+ .select('DISTINCT "vehicle_journeys".*')
+ .joins('
+ LEFT JOIN "vehicle_journey_at_stops"
+ ON "vehicle_journey_at_stops"."vehicle_journey_id" =
+ "vehicle_journeys"."id"
+ ')
+ .where_departure_time_between('02:30', '03:30', allow_empty: true)
+ .to_a
+ ).to eq([journey])
+ end
end
subject { create(:vehicle_journey_odd) }
--
cgit v1.2.3
From 36ebc58343bc82c08672f019b1102c3f49e244fb Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 17:41:03 +0200
Subject: VehicleJourneysController#collection: Restore departure time filter
Handle temporary fixes from 972500267f28f233d5670277c02d43fae5ad8e7b and
1f6fb9c73206f3984d2f942d5d16fb9c094b2164. Restore the JavaScript because
that should function the same way now.
Remove the Ransack call as we've moved this departure time filter
outside of Ransack and into our own custom method in order to eliminate
a duplicated "JOIN" call on "vehicle_journey_at_stops" collision between
the `.with_stops` query and Ransack. The new filter lives in
`VehicleJourney.where_departure_time_between`.
Refs #3370
---
.../es6_browserified/vehicle_journeys/reducers/filters.js | 7 +++----
app/controllers/vehicle_journeys_controller.rb | 4 ----
2 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js
index 80b62c6b4..cd065e362 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/reducers/filters.js
@@ -53,10 +53,9 @@ const filters = (state = {}, action) => {
let params = {
'q[journey_pattern_id_eq]': state.query.journeyPattern.id || undefined,
'q[time_tables_id_eq]': state.query.timetable.id || undefined,
- // Fixme 3358
- // 'q[vehicle_journey_at_stops_departure_time_gteq]': (state.query.interval.start.hour + ':' + state.query.interval.start.minute),
- // 'q[vehicle_journey_at_stops_departure_time_lteq]': (state.query.interval.end.hour + ':' + state.query.interval.end.minute),
- // 'q[vehicle_journey_without_departure_time]' : state.query.withoutSchedule
+ 'q[vehicle_journey_at_stops_departure_time_gteq]': (state.query.interval.start.hour + ':' + state.query.interval.start.minute),
+ 'q[vehicle_journey_at_stops_departure_time_lteq]': (state.query.interval.end.hour + ':' + state.query.interval.end.minute),
+ 'q[vehicle_journey_without_departure_time]' : state.query.withoutSchedule
}
let queryString = actions.encodeParams(params)
return _.assign({}, state, {queryString: queryString})
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index eebcbb922..10f0dc324 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -92,10 +92,6 @@ class VehicleJourneysController < ChouetteController
@q = scope.search filtered_ransack_params
- # Fixme 3358
- # grouping = ransack_periode_filter
- # @q.build_grouping(grouping) if grouping
-
@ppage = 20
@vehicle_journeys = @q.result.paginate(:page => params[:page], :per_page => @ppage)
@footnotes = route.line.footnotes.to_json
--
cgit v1.2.3
From 83f143174002ea8d2758d3a3f79fa1b16be9e9eb Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 17:45:14 +0200
Subject: VehicleJourneysController: Remove `#ransack_periode_filter`
This method is superseded by
`VehicleJourney.where_departure_time_between`.
Refs #3370
---
app/controllers/vehicle_journeys_controller.rb | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index 10f0dc324..bf27551fb 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -99,19 +99,6 @@ class VehicleJourneysController < ChouetteController
@vehicle_journeys
end
- def ransack_periode_filter
- if params[:q] && params[:q][:vehicle_journey_at_stops_departure_time_gteq]
- between = [:departure_time_gteq, :departure_time_lteq].map do |filter|
- "2000-01-01 #{params[:q]["vehicle_journey_at_stops_#{filter}"]}:00 UTC"
- end
- {
- :m => 'or',
- :vehicle_journey_at_stops_departure_time_between => between.join(' to '),
- :vehicle_journey_at_stops_id_null => params[:q][:vehicle_journey_without_departure_time]
- }
- end
- end
-
def filtered_ransack_params
if params[:q]
params[:q] = params[:q].reject{|k| params[:q][k] == 'undefined'}
--
cgit v1.2.3
From 19d4f6e53405aa391a01e6340979e3d0d815542a Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 17:47:04 +0200
Subject: VehicleJourneysController: Add a comment on departure time filter
This section is a little dense. Comment what it is to make it more
obvious.
Refs #3370
---
app/controllers/vehicle_journeys_controller.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index bf27551fb..d8cbef478 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -79,6 +79,7 @@ class VehicleJourneysController < ChouetteController
def collection
scope = route.vehicle_journeys.with_stops
+ # Apply departure time range filter
if params[:q] &&
params[:q][:vehicle_journey_at_stops_departure_time_gteq] &&
params[:q][:vehicle_journey_at_stops_departure_time_lteq]
--
cgit v1.2.3
From 8cfb32a40ae3f2c48c6a7884a1a8251ee4a48254 Mon Sep 17 00:00:00 2001
From: Teddy Wing
Date: Fri, 12 May 2017 18:06:51 +0200
Subject: Revert "Fix broken filters vj spec (queries were modified)"
This reverts commit 012a2e5cdcf62d60325a951929850b4e08b24530.
Now that we've fixed the departure time filter on
VehicleJourneysController#index
(7bf94bc6e6ce6558252252e68419e89a23213573) and re-enabled the supporting
JavaScript (36ebc58343bc82c08672f019b1102c3f49e244fb), this temporary
test fix can be reverted.
---
spec/javascripts/vehicle_journeys/reducers/filters_spec.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
index 1dea403cb..d5cdff430 100644
--- a/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
+++ b/spec/javascripts/vehicle_journeys/reducers/filters_spec.js
@@ -144,7 +144,7 @@ describe('filters reducer', () => {
})
it('should handle CREATE_QUERY_STRING', () => {
- let strResult = 'q%5Bjourney_pattern_id_eq%5D=undefined&q%5Btime_tables_id_eq%5D=undefined'
+ let strResult = "q%5Bjourney_pattern_id_eq%5D=undefined&q%5Btime_tables_id_eq%5D=undefined&q%5Bvehicle_journey_at_stops_departure_time_gteq%5D=11%3A11&q%5Bvehicle_journey_at_stops_departure_time_lteq%5D=22%3A22&q%5Bvehicle_journey_without_departure_time%5D=true"
expect(
statusReducer(state, {
type: 'CREATE_QUERY_STRING',
--
cgit v1.2.3
From 2c32ac2a3372dfaee531734d3cf94f6b522b7c1b Mon Sep 17 00:00:00 2001
From: Xinhui
Date: Mon, 15 May 2017 11:32:56 +0200
Subject: Calendar #convert_to_time_tablet
Refs #3372
---
app/models/calendar.rb | 11 +++++++++++
spec/models/calendar_spec.rb | 16 ++++++++++++----
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/app/models/calendar.rb b/app/models/calendar.rb
index 91a17e853..39e0d6d49 100644
--- a/app/models/calendar.rb
+++ b/app/models/calendar.rb
@@ -19,6 +19,17 @@ class Calendar < ActiveRecord::Base
[:contains_date]
end
+ def convert_to_time_table
+ Chouette::TimeTable.new.tap do |tt|
+ self.dates.each do |d|
+ tt.dates << Chouette::TimeTableDate.new(date: d, in_out: true)
+ end
+ self.date_ranges.each do |p|
+ tt.periods << Chouette::TimeTablePeriod.new(period_start: p.begin, period_end: p.end)
+ end
+ end
+ end
+
class Period
include ActiveAttr::Model
diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb
index 36981961f..33d9676cd 100644
--- a/spec/models/calendar_spec.rb
+++ b/spec/models/calendar_spec.rb
@@ -9,6 +9,18 @@ RSpec.describe Calendar, :type => :model do
it { is_expected.to validate_presence_of(:short_name) }
it { is_expected.to validate_uniqueness_of(:short_name) }
+ describe '#to_time_table' do
+ let(:calendar) { create(:calendar, date_ranges: [Date.today..(Date.today + 1.month)]) }
+
+ it 'should convert calendar to an instance of Chouette::TimeTable' do
+ time_table = calendar.convert_to_time_table
+ expect(time_table).to be_an_instance_of(Chouette::TimeTable)
+ expect(time_table.periods[0].period_start).to eq(calendar.date_ranges[0].begin)
+ expect(time_table.periods[0].period_end).to eq(calendar.date_ranges[0].end)
+ expect(time_table.dates.map(&:date)).to match_array(calendar.dates)
+ end
+ end
+
describe 'validations' do
it 'validates that dates and date_ranges do not overlap' do
calendar = build(:calendar, dates: [Date.today], date_ranges: [Date.today..Date.tomorrow])
@@ -69,7 +81,6 @@ RSpec.describe Calendar, :type => :model do
end
describe 'intersect?' do
-
it 'should detect date in common with other date_ranges' do
november = period(begin: '2016-11-01', end: '2016-11-30')
mid_november_mid_december = period(begin: '2016-11-15', end: '2016-12-15')
@@ -111,7 +122,6 @@ RSpec.describe Calendar, :type => :model do
end
describe 'DateValue' do
-
subject { date_value }
def date_value(attributes = {})
@@ -141,8 +151,6 @@ RSpec.describe Calendar, :type => :model do
end
it { is_expected.to validate_presence_of(:value) }
-
end
-
end
--
cgit v1.2.3