diff options
| -rw-r--r-- | app/models/clean_up.rb | 5 | ||||
| -rw-r--r-- | spec/models/clean_up_spec.rb | 20 | 
2 files changed, 25 insertions, 0 deletions
| diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index 0f73e07b2..cf8908263 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -105,6 +105,11 @@ class CleanUp < ApplicationModel      Chouette::VehicleJourney.joins(:route).where(["routes.line_id not in (?)", line_ids]).destroy_all    end +  def destroy_routes_outside_referential +    line_ids = referential.metadatas.pluck(:line_ids).flatten.uniq +    Chouette::Route.where(['line_id not in (?)', line_ids]).destroy_all +  end +    def destroy_vehicle_journeys      Chouette::VehicleJourney.where("id not in (select distinct vehicle_journey_id from time_tables_vehicle_journeys)").destroy_all    end diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb index afd2d8721..cf15ab934 100644 --- a/spec/models/clean_up_spec.rb +++ b/spec/models/clean_up_spec.rb @@ -264,4 +264,24 @@ RSpec.describe CleanUp, :type => :model do        }      end    end + +  describe "#destroy_routes_outside_referential" do +    let(:line_referential) { create(:line_referential) } +    let(:line) { create(:line, line_referential: line_referential) } +    let(:metadata) { create(:referential_metadata, lines: [line]) } +    let(:referential) { create(:workbench_referential, metadatas: [metadata]) } +    let(:cleaner) { create(:clean_up, referential: referential) } + +    it "destroys routes not in the the referential" do +      route = create(:route) + +      cleaner.destroy_routes_outside_referential + +      expect(Chouette::Route.exists?(route.id)).to be false + +      line.routes.each do |route| +        expect(route).not_to be_destroyed +      end +    end +  end  end | 
