Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Christmas snowflakes #509

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'holiday_calendar'

module ApplicationHelper
# Example: charset: 'utf-8'
def default_meta_tags
Expand Down
6 changes: 6 additions & 0 deletions app/views/home/_xmas.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% if HolidayCalendar.new(Date.current).xmas? %>
<script src="https://unpkg.com/magic-snowflakes/dist/snowflakes.min.js"></script>
<script>
new Snowflakes();
</script>
<% end %>
1 change: 1 addition & 0 deletions app/views/home/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@
= render 'contact_forms/contact'
.col-md-8.col-sm-12
= render 'contact_forms/form', contact_form: @home.contact
= render 'xmas'
17 changes: 17 additions & 0 deletions lib/holiday_calendar.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions spec/lib/holiday_calendar_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading