activity_notification 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +41 -5
  3. data/CHANGELOG.md +20 -0
  4. data/Gemfile +4 -1
  5. data/Gemfile.lock +81 -70
  6. data/README.md +152 -12
  7. data/activity_notification.gemspec +6 -4
  8. data/gemfiles/Gemfile.rails-4.2.lock +27 -22
  9. data/gemfiles/Gemfile.rails-5.0.lock +26 -21
  10. data/gemfiles/Gemfile.rails-5.1 +15 -0
  11. data/gemfiles/Gemfile.rails-5.1.lock +229 -0
  12. data/lib/activity_notification/apis/notification_api.rb +2 -2
  13. data/lib/activity_notification/apis/subscription_api.rb +7 -7
  14. data/lib/activity_notification/controllers/common_controller.rb +2 -2
  15. data/lib/activity_notification/helpers/view_helpers.rb +1 -1
  16. data/lib/activity_notification/models/concerns/notifiable.rb +19 -1
  17. data/lib/activity_notification/models/concerns/target.rb +5 -3
  18. data/lib/activity_notification/orm/active_record/notification.rb +3 -1
  19. data/lib/activity_notification/orm/active_record/subscription.rb +3 -1
  20. data/lib/activity_notification/orm/mongoid.rb +2 -2
  21. data/lib/activity_notification/renderable.rb +1 -1
  22. data/lib/activity_notification/roles/acts_as_notifiable.rb +98 -17
  23. data/lib/activity_notification/version.rb +1 -1
  24. data/spec/concerns/apis/notification_api_spec.rb +9 -8
  25. data/spec/concerns/apis/subscription_api_spec.rb +28 -28
  26. data/spec/concerns/models/notifier_spec.rb +1 -1
  27. data/spec/concerns/models/subscriber_spec.rb +7 -7
  28. data/spec/concerns/models/target_spec.rb +20 -20
  29. data/spec/controllers/notifications_controller_shared_examples.rb +19 -8
  30. data/spec/controllers/subscriptions_controller_shared_examples.rb +16 -5
  31. data/spec/models/notification_spec.rb +4 -4
  32. data/spec/models/subscription_spec.rb +16 -12
  33. data/spec/rails_app/app/controllers/articles_controller.rb +1 -1
  34. data/spec/rails_app/app/controllers/comments_controller.rb +0 -1
  35. data/spec/rails_app/app/models/admin.rb +29 -8
  36. data/spec/rails_app/app/models/article.rb +45 -13
  37. data/spec/rails_app/app/models/comment.rb +107 -42
  38. data/spec/rails_app/app/models/user.rb +45 -12
  39. data/spec/rails_app/app/views/layouts/_header.html.erb +1 -0
  40. data/spec/rails_app/config/database.yml +26 -15
  41. data/spec/rails_app/config/initializers/devise.rb +5 -1
  42. data/spec/rails_app/db/migrate/20160715050420_create_activity_notification_tables.rb +1 -1
  43. data/spec/rails_app/db/migrate/20160715050433_create_test_tables.rb +1 -1
  44. data/spec/rails_app/db/seeds.rb +31 -8
  45. data/spec/roles/acts_as_notifiable_spec.rb +154 -1
  46. data/spec/spec_helper.rb +7 -2
  47. metadata +47 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e179e93cf2ac56df97de6634905fa1167b46ed6c
4
- data.tar.gz: 1ee6aa961fcaf36d1b57d51b6eb984b4994c0b1a
3
+ metadata.gz: 88318797860ba42ece844a7e4b34152b3ea640a7
4
+ data.tar.gz: b7ba3947ed5473862f6f804eeff88e0e259f3e60
5
5
  SHA512:
6
- metadata.gz: 013879fc731c40a053424a7a1910602f551baf17f200fbdd297458dbf45d3d8dd09c4eed978096ae9939da7b76bd8233ec860cd1a56d6d3f3f7cdbe1072ddb1a
7
- data.tar.gz: 46afc218dd6ee8feded9f54acfc0819a9fb60ab956bd5e80f83aa9975f3b9b9d92bbaa221a3d427d023ebbae6401a9d0c622cf8838a97d279ee86cd881b77826
6
+ metadata.gz: c215def478cbd3ecc909fc3e24cf7bf803dc6e5342893bfd14b2c987ef72b28a147e73b0871b775a59acb738ba2324522f97abd1e7ea448d7862303def127800
7
+ data.tar.gz: 0b84b958c2a507ce739a73a3f8afc76e7525b810ddd953e2d78a298e445ef1ee653754c2e38bbfbad11157fe0e24803c7a6fa42da0f339fa46c61df021bf9e9b
data/.travis.yml CHANGED
@@ -13,8 +13,9 @@ rvm:
13
13
 
