diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 21acd275..0cefe871 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'holiday_calendar' + module ApplicationHelper # Example: charset: 'utf-8' def default_meta_tags diff --git a/app/views/home/_xmas.erb b/app/views/home/_xmas.erb new file mode 100644 index 00000000..987366e3 --- /dev/null +++ b/app/views/home/_xmas.erb @@ -0,0 +1,6 @@ +<% if HolidayCalendar.new(Date.current).xmas? %> + + +<% end %> \ No newline at end of file diff --git a/app/views/home/index.slim b/app/views/home/index.slim index 18dc120e..f99407ae 100644 --- a/app/views/home/index.slim +++ b/app/views/home/index.slim @@ -75,3 +75,4 @@ = render 'contact_forms/contact' .col-md-8.col-sm-12 = render 'contact_forms/form', contact_form: @home.contact += render 'xmas' diff --git a/lib/holiday_calendar.rb b/lib/holiday_calendar.rb new file mode 100644 index 00000000..20fa6751 --- /dev/null +++ b/lib/holiday_calendar.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'date' + +class HolidayCalendar + def initialize(date) + @date = date + end + + def xmas? + (date.month == 12) && (24..26).cover?(date.day) + end + + private + + attr_reader :date +end diff --git a/spec/lib/holiday_calendar_spec.rb b/spec/lib/holiday_calendar_spec.rb new file mode 100644 index 00000000..f84115db --- /dev/null +++ b/spec/lib/holiday_calendar_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'holiday_calendar' + +RSpec.describe HolidayCalendar do + describe '#xmas?' do + context 'when date is before Christmas' do + it { expect(described_class.new(Date.new(2023, 12, 23))).not_to be_xmas } + it { expect(described_class.new(Date.new(2024, 1, 1))).not_to be_xmas } + end + + context 'when the date is Christmas or Christmas Eve' do + it { expect(described_class.new(Date.new(2023, 12, 24))).to be_xmas } + it { expect(described_class.new(Date.new(2023, 12, 26))).to be_xmas } + it { expect(described_class.new(Date.new(2024, 12, 25))).to be_xmas } + end + + context 'when date is after Christmas' do + it { expect(described_class.new(Date.new(2023, 12, 27))).not_to be_xmas } + it { expect(described_class.new(Date.new(2024, 12, 31))).not_to be_xmas } + end + end +end