Skip to content
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: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ gem 'omniauth-rails_csrf_protection'
gem 'blazer' # for querying the database

# monitoring & performance
gem 'delayed_job_active_record'
gem 'sentry-rails'
gem 'sentry-ruby'
gem 'skylight' # performance monitoring: https://www.skylight.io/app/applications/670fP418RH7v/recent/6h/endpoints
Expand Down Expand Up @@ -48,6 +47,7 @@ group :development do
# debugging
gem 'better_errors'
gem 'binding_of_caller' # FIX: commands such as continue not work while debugging with binding.pry
gem 'letter_opener' # previews outgoing emails in the browser instead of sending them

# performance
gem 'parity' # CLI commands to simplify integration with Heroku apps (e.g, database sync, deployment, etc)
Expand Down
15 changes: 9 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ GEM
xpath (~> 3.2)
cgi (0.5.1)
chartkick (5.1.0)
childprocess (5.1.0)
logger (~> 1.5)
coderay (1.1.3)
concurrent-ruby (1.3.6)
connection_pool (2.5.5)
Expand All @@ -116,11 +118,6 @@ GEM
irb (~> 1.10)
reline (>= 0.3.8)
debug_inspector (1.2.0)
delayed_job (4.1.11)
activesupport (>= 3.0, < 8.0)
delayed_job_active_record (4.1.8)
activerecord (>= 3.0, < 8.0)
delayed_job (>= 3.0, < 5)
drb (2.2.3)
dry-cli (1.0.0)
erb (6.0.2)
Expand Down Expand Up @@ -169,6 +166,12 @@ GEM
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
launchy (3.1.1)
addressable (~> 2.8)
childprocess (~> 5.0)
logger (~> 1.6)
letter_opener (1.10.0)
launchy (>= 2.2, < 4)
logger (1.6.1)
loofah (2.25.1)
crass (~> 1.0.2)
Expand Down Expand Up @@ -407,12 +410,12 @@ DEPENDENCIES
bootsnap
capybara
debug
delayed_job_active_record
factory_bot_rails
faker
groupdate
heroicon
kaminari
letter_opener
mini_magick
minitest-spec-rails
minitest-stub-const
Expand Down
1 change: 0 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
web: bundle exec puma -C config/puma.rb
release: rake db:migrate
worker: rake jobs:work
3 changes: 1 addition & 2 deletions app/controllers/user/authorization_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ def index
def create
authorization_request = AuthorizationRequest.find_or_create_by!(organization: organization, user: current_user)

# TODO: Move this to a background job. Once we have a background job, we can remove the `if` statement.
if authorization_request.previously_new_record?
organization.users.each do |user|
UserMailer
.with(user: user, authorization_request: authorization_request)
.new_authorization_request
.deliver_later
.deliver_now
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/user/authorizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def send_notifications(authorization)
end

def notify_user(authorization)
UserMailer.with(granted_by_user: current_user, authorization: authorization).authorization_granted.deliver_later
UserMailer.with(granted_by_user: current_user, authorization: authorization).authorization_granted.deliver_now
end

def notify_admin(authorization)
UserMailer.with(granted_by_user: current_user, authorization: authorization).authorization_alert.deliver_later
UserMailer.with(granted_by_user: current_user, authorization: authorization).authorization_alert.deliver_now
end

def clear_related_authorization_requests
Expand Down
9 changes: 0 additions & 9 deletions app/jobs/application_job.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def find_or_create_with_omniauth(auth)
user.update_dynamic_attributes(auth)
report_sign_in(user)
user.save!
UserMailer.with(user: user).welcome.deliver_later if user.new_record? && user.valid? # TODO: why check valid here?
UserMailer.with(user: user).welcome.deliver_now if user.new_record? && user.valid? # TODO: why check valid here?
user
end

Expand Down
6 changes: 0 additions & 6 deletions bin/delayed_job

This file was deleted.

4 changes: 2 additions & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)

# Do not send emails in development
config.action_mailer.perform_deliveries = false
# Preview outgoing emails in the browser via letter_opener (no real SMTP)
config.action_mailer.delivery_method = :letter_opener