14
14
  gemfile:
15
15
  - Gemfile
16
- - gemfiles/Gemfile.rails-5.0
17
16
  - gemfiles/Gemfile.rails-4.2
17
+ - gemfiles/Gemfile.rails-5.0
18
+ - gemfiles/Gemfile.rails-5.1
18
19
 
19
20
  env:
20
21
  - AN_ORM=active_record
@@ -22,12 +23,44 @@ env:
22
23
 
23
24
  matrix:
24
25
  exclude:
26
+ - rvm: 2.1.10
27
+ gemfile: Gemfile
25
28
  - rvm: 2.1.10
26
29
  gemfile: gemfiles/Gemfile.rails-5.0
27
30
  - rvm: 2.1.10
28
- gemfile: Gemfile
29
- - env: AN_ORM=mongoid
30
- gemfile: Gemfile
31
+ gemfile: gemfiles/Gemfile.rails-5.1
32
+ - rvm: ruby-head
33
+ env: AN_ORM=mongoid
34
+ - gemfile: Gemfile
35
+ env: AN_ORM=mongoid
36
+ include:
37
+ - rvm: 2.4.1
38
+ gemfile: gemfiles/Gemfile.rails-4.2
39
+ env: AN_ORM=active_record AN_TEST_DB=mysql
40
+ - rvm: 2.4.1
41
+ gemfile: gemfiles/Gemfile.rails-4.2
42
+ env: AN_ORM=active_record AN_TEST_DB=postgresql
43
+ - rvm: 2.4.1
44
+ gemfile: gemfiles/Gemfile.rails-4.2
45
+ env: AN_ORM=mongoid AN_TEST_DB=mongodb
46
+ - rvm: 2.4.1
47
+ gemfile: gemfiles/Gemfile.rails-5.0
48
+ env: AN_ORM=active_record AN_TEST_DB=mysql
49
+ - rvm: 2.4.1
50
+ gemfile: gemfiles/Gemfile.rails-5.0
51
+ env: AN_ORM=active_record AN_TEST_DB=postgresql
52
+ - rvm: 2.4.1
53
+ gemfile: gemfiles/Gemfile.rails-5.0
54
+ env: AN_ORM=mongoid AN_TEST_DB=mongodb
55
+ - rvm: 2.4.1
56
+ gemfile: gemfiles/Gemfile.rails-5.1
57
+ env: AN_ORM=active_record AN_TEST_DB=mysql
58
+ - rvm: 2.4.1
59
+ gemfile: gemfiles/Gemfile.rails-5.1
60
+ env: AN_ORM=active_record AN_TEST_DB=postgresql
61
+ - rvm: 2.4.1
62
+ gemfile: gemfiles/Gemfile.rails-5.1
63
+ env: AN_ORM=mongoid AN_TEST_DB=mongodb
31
64
  allow_failures:
32
65
  - rvm: ruby-head
33
66
  fast_finish: true
@@ -41,7 +74,10 @@ cache: bundler
41
74
 
42
75
  before_install: "rm ${BUNDLE_GEMFILE}.lock"
43
76
 
44
- before_script: "bundle update"
77
+ before_script:
78
+ - bundle update
79
+ - mysql -e 'create database activity_notification_test'
80
+ - psql -c 'create database activity_notification_test' -U postgres
45
81
 
46
82
  script: bundle exec rspec
47
83
 
data/CHANGELOG.md CHANGED
@@ -1,7 +1,26 @@
1
+ ## 1.4.0 / 2017-05-10
2
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.3.0...v1.4.0)
3
+
4
+ Enhancements:
5
+
6
+ * Allow use with Rails 5.1
7
+ * Allow mongoid models as `Target` and `Notifiable` models
8
+ * Add functions for automatic tracked notifications
9
+ * Enable `render_notification_of` view helper method to use `:as_latest_group_member` option
10
+
11
+ Bug Fixes:
12
+
13
+ * Fix illegal ActiveRecord query for MySQL and PostgreSQL database
14
+
15
+ Breaking Changes:
16
+
17
+ * Update type of polymolohic id field in Notification and Subscription from Integer to String
18
+
1
19
  ## 1.3.0 / 2017-04-07
2
20
  [Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.2.1...v1.3.0)
3
21
 
4
22
  Enhancements:
