From 72fd54c38b958d0be9d608a676e8fef84691d088 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 14 May 2018 18:42:59 +0200 Subject: CleanUp: Add `#run_methods` This method is coupled with a new virtual attribute that can be used in the initializer like: CleanUp.new(methods: [:destroy_routes]) The method will run all methods specified in the `:methods` list. The plan is to replace the calls to `destroy_routes` etc. with a call to this method. The result will be a more configurable clean-up process, allowing users to selectively choose what to clean up by declaring what methods in the `CleanUp` model to call. Refs #6854 --- spec/models/clean_up_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec') 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 -- cgit v1.2.3