# Sets default host for email path and urls
routes.default_url_options[:host] = 'http://localhost:3001'
Expand Down
4 changes: 0 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]

# Use a real queuing backend for Active Job (and separate queues per environment).
config.active_job.queue_adapter = :delayed_job
# config.active_job.queue_name_prefix = "cherry_production"

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
Expand Down
1 change: 0 additions & 1 deletion config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.action_mailer.perform_deliveries = false

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
Expand Down
24 changes: 24 additions & 0 deletions db/migrate/20260420142918_drop_delayed_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class DropDelayedJobs < ActiveRecord::Migration[7.0]
def up
drop_table :delayed_jobs
end

def down
create_table :delayed_jobs do |table|
table.integer :priority, default: 0, null: false
table.integer :attempts, default: 0, null: false
table.text :handler, null: false
table.text :last_error
table.datetime :run_at
table.datetime :locked_at
table.datetime :failed_at
table.string :locked_by
table.string :queue
table.timestamps null: true
end

add_index :delayed_jobs, %i[priority run_at], name: 'delayed_jobs_priority'
end
end
17 changes: 1 addition & 16 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 16 additions & 28 deletions test/controllers/user/authorizations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,40 @@ class User::AuthorizationsControllerTest < ApplicationIntegrationTest
it 'sends email to the user to whom the authorization has been granted' do
Organization.any_instance.stubs(:can_create_new_authorizations?).returns(true)
sign_in(user, controller_test: true)
post(user_authorizations_path(email: 'hello@example.com', organization_id: organization.id), as: :json)
assert_emails(1) do
post(user_authorizations_path(email: 'hello@example.com', organization_id: organization.id), as: :json)
end
assert_response :success

assert_enqueued_email_with(
UserMailer,
:authorization_granted,
params: {
granted_by_user: user,
authorization: Authorization.last
}
)
email = ActionMailer::Base.deliveries.last
assert_equal ['hello@example.com'], email.to
assert_equal 'Cherry - Authorization Granted', email.subject
end

it 'notifies admin about new authorizations' do
Organization.any_instance.stubs(:can_create_new_authorizations?).returns(true)
authorized_user = create :user
Authorization.create!(email: authorized_user.email, organization: organization)
sign_in(authorized_user, controller_test: true)
post(user_authorizations_path(email: 'hello@example.com', organization_id: organization.id), as: :json)
assert_emails(2) do
post(user_authorizations_path(email: 'hello@example.com', organization_id: organization.id), as: :json)
end
assert_response :success

assert_enqueued_email_with(
UserMailer,
:authorization_alert,
params: {
granted_by_user: authorized_user,
authorization: Authorization.last
}
)
alert = ActionMailer::Base.deliveries.find { |e| e.subject == 'Cherry - New Authorization' }
assert_equal [user.email], alert.to
end

it 'does not notify admin when the admin is the creator of the authorization' do
Organization.any_instance.stubs(:can_create_new_authorizations?).returns(true)
sign_in(user, controller_test: true)
post(user_authorizations_path(email: 'hello@example.com', organization_id: organization.id), as: :json)
assert_emails(1) do
post(user_authorizations_path(email: 'hello@example.com', organization_id: organization.id), as: :json)
end
assert_response :success

assert_equal 1, ActiveJob::Base.queue_adapter.enqueued_jobs.count
assert_enqueued_email_with(
UserMailer,
:authorization_granted,
params: {
granted_by_user: user,
authorization: Authorization.last
}
)
email = ActionMailer::Base.deliveries.last
assert_equal 'Cherry - Authorization Granted', email.subject
end
end

Expand Down
Binary file modified test/screenshots/dashboard-with-chart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/screenshots/metric-contributions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion test/tasks/database_cleanup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class DatabaseCleanupTest < ActionMailer::TestCase
it 'deletes older project occurrences' do
assert_equal 4, Occurrence.count
Rake::Task['database:cleanup'].execute
assert_equal 0, Delayed::Job.count
assert_equal 2, Occurrence.count
end
end
Expand Down
Loading