diff --git a/.rubocop.yml b/.rubocop.yml index 55fd501..2958b3d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +Metrics/AbcSize: + Max: 20 + Metrics/MethodLength: Max: 20 diff --git a/lib/biz/calculation/active.rb b/lib/biz/calculation/active.rb index 1ed3652..42908be 100644 --- a/lib/biz/calculation/active.rb +++ b/lib/biz/calculation/active.rb @@ -8,7 +8,8 @@ def initialize(schedule, time) end def result - schedule.intervals.any? { |interval| interval.contains?(time) } && + schedule.intervals.any? { |interval| interval.contains?(time) } && + schedule.breaks.none? { |break_| break_.contains?(time) } && schedule.holidays.none? { |holiday| holiday.contains?(time) } end diff --git a/spec/calculation/active_spec.rb b/spec/calculation/active_spec.rb index a70f022..fd2a11d 100644 --- a/spec/calculation/active_spec.rb +++ b/spec/calculation/active_spec.rb @@ -1,11 +1,17 @@ RSpec.describe Biz::Calculation::Active do subject(:calculation) { - described_class.new(schedule(holidays: [Date.new(2006, 1, 4)]), time) + described_class.new( + schedule( + breaks: {Date.new(2006, 1, 3) => {'05:30' => '11:00'}}, + holidays: [Date.new(2006, 1, 4)] + ), + time + ) } describe '#result' do context 'when the time is not contained by an interval' do - context 'and not on a holiday' do + context 'and not on a break nor holiday' do let(:time) { Time.utc(2006, 1, 1, 6) } it 'returns false' do @@ -13,6 +19,14 @@ end end + context 'and on a break' do + let(:time) { Time.utc(2006, 1, 3, 6) } + + it 'returns false' do + expect(calculation.result).to eq false + end + end + context 'and on a holiday' do let(:time) { Time.utc(2006, 1, 4, 6) } @@ -23,7 +37,7 @@ end context 'when the time is contained by an interval' do - context 'and not on a holiday' do + context 'and not on a break nor holiday' do let(:time) { Time.utc(2006, 1, 2, 12) } it 'returns true' do @@ -31,6 +45,14 @@ end end + context 'and on a break' do + let(:time) { Time.utc(2006, 1, 3, 10) } + + it 'returns false' do + expect(calculation.result).to eq false + end + end + context 'and on a holiday' do let(:time) { Time.utc(2006, 1, 4, 12) } diff --git a/spec/schedule_spec.rb b/spec/schedule_spec.rb index 6eb536c..7b1714d 100644 --- a/spec/schedule_spec.rb +++ b/spec/schedule_spec.rb @@ -104,7 +104,7 @@ end context 'when the time is in business hours' do - let(:time) { Time.utc(2006, 1, 2, 10) } + let(:time) { Time.utc(2006, 1, 2, 12) } it 'returns true' do expect(schedule.in_hours?(time)).to eq true @@ -122,7 +122,7 @@ end context 'when the time is in business hours' do - let(:time) { Time.utc(2006, 1, 2, 10) } + let(:time) { Time.utc(2006, 1, 2, 12) } it 'returns true' do expect(schedule.business_hours?(time)).to eq true