aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-05-15 15:24:29 +0200
committerTeddy Wing2018-05-15 15:24:29 +0200
commitceec2e53425f8a1c726f4903d03e268386cb598e (patch)
treea77345d0389ba2f3cda8b4d6cb57b37bc99e0c36
parent3667a7d4976a9e69ae990df9ba681f679e0ee4fa (diff)
downloadchouette-core-ceec2e53425f8a1c726f4903d03e268386cb598e.tar.bz2
Gives us a single call site to trigger the destruction of vehicle journeys, journey patterns, and routes without content. This was previously done directly in the `#clean` method, but since it's not needed during referential duplication (only during merges), we don't want to enable it by default. Thus now to activate the same old functionality, you would create a `CleanUp` like this: CleanUp.new(methods: [:destroy_empty]) Refs #6854
-rw-r--r--app/models/clean_up.rb6
-rw-r--r--spec/models/clean_up_spec.rb12
2 files changed, 18 insertions, 0 deletions
diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb
index a708a77ea..9cf2389c9 100644
--- a/app/models/clean_up.rb
+++ b/app/models/clean_up.rb
@@ -124,6 +124,12 @@ class CleanUp < ApplicationModel
Chouette::Route.where("id not in (select distinct route_id from journey_patterns)").destroy_all
end
+ def destroy_empty
+ destroy_vehicle_journeys
+ destroy_journey_patterns
+ destroy_routes
+ end
+
def overlapping_periods
self.end_date = self.begin_date if self.date_type != 'between'
Chouette::TimeTablePeriod.where('(period_start, period_end) OVERLAPS (?, ?)', self.begin_date, self.end_date)
diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb
index f0c3a3233..f39ca2f2b 100644
--- a/spec/models/clean_up_spec.rb
+++ b/spec/models/clean_up_spec.rb
@@ -297,6 +297,18 @@ RSpec.describe CleanUp, :type => :model do
end
end
+ describe "#destroy_empty" do
+ it "calls the appropriate destroy methods" do
+ cleaner = create(:clean_up)
+
+ expect(cleaner).to receive(:destroy_vehicle_journeys)
+ expect(cleaner).to receive(:destroy_journey_patterns)
+ expect(cleaner).to receive(:destroy_routes)
+
+ cleaner.destroy_empty
+ end
+ end
+
describe "#run_methods" do
let(:cleaner) { create(:clean_up) }