Skip to content

Commit

Permalink
Allow Noticed to work with PostGIS ActiveRecord adapter (#150)
Browse files Browse the repository at this point in the history
We use [activerecord-postgis-adapter][1] in one of our applications,
which for all intents and purposes is a superset of the default
ActiveRecord `postgres` adapter.

Because Noticed explicitly checks whether the ActiveRecord adapter
name matches `postgres`, our automatic deletion of notifications for
deleted records using `has_noticed_notifications` no longer works.

- Add `postgis` as an equal alternative to `postgres` when checking
  for adapters in `has_noticed_notifications`
- Fix a tiny spelling mistake

[1]: https://github.com/rgeo/activerecord-postgis-adapter
  • Loading branch information
csutter committed Sep 17, 2021
1 parent f74fbaf commit 9a68ac8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/noticed/has_notifications.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Noticed
module HasNotifications
# Defines a method for the association and a before_destory callback to remove notifications
# Defines a method for the association and a before_destroy callback to remove notifications
# where this record is a param
#
# class User < ApplicationRecord
Expand All @@ -18,7 +18,7 @@ def has_noticed_notifications(param_name: model_name.singular, **options)
define_method "notifications_as_#{param_name}" do
model = options.fetch(:model_name, "Notification").constantize
case current_adapter
when "postgresql"
when "postgresql", "postgis"
model.where("params @> ?", Noticed::Coder.dump(param_name.to_sym => self).to_json)
when "mysql2"
model.where("JSON_CONTAINS(params, ?)", Noticed::Coder.dump(param_name.to_sym => self).to_json)
Expand Down

0 comments on commit 9a68ac8

Please sign in to comment.