Skip to content

Commit

Permalink
errors and flakes
Browse files Browse the repository at this point in the history
  • Loading branch information
compwron committed May 5, 2024
1 parent 7f8465d commit 69c0dca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
after_action :verify_authorized, except: :index, unless: :devise_controller?
# after_action :verify_policy_scoped, only: :index

KNOWN_ERRORS = [Pundit::NotAuthorizedError, Organizational::UnknownOrganization]
rescue_from StandardError, with: :log_and_reraise
rescue_from Pundit::NotAuthorizedError, with: :not_authorized
rescue_from Organizational::UnknownOrganization, with: :not_authorized
Expand Down Expand Up @@ -138,7 +139,9 @@ def not_authorized
end

def log_and_reraise(error)
Bugsnag.notify(error)
unless KNOWN_ERRORS.include?(error.class)
Bugsnag.notify(error)
end
raise
end

Expand Down
21 changes: 13 additions & 8 deletions spec/lib/tasks/volunteer_birthday_reminder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@

RSpec.describe "lib/tasks/volunteer_birthday_reminder.rake" do
let(:rake_task) { Rake::Task["volunteer_birthday_reminder"].invoke }
let(:now) { Date.new(2022, 10, 15) }
let(:this_month) { now.month }
let(:this_month_15th) { Date.new(now.year, now.month, 15) }
let(:next_month) { Date.new(1988, this_month + 1, 1) }
let(:not_next_month) { Date.new(1998, this_month - 1, 1) }

before do
Rake::Task.clear
Casa::Application.load_tasks

travel_to Date.new(2022, 10, 15)
travel_to now
end

after do
Expand All @@ -18,7 +23,7 @@

context "there is a volunteer with a birthday next month" do
let!(:volunteer) do
create(:volunteer, :with_assigned_supervisor, date_of_birth: Date.new(1988, 11, 30))
create(:volunteer, :with_assigned_supervisor, date_of_birth: next_month)
end

it "creates a notification" do
Expand All @@ -29,7 +34,7 @@
context "there are many volunteers with birthdays next month" do
volunteer_count = 10
let!(:volunteer) do
create_list(:volunteer, volunteer_count, :with_assigned_supervisor, date_of_birth: Date.new(1988, 11, 30))
create_list(:volunteer, volunteer_count, :with_assigned_supervisor, date_of_birth: next_month)
end

it "creates many notifications" do
Expand All @@ -39,7 +44,7 @@

context "there is an unsupervised volunteer with a birthday next month" do
let!(:volunteer) do
create(:volunteer, date_of_birth: Date.new(1988, 11, 30))
create(:volunteer, date_of_birth: next_month)
end

it "does not create a notification" do
Expand All @@ -59,7 +64,7 @@

context "there is a volunteer with a birthday that is not next month" do
let!(:volunteer) do
create(:volunteer, :with_assigned_supervisor, date_of_birth: Date.new(1998, 7, 16))
create(:volunteer, :with_assigned_supervisor, date_of_birth: not_next_month)
end

it "does not create a notification" do
Expand All @@ -68,10 +73,10 @@
end

context "when today is the 15th" do
before { travel_to(Date.new(2022, 10, 15)) }
before { travel_to(this_month_15th) }

let!(:volunteer) do
create(:volunteer, :with_assigned_supervisor, date_of_birth: Date.new(1988, 11, 30))
create(:volunteer, :with_assigned_supervisor, date_of_birth: next_month)
end

it "runs the rake task" do
Expand All @@ -80,7 +85,7 @@
end

context "when today is not the 15th" do
before { travel_to(Date.new(2022, 10, 1)) }
before { travel_to(this_month_15th + 2.days) }

it "skips the rake task" do
expect { rake_task }.to change { Notification.count }.by(0)
Expand Down

0 comments on commit 69c0dca

Please sign in to comment.