diff options
| -rw-r--r-- | app/models/clean_up.rb | 8 | ||||
| -rw-r--r-- | spec/models/clean_up_spec.rb | 20 | 
2 files changed, 28 insertions, 0 deletions
| diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb index f668b9fda..4656cdb31 100644 --- a/app/models/clean_up.rb +++ b/app/models/clean_up.rb @@ -16,6 +16,8 @@ class CleanUp < ApplicationModel      where(referential_id: referential.id)    end +  attr_accessor :methods +    def end_date_must_be_greater_that_begin_date      if self.end_date && self.date_type == 'between' && self.begin_date >= self.end_date        errors.add(:base, I18n.t('activerecord.errors.models.clean_up.invalid_period')) @@ -54,6 +56,12 @@ class CleanUp < ApplicationModel      end    end +  def run_methods +    return if methods.nil? + +    methods.each { |method| send(method) } +  end +    def destroy_time_tables_between      time_tables = Chouette::TimeTable.where('end_date < ? AND start_date > ?', self.end_date, self.begin_date)      self.destroy_time_tables(time_tables) diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb index 8a96437fb..f0c3a3233 100644 --- a/spec/models/clean_up_spec.rb +++ b/spec/models/clean_up_spec.rb @@ -296,4 +296,24 @@ RSpec.describe CleanUp, :type => :model do        expect(Chouette::VehicleJourney.exists?(vehicle_journey.id)).to be false      end    end + +  describe "#run_methods" do +    let(:cleaner) { create(:clean_up) } + +    it "calls methods in the :methods attribute" do +      cleaner = create( +        :clean_up, +        methods: [:destroy_routes_outside_referential] +      ) + +      expect(cleaner).to receive(:destroy_routes_outside_referential) +      cleaner.run_methods +    end + +    it "doesn't do anything if :methods is nil" do +      cleaner = create(:clean_up) + +      expect { cleaner.run_methods }.not_to raise_error +    end +  end  end | 