23
+
5
24
  * Suport Mongoid ORM to store `Notification` and `Subscription` records
6
25
  * Separate `Notification` and `Subscription` models into ORMs and make them load from ORM selector
7
26
  * Update query logic in `Notification` and `Subscription` models for Mongoid
@@ -13,6 +32,7 @@ Enhancements:
13
32
  [Full Changelog](http://github.com/simukappu/activity_notification/compare/v1.2.0...v1.2.1)
14
33
 
15
34
  Enhancements:
35
+
16
36
  * Support default Slack optional target with `slack-notifier` 2.0.0
17
37
 
18
38
  Breaking Changes:
data/Gemfile CHANGED
@@ -2,7 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'rails', '~> 5.0'
5
+ gem 'rails', '~> 5.1'
6
+
7
+ #TODO Remove it after devise supporting rails 5.1 is released
8
+ gem 'devise', github: 'plataformatec/devise', ref: '83002017'
6
9
 
7
10
  group :development do
8
11
  gem 'bullet'
data/Gemfile.lock CHANGED
@@ -1,48 +1,60 @@
1
+ GIT
2
+ remote: git://github.com/plataformatec/devise.git
3
+ revision: 83002017ea4761e30796f3b288be9c7d9b870fcd
4
+ ref: 83002017
5
+ specs:
6
+ devise (4.2.1)
7
+ bcrypt (~> 3.0)
8
+ orm_adapter (~> 0.1)
9
+ railties (>= 4.1.0, < 5.2)
10
+ responders
11
+ warden (~> 1.2.3)
12
+
1
13
  PATH
2
14
  remote: .
3
15
  specs:
4
- activity_notification (1.3.0)
16
+ activity_notification (1.4.0)
5
17
  activerecord (>= 4.2.0)
6
18
  i18n (>= 0.5.0)
7
19
  jquery-rails (>= 3.1.1)
8
- railties (>= 4.2.0, < 5.1)
20
+ railties (>= 4.2.0, < 5.2)
9
21
 
10
22
  GEM
11
23
  remote: https://rubygems.org/
12
24
  specs:
13
- actioncable (5.0.2)
14
- actionpack (= 5.0.2)
15
- nio4r (>= 1.2, < 3.0)
25
+ actioncable (5.1.0)
26
+ actionpack (= 5.1.0)
27
+ nio4r (~> 2.0)
16
28
  websocket-driver (~> 0.6.1)
17
- actionmailer (5.0.2)
18
- actionpack (= 5.0.2)
19
- actionview (= 5.0.2)
20
- activejob (= 5.0.2)
29
+ actionmailer (5.1.0)
30
+ actionpack (= 5.1.0)
31
+ actionview (= 5.1.0)
32
+ activejob (= 5.1.0)
21
33
  mail (~> 2.5, >= 2.5.4)
22
34
  rails-dom-testing (~> 2.0)
23
- actionpack (5.0.2)
24
- actionview (= 5.0.2)
25
- activesupport (= 5.0.2)
35
+ actionpack (5.1.0)
36
+ actionview (= 5.1.0)
37
+ activesupport (= 5.1.0)
26
38
  rack (~> 2.0)
27
39
  rack-test (~> 0.6.3)
28
40
  rails-dom-testing (~> 2.0)
29
41
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- actionview (5.0.2)
31
- activesupport (= 5.0.2)
42
+ actionview (5.1.0)
43
+ activesupport (= 5.1.0)
32
44
  builder (~> 3.1)
33
- erubis (~> 2.7.0)
45
+ erubi (~> 1.4)
34
46
  rails-dom-testing (~> 2.0)
35
47
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
- activejob (5.0.2)
37
- activesupport (= 5.0.2)
48
+ activejob (5.1.0)
49
+ activesupport (= 5.1.0)
38
50
  globalid (>= 0.3.6)
39
- activemodel (5.0.2)
40
- activesupport (= 5.0.2)
41
- activerecord (5.0.2)
42
- activemodel (= 5.0.2)
43
- activesupport (= 5.0.2)
44
- arel (~> 7.0)
45
- activesupport (5.0.2)
51
+ activemodel (5.1.0)
52
+ activesupport (= 5.1.0)
53
+ activerecord (5.1.0)
54
+ activemodel (= 5.1.0)
55
+ activesupport (= 5.1.0)
56
+ arel (~> 8.0)
57
+ activesupport (5.1.0)
46
58
  concurrent-ruby (~> 1.0, >= 1.0.2)
47
59
  i18n (~> 0.7)
48
60
  minitest (~> 5.1)
@@ -51,14 +63,14 @@ GEM
51
63
  activesupport (>= 3.0)
52
64
  railties (>= 3.0)
53
65
  rspec-rails (>= 2.2)
54
- arel (7.1.4)
55
- aws-sdk (2.9.1)
56
- aws-sdk-resources (= 2.9.1)
57
- aws-sdk-core (2.9.1)
66
+ arel (8.0.0)
67
+ aws-sdk (2.9.16)
68
+ aws-sdk-resources (= 2.9.16)
69
+ aws-sdk-core (2.9.16)
58
70
  aws-sigv4 (~> 1.0)
59
71
  jmespath (~> 1.0)
60
- aws-sdk-resources (2.9.1)
61
- aws-sdk-core (= 2.9.1)
72
+ aws-sdk-resources (2.9.16)
73
+ aws-sdk-core (= 2.9.16)
62
74
  aws-sigv4 (1.0.0)
63
75
  bcrypt (3.1.11)
64
76
  bson (4.2.1)
@@ -67,72 +79,68 @@ GEM
67
79
  activesupport (>= 3.0.0)
68
80
  uniform_notifier (~> 1.10.0)
69
81
  concurrent-ruby (1.0.5)
70
- coveralls (0.8.20)
82
+ coveralls (0.8.21)
71
83
  json (>= 1.8, < 3)
72
84
  simplecov (~> 0.14.1)
73
85
  term-ansicolor (~> 1.3)
74
86
  thor (~> 0.19.4)
75
87
  tins (~> 1.6)
76
- devise (4.2.1)
77
- bcrypt (~> 3.0)
78
- orm_adapter (~> 0.1)
79
- railties (>= 4.1.0, < 5.1)
80
- responders
81
- warden (~> 1.2.3)
82
88
  diff-lcs (1.3)
83
89
  docile (1.1.5)
84
- dotenv (2.2.0)
85
- dotenv-rails (2.2.0)
86
- dotenv (= 2.2.0)
87
- railties (>= 3.2, < 5.1)
88
- erubis (2.7.0)
90
+ dotenv (2.2.1)
91
+ dotenv-rails (2.2.1)
92
+ dotenv (= 2.2.1)
93
+ railties (>= 3.2, < 5.2)
94
+ erubi (1.6.0)
89
95
  factory_girl (4.8.0)
90
96
  activesupport (>= 3.0.0)
91
97
  factory_girl_rails (4.8.0)
92
98
  factory_girl (~> 4.8.0)
93
99
  railties (>= 3.0.0)
94
- globalid (0.3.7)
95
- activesupport (>= 4.1.0)
100
+ globalid (0.4.0)
101
+ activesupport (>= 4.2.0)
96
102
  i18n (0.8.1)
97
103
  jmespath (1.3.1)
98
104
  jquery-rails (4.3.1)
99
105
  rails-dom-testing (>= 1, < 3)
100
106
  railties (>= 4.2.0)
101
107
  thor (>= 0.14, < 2.0)
102
- json (2.0.3)
108
+ json (2.1.0)
103
109
  loofah (2.0.3)
104
110
  nokogiri (>= 1.5.9)
105
- mail (2.6.4)
111
+ mail (2.6.5)
106
112
  mime-types (>= 1.16, < 4)
107
113
  method_source (0.8.2)
108
114
  mime-types (3.1)
109
115
  mime-types-data (~> 3.2015)
110
116
  mime-types-data (3.2016.0521)
111
117
  mini_portile2 (2.1.0)
112
- minitest (5.10.1)
118
+ minitest (5.10.2)
113
119
  mongo (2.4.1)
114
120
  bson (>= 4.2.1, < 5.0.0)
115
121
  mongoid (6.1.0)
116
122
  activemodel (~> 5.0)
117
123
  mongo (>= 2.4.1, < 3.0.0)
124
+ mysql2 (0.4.6)
118
125
  nio4r (2.0.0)
119
- nokogiri (1.7.1)
126
+ nokogiri (1.7.2)
120
127
  mini_portile2 (~> 2.1.0)
121
128
  orm_adapter (0.5.0)
122
- rack (2.0.1)
129
+ pg (0.20.0)
130
+ rack (2.0.2)
123
131
  rack-test (0.6.3)
124
132
  rack (>= 1.0)
125
- rails (5.0.2)
126
- actioncable (= 5.0.2)
127
- actionmailer (= 5.0.2)
128
- actionpack (= 5.0.2)
129
- actionview (= 5.0.2)
130
- activejob (= 5.0.2)
131
- activemodel (= 5.0.2)
132
- activerecord (= 5.0.2)
133
- activesupport (= 5.0.2)
133
+ rails (5.1.0)
134
+ actioncable (= 5.1.0)
135
+ actionmailer (= 5.1.0)
136
+ actionpack (= 5.1.0)
137
+ actionview (= 5.1.0)
138
+ activejob (= 5.1.0)
139
+ activemodel (= 5.1.0)
140
+ activerecord (= 5.1.0)
141
+ activesupport (= 5.1.0)
134
142
  bundler (>= 1.3.0, < 2.0)
135
- railties (= 5.0.2)
143
+ railties (= 5.1.0)
136
144
  sprockets-rails (>= 2.0.0)
137
145
  rails-controller-testing (1.0.1)
138
146
  actionpack (~> 5.x)
@@ -143,15 +151,16 @@ GEM
143
151
  nokogiri (~> 1.6)
144
152
  rails-html-sanitizer (1.0.3)
145
153
  loofah (~> 2.0)
146
- railties (5.0.2)
147
- actionpack (= 5.0.2)
148
- activesupport (= 5.0.2)
154
+ railties (5.1.0)
155
+ actionpack (= 5.1.0)
156
+ activesupport (= 5.1.0)
149
157
  method_source
150
158
  rake (>= 0.8.7)
151
159
  thor (>= 0.18.1, < 2.0)
152
160
  rake (12.0.0)
153
- responders (2.3.0)
154
- railties (>= 4.2.0, < 5.1)
161
+ responders (2.4.0)
162
+ actionpack (>= 4.2.0, < 5.3)
163
+ railties (>= 4.2.0, < 5.3)
155
164
  rspec-core (3.5.4)
156
165
  rspec-support (~> 3.5.0)
157
166
  rspec-expectations (3.5.0)
@@ -183,7 +192,7 @@ GEM
183
192
  activesupport (>= 4.0)
184
193
  sprockets (>= 3.0.0)
185
194
  sqlite3 (1.3.13)
186
- term-ansicolor (1.5.0)
195
+ term-ansicolor (1.6.0)
187
196
  tins (~> 1.0)
188
197
  thor (0.19.4)
189
198
  thread_safe (0.3.6)
@@ -197,7 +206,7 @@ GEM
197
206
  websocket-driver (0.6.5)
198
207
  websocket-extensions (>= 0.1.0)
199
208
  websocket-extensions (0.1.2)
200
- yard (0.9.8)
209
+ yard (0.9.9)
201
210
  yard-activesupport-concern (0.0.1)
202
211
  yard (>= 0.8)
203
212
 
@@ -210,18 +219,20 @@ DEPENDENCIES
210
219
  aws-sdk (~> 2)
211
220
  bullet
212
221
  coveralls
213
- devise (~> 4.2.1)
222
+ devise!
214
223
  dotenv-rails
215
224
  factory_girl_rails (~> 4.8.0)
216
225
  mongoid (>= 4.0.0)
217
- rails (~> 5.0)
226
+ mysql2 (~> 0.4.6)
227
+ pg (~> 0.20.0)
228
+ rails (~> 5.1)
218
229
  rails-controller-testing
219
- rspec-rails (~> 3.5.1)
230
+ rspec-rails (~> 3.5.2)
220
231
  simplecov (~> 0.14.1)
221
232
  slack-notifier (>= 1.5.1)
222
233
  sqlite3 (~> 1.3.13)
223
234
  timecop
224
- yard (~> 0.9.8)
235
+ yard (~> 0.9.9)
225
236
  yard-activesupport-concern (~> 0.0.1)
226
237
 
227
238
  BUNDLED WITH
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  `activity_notification` provides integrated user activity notifications for Ruby on Rails. You can easily use it to configure multiple notification targets and make activity notifications with notifiable models, like adding comments, responding etc.
12
12
 
13
- `activity_notification` supports Rails 5.0 and 4.2+. Also, it is supported with ActiveRecord and [Mongoid](http://mongoid.org) ORM.
13
+ `activity_notification` supports Rails 4.2+ with ActiveRecord and [Mongoid](http://mongoid.org) ORM. It is tested for MySQL, PostgreSQL, SQLite with ActiveRecord ORM and MongoDB with Mongoid ORM.
14
14
 
15
15
 
16
16
  ## About
@@ -18,8 +18,9 @@
18
18
  `activity_notification` provides following functions:
19
19
  * Notification API (creating notifications, query for notifications and managing notification parameters)
20
20
  * Notification models (stored with ActiveRecord or [Mongoid](http://mongoid.org) ORM)
21
- * Notification controllers (managing open/unopen of notifications, link to notifiable activity page)
21
+ * Notification controllers (managing open/unopen of notifications, providing link to notifiable activity page)
22
22
  * Notification views (presentation of notifications)
23
+ * Automatic tracked notifications (generating notifications along with the lifecycle of notifiable models)
23
24
  * Grouping notifications (grouping like `"Kevin and 7 other users posted comments to this article"`)
24
25
  * Email notification
25
26
  * Batch email notification (event driven or periodical email notification, daily or weekly etc)
@@ -57,6 +58,8 @@
57
58
  - [Configuring controllers](#configuring-controllers)
58
59
  - [Configuring routes](#configuring-routes)
59
60
  - [Creating notifications](#creating-notifications)
61
+ - [Notification API](#notification-api)
62
+ - [Automatic tracked notifications](#automatic-tracked-notifications)
60
63
  - [Displaying notifications](#displaying-notifications)
61
64
  - [Preparing target notifications](#preparing-target-notifications)
62
65
  - [Rendering notifications](#rendering-notifications)
@@ -147,12 +150,28 @@ You need to configure Mongoid in your Rails application for your MongoDB environ
147
150
  Configure your target model (e.g. app/models/user.rb).
148
151
  Add `acts_as_target` configuration to your target model to get notifications.
149
152
 
153
+ ##### Target as ActiveRecord model
154
+
150
155
  ```ruby
151
156
  class User < ActiveRecord::Base
152
157
  # acts_as_target configures your model as ActivityNotification::Target
153
- # with parameters as value or custom methods defined in your model as lambda or symbol
158
+ # with parameters as value or custom methods defined in your model as lambda or symbol.
159
+ # This is an example without any options (default configuration) as the target.
160
+ acts_as_target
161
+ end
162
+ ```
163
+
164
+ ##### Target as Mongoid model
154
165
 
155
- # This is an example without any options (default configuration) as the target
166
+ ```ruby
167
+ require 'mongoid'
168
+ class User
169
+ include Mongoid::Document
170
+ include Mongoid::Timestamps
171
+ include GlobalID::Identification
172
+
173
+ # You need include ActivityNotification::Models except ActiveRecord models
174
+ include ActivityNotification::Models
156
175
  acts_as_target
157
176
  end
158
177
  ```
@@ -162,9 +181,11 @@ end
162
181
  #### Configuring notifiable model
163
182
 
164
183
  Configure your notifiable model (e.g. app/models/comment.rb).
165
- Add `acts_as_notifiable` configuration to your notifiable model representing activity to notify.
184
+ Add `acts_as_notifiable` configuration to your notifiable model representing activity to notify for each of your target model.
166
185
  You have to define notification targets for all notifications from this notifiable model by `:targets` option. Other configurations are options. `:notifiable_path` option is a path to move when the notification is opened by the target user.
167
186
 
187
+ ##### Notifiable as ActiveRecord model
188
+
168
189
  ```ruby
169
190
  class Article < ActiveRecord::Base
170
191
  belongs_to :user
@@ -177,7 +198,8 @@ class Comment < ActiveRecord::Base
177
198
  belongs_to :user
178
199
 
179
200
  # acts_as_notifiable configures your model as ActivityNotification::Notifiable
180
- # with parameters as value or custom methods defined in your model as lambda or symbol
201
+ # with parameters as value or custom methods defined in your model as lambda or symbol.
202
+ # The first argument is the plural symbol name of your target model.
181
203
  acts_as_notifiable :users,
182
204
  # Notification targets as :targets is a necessary option
183
205
  # Set to notify to author and users commented to the article, except comment owner self
@@ -194,6 +216,42 @@ class Comment < ActiveRecord::Base
194
216
  end
195
217
  ```
196
218
 
219
+ ##### Notifiable as Mongoid model
220
+
221
+ ```ruby
222
+ require 'mongoid'
223
+ class Article
224
+ include Mongoid::Document
225
+ include Mongoid::Timestamps
226
+
227
+ belongs_to :user
228
+ has_many :comments, dependent: :destroy
229
+
230
+ def commented_users
231
+ User.where(:id.in => comments.pluck(:user_id))
232
+ end
233
+ end
234
+
235
+ require 'mongoid'
236
+ class Comment
237
+ include Mongoid::Document
238
+ include Mongoid::Timestamps
239
+ include GlobalID::Identification
240
+
241
+ # You need include ActivityNotification::Models except ActiveRecord models
242
+ include ActivityNotification::Models
243
+ acts_as_notifiable :users,
244
+ targets: ->(comment, key) {
245
+ ([comment.article.user] + comment.article.commented_users.to_a - [comment.user]).uniq
246
+ },
247
+ notifiable_path: :article_notifiable_path
248
+
249
+ def article_notifiable_path
250
+ article_path(article)
251
+ end
252
+ end
253
+ ```
254
+
197
255
  ### Configuring views
198
256
 
199
257
  `activity_notification` provides view templates to customize your notification views. The view generator can generate default views for all targets.
@@ -282,6 +340,8 @@ end
282
340
 
283
341
  ### Creating notifications
284
342
 
343
+ #### Notification API
344
+
285
345
  You can trigger notifications by setting all your required parameters and triggering `notify`
286
346
  on the notifiable model, like this:
287
347
 
@@ -295,7 +355,57 @@ Or, you can call public API as `ActivityNotification::Notification.notify`
295
355
  ActivityNotification::Notification.notify :users, @comment, key: "comment.reply"
296
356
  ```
297
357
 
358
+ The first argument is the plural symbol name of your target model, which is configured in notifiable model by `acts_as_notifiable`.
359
+
298
360
  *Hint*: `:key` is a option. Default key `#{notifiable_type}.default` which means `comment.default` will be used without specified key.
361
+ You can override it by `Notifiable#default_notification_key`.
362
+
363
+ #### Automatic tracked notifications
364
+
365
+ You can also generate automatic tracked notifications by `:tracked` option in `acts_as_notifiable`.
366
+ `:tracked` option adds required callbacks to generate notifications for creation and update of the notifiable model.
367
+ Set true to `:tracked` option to generate all tracked notifications, like this:
368
+
369
+ ```ruby
370
+ class Comment < ActiveRecord::Base
371
+ acts_as_notifiable :users,
372
+ targets: ->(comment, key) {
373
+ ([comment.article.user] + comment.article.commented_users.to_a - [comment.user]).uniq
374
+ },
375
+ # Set true to :tracked option to generate automatic tracked notifications.
376
+ # It adds required callbacks to generate notifications for creation and update of the notifiable model.
377
+ tracked: true
378
+ end
379
+ ```
380
+
381
+ Or, set `:only` or `:except` option to generate specified tracked notifications, like this:
382
+
383
+ ```ruby
384
+ class Comment < ActiveRecord::Base
385
+ acts_as_notifiable :users,
386
+ targets: ->(comment, key) {
387
+ ([comment.article.user] + comment.article.commented_users.to_a - [comment.user]).uniq
388
+ },
389
+ # Set { only: [:create] } to :tracked option to generate tracked notifications for creation only.
390
+ # It adds required callbacks to generate notifications for creation of the notifiable model.
391
+ tracked: { only: [:create] }
392
+ end
393
+ ```
394
+
395
+ ```ruby
396
+ class Comment < ActiveRecord::Base
397
+ acts_as_notifiable :users,
398
+ targets: ->(comment, key) {
399
+ ([comment.article.user] + comment.article.commented_users.to_a - [comment.user]).uniq
400
+ },
401
+ # Set { except: [:update] } to :tracked option to generate tracked notifications except update (creation only).
402
+ # It adds required callbacks to generate notifications for creation of the notifiable model.
403
+ tracked: { except: [:update] }
404
+ end
405
+ ```
406
+
407
+ *Hint*: `#{notifiable_type}.create` and `#{notifiable_type}.update` will be used as the key of tracked notifications.
408
+ You can override them by `Notifiable#notification_key_for_tracked_creation` and `Notifiable#notification_key_for_tracked_update`.
299
409
 
300
410
  ### Displaying notifications
301
411
 
@@ -361,7 +471,7 @@ Then, content named `:notification_index` will be prepared and you can use it in
361
471
  Sometimes, it's desirable to pass additional local variables to partials. It can be done this way:
362
472
 
363
473
  ```erb
364
- <%= render_notification(@notification, locals: {friends: current_user.friends}) %>
474
+ <%= render_notification(@notification, locals: { friends: current_user.friends }) %>
365
475
  ```
366
476
 
367
477
  #### Notification views
@@ -626,7 +736,7 @@ This makes all target model subscribers. You can also configure them for each ta
626
736
  class User < ActiveRecord::Base
627
737
  # Example using confirmed_at of devise field
628
738
  # to decide whether activity_notification manages subscriptions of this user
629
- acts_as_target email: :email, email_allowed: :confirmed_at, subscription_allowed: confirmed_at
739
+ acts_as_target email: :email, email_allowed: :confirmed_at, subscription_allowed: :confirmed_at
630
740
  end
631
741
  ```
632
742
 
@@ -786,7 +896,7 @@ class Comment < ActiveRecord::Base
786
896
  require 'activity_notification/optional_targets/amazon_sns'
787
897
  require 'activity_notification/optional_targets/slack'
788
898
  require 'custom_optional_targets/console_output'
789
- acts_as_notifiable :admins, targets: Admin.all,
899
+ acts_as_notifiable :admins, targets: [Admin.first].compact,
790
900
  notifiable_path: :article_notifiable_path,
791
901
  # Set optional target implementation class and initializing parameters
792
902
  optional_targets: {
@@ -839,7 +949,7 @@ Any other options for `Aws::SNS::Client.new` are available as initializing param
839
949
  ```ruby
840
950
  class Comment < ActiveRecord::Base
841
951
  require 'activity_notification/optional_targets/amazon_sns'
842
- acts_as_notifiable :admins, targets: Admin.all,
952
+ acts_as_notifiable :admins, targets: [Admin.first].compact,
843
953
  optional_targets: {
844
954
  ActivityNotification::OptionalTarget::AmazonSNS => { topic_arn: 'arn:aws:sns:XXXXX:XXXXXXXXXXXX:XXXXX' }
845
955
  }
@@ -862,7 +972,7 @@ Any other options for `Slack::Notifier.new` are available as initializing parame
862
972
  ```ruby
863
973
  class Comment < ActiveRecord::Base
864
974
  require 'activity_notification/optional_targets/slack'
865
- acts_as_notifiable :admins, targets: Admin.all,
975
+ acts_as_notifiable :admins, targets: [Admin.first].compact,
866
976
  optional_targets: {
867
977
  ActivityNotification::OptionalTarget::Slack => {
868
978
  webhook_url: 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX',
@@ -912,7 +1022,7 @@ Then, you can configure them to notifiable model by `acts_as_notifiable` like th
912
1022
  ```ruby
913
1023
  class Comment < ActiveRecord::Base
914
1024
  require 'custom_optional_targets/amazon_sns'
915
- acts_as_notifiable :admins, targets: Admin.all,
1025
+ acts_as_notifiable :admins, targets: [Admin.first].compact,
916
1026
  optional_targets: {
917
1027
  CustomOptionalTarget::AmazonSNS => { topic_arn: 'arn:aws:sns:XXXXX:XXXXXXXXXXXX:XXXXX' }
918
1028
  }
@@ -1002,6 +1112,36 @@ $ bin/rails server
1002
1112
  ```
1003
1113
  Then, you can access <http://localhost:3000> for the dummy application.
1004
1114
 
1115
+ ##### Run with your local database
1116
+ As default, dummy Rails application runs with local SQLite database in `spec/rails_app/db/development.sqlite3`.
1117
+ This application supports to run with your local MySQL, PostgreSQL and MongoDB.
1118
+ Set `AN_TEST_DB` environment variable like:
1119
+ ```console
1120
+ $ export AN_TEST_DB=mysql
1121
+ ```
1122
+ for MySQL,
1123
+ ```console
1124
+ $ export AN_TEST_DB=postgresql
1125
+ ```
1126
+ for PostgreSQL, and
1127
+ ```console
1128
+ $ export AN_TEST_DB=mongodb
1129
+ ```
1130
+ for MongoDB. When you set `mongodb` as `AN_TEST_DB`, you have to use `activity_notification` with MongoDB. Also set `AN_ORM` like:
1131
+ ```console
1132
+ $ export AN_ORM=mongoid
1133
+ ```
1134
+
1135
+ Then, configure `spec/rails_app/config/database.yml` or `spec/rails_app/config/mongoid.yml` as your local database.
1136
+ Finally, run database migration, seed data script and the dummy appliation.
1137
+ ```console
1138
+ $ cd spec/rails_app
1139
+ $ # You don't need migration when you use MongoDB only (AN_ORM=mongoid and AN_TEST_DB=mongodb)
1140
+ $ bin/rake db:migrate
1141
+ $ bin/rake db:seed
1142
+ $ bin/rails server
1143
+ ```
1144
+
1005
1145
 
1006
1146
  ## Documentation
1007
1147