From ceec2e53425f8a1c726f4903d03e268386cb598e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 15 May 2018 15:24:29 +0200 Subject: CleanUp: Add `#destroy_empty` 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 --- app/models/clean_up.rb | 6 ++++++ spec/models/clean_up_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+) 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) } -- cgit v1.2.3