Skip to content

Commit

Permalink
add noticed
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Jan 3, 2024
1 parent fc1dc19 commit 46be9f8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,5 @@ gem "image_processing", ">= 1.2"
gem "devise-i18n", "~> 1.10"

gem "dockerfile-rails", ">= 1.5", group: :development

gem "noticed", "~> 1.6"
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ GEM
activerecord (>= 4.2, < 8)
dockerfile-rails (1.5.3)
rails
domain_name (0.6.20231109)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
Expand All @@ -164,6 +165,9 @@ GEM
faker (3.0.0)
i18n (>= 1.8.11, < 2)
ffi (1.15.5)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
formatador (1.1.0)
globalid (1.0.1)
activesupport (>= 5.0)
Expand All @@ -181,6 +185,14 @@ GEM
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
http (5.1.1)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
Expand Down Expand Up @@ -222,6 +234,9 @@ GEM
listen (3.7.1)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -257,6 +272,9 @@ GEM
racc (~> 1.4)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
noticed (1.6.3)
http (>= 4.0.0)
rails (>= 5.2.0)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
Expand Down Expand Up @@ -489,6 +507,7 @@ DEPENDENCIES
kaminari (~> 1.2)
mobility (~> 1.2)
mobility-ransack (~> 1.2.2)
noticed (~> 1.6)
pg (~> 1.1)
puma (~> 6.4)
pundit (~> 2.2)
Expand Down
4 changes: 4 additions & 0 deletions app/models/notification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Notification < ApplicationRecord
include Noticed::Model
belongs_to :recipient, polymorphic: true
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class User < ApplicationRecord
has_many :discussions, dependent: :destroy
has_many :posts, dependent: :destroy
has_one :preference, dependent: :destroy
has_many :notifications, as: :recipient, dependent: :destroy

# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
Expand Down
13 changes: 13 additions & 0 deletions db/migrate/20240102141608_create_notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateNotifications < ActiveRecord::Migration[7.0]
def change
create_table :notifications do |t|
t.references :recipient, polymorphic: true, null: false
t.string :type, null: false
t.jsonb :params
t.datetime :read_at

t.timestamps
end
add_index :notifications, :read_at
end
end
14 changes: 13 additions & 1 deletion db/schema.rb

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

8 changes: 8 additions & 0 deletions spec/factories/notifications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FactoryBot.define do
factory :notification do
recipient factory: :user
type { "" }
params { "" }
read_at { Time.zone.today }
end
end
5 changes: 5 additions & 0 deletions spec/models/notification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe Notification, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit 46be9f8

Please sign in to comment.