diff --git a/lib/schked/config.rb b/lib/schked/config.rb index 147a964..77ccd06 100644 --- a/lib/schked/config.rb +++ b/lib/schked/config.rb @@ -4,7 +4,8 @@ module Schked class Config - attr_writer :logger + attr_writer :logger, + :do_not_load_root_schedule def paths @paths ||= [] @@ -18,6 +19,10 @@ def logger @logger ||= Logger.new($stdout).tap { |l| l.level = Logger::INFO } end + def do_not_load_root_schedule? + !!@do_not_load_root_schedule + end + def register_callback(name, &block) callbacks[name] << block end diff --git a/lib/schked/railtie.rb b/lib/schked/railtie.rb index f21a01e..ed665d3 100644 --- a/lib/schked/railtie.rb +++ b/lib/schked/railtie.rb @@ -6,7 +6,10 @@ module Schked class Railtie < Rails::Railtie class PathsConfig def self.call(app) - if (root_schedule = app.root.join("config", "schedule.rb")).exist? + return if Schked.config.do_not_load_root_schedule? + + root_schedule = app.root.join("config", "schedule.rb") + if root_schedule.exist? path = root_schedule.to_s Schked.config.paths << path unless Schked.config.paths.include?(path) end diff --git a/spec/rails/railtie_spec.rb b/spec/rails/railtie_spec.rb index e20e08f..94305b1 100644 --- a/spec/rails/railtie_spec.rb +++ b/spec/rails/railtie_spec.rb @@ -4,7 +4,11 @@ describe Schked::Railtie do describe "schked.config" do - subject(:config) { Schked.config } + let(:config) { Schked::Config.new } + + before do + allow(Schked).to receive(:config).and_return(config) + end context "when by default root schedule doesn't exist" do it { expect(config.paths).to be_empty } @@ -36,6 +40,14 @@ expect(config.paths).to match_array([schedule_path]) end end + + context "when passed do_not_load_root_schedule config option" do + before { config.do_not_load_root_schedule = true } + + it "doesn't add root schedule to paths" do + expect(config.paths).to be_empty + end + end end end end