spec/scheduling_spec.rb in delayed_cron-0.2.8 vs spec/scheduling_spec.rb in delayed_cron-0.2.9
- old
+ new
@@ -33,10 +33,41 @@
it "does not change options if `at` is not present" do
expect(DelayedCron.parse_options(no_at)).to eq(no_at)
end
end
+ describe ".add_interval" do
+ it 'adds an interval key and value to the options hash' do
+ options = DelayedCron.add_interval(at: '12:00:00 -0500')
+ expect(options).to include(:interval)
+ end
+ end
+
+ describe ".convert_time_string_to_seconds_interval" do
+ let(:next_occurrence) do
+ DelayedCron.convert_time_string_to_seconds_interval(scheduled_time)
+ end
+ # Set Time.now to January 1, 2014 12:00:00 PM
+ before { Timecop.freeze(Time.local(2014, 1, 1, 12, 0, 0)) }
+ context "next occurrence is today" do
+ let(:known_interval) { 3600 }
+ let(:scheduled_time) { "13:00:00 -0500" }
+ it "converts a time string to seconds" do
+ expect(next_occurrence).to be(known_interval)
+ end
+ end
+
+ context "next occurrence is tomorrow" do
+ let(:known_interval) { 82800 }
+ let(:scheduled_time) { "11:00:00 -0500" }
+ it "converts a time string to seconds" do
+ expect(next_occurrence).to be(known_interval)
+ end
+ end
+
+ end
+
describe ".timing_opts" do
let(:options) do
{ interval: 1.day, at: "05:00:00 -0400" }
end
@@ -44,30 +75,9 @@
it "collects the timing options" do
interval = { interval: 1.day }
timing_opts = DelayedCron.timing_opts(options[:interval], options[:at])
expect(timing_opts).to eq(options)
expect(timing_opts).not_to eq(interval)
- end
- end
-
- describe ".beginning_of_day" do
- it "returns the beginning of the day for the interval" do
- seconds = 2.days.to_i
- beginning_of_day_2_days_from_now = DelayedCron.beginning_of_day(seconds)
- expect(beginning_of_day_2_days_from_now).to be < 2.days.from_now
- expect(beginning_of_day_2_days_from_now).to be > 1.day.from_now
- end
- end
-
- describe ".adjust_interval" do
- it "adjusts the interval based on the :at option" do
- # Set Time.now to January 1, 2014 12:00:00 PM
- Timecop.freeze(Time.local(2014, 1, 1, 12, 0, 0))
- interval = 9.days
- adjusted_interval = interval - 12.hours
- expect(DelayedCron.processor).to receive(:enqueue_delayed_cron)
- .with("SomeClass", "long_method", { interval: adjusted_interval.to_i, at: "00:00" })
- DelayedCron.schedule("SomeClass", "long_method", { interval: interval, at: "00:00" })
end
end
end