activity_notification 0.0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/Gemfile +6 -3
  4. data/Gemfile.lock +74 -58
  5. data/README.md +53 -26
  6. data/activity_notification.gemspec +2 -0
  7. data/app/controllers/activity_notification/notifications_controller.rb +4 -4
  8. data/app/mailers/activity_notification/mailer.rb +9 -3
  9. data/app/views/activity_notification/mailer/default/default.html.erb +9 -4
  10. data/app/views/activity_notification/mailer/default/default.text.erb +10 -0
  11. data/app/views/activity_notification/notifications/default/_default.html.erb +173 -34
  12. data/app/views/activity_notification/notifications/default/_index.html.erb +119 -11
  13. data/app/views/activity_notification/notifications/default/destroy.js.erb +2 -2
  14. data/app/views/activity_notification/notifications/default/index.html.erb +25 -14
  15. data/app/views/activity_notification/notifications/default/open.js.erb +2 -2
  16. data/app/views/activity_notification/notifications/default/open_all.js.erb +2 -2
  17. data/app/views/activity_notification/notifications/default/show.html.erb +1 -1
  18. data/gemfiles/Gemfile.rails-4.2 +0 -2
  19. data/gemfiles/Gemfile.rails-4.2.lock +3 -3
  20. data/gemfiles/Gemfile.rails-5.0 +1 -3
  21. data/lib/activity_notification.rb +10 -9
  22. data/lib/activity_notification/apis/notification_api.rb +108 -14
  23. data/lib/activity_notification/common.rb +11 -2
  24. data/lib/activity_notification/config.rb +13 -13
  25. data/lib/activity_notification/helpers/view_helpers.rb +26 -4
  26. data/lib/activity_notification/mailers/helpers.rb +8 -4
  27. data/lib/activity_notification/models.rb +4 -0
  28. data/lib/activity_notification/models/concerns/group.rb +32 -0
  29. data/lib/activity_notification/models/concerns/notifiable.rb +60 -32
  30. data/lib/activity_notification/models/concerns/notifier.rb +17 -1
  31. data/lib/activity_notification/models/concerns/target.rb +114 -55
  32. data/lib/activity_notification/models/notification.rb +26 -25
  33. data/lib/activity_notification/rails.rb +1 -0
  34. data/lib/activity_notification/renderable.rb +8 -3
  35. data/lib/activity_notification/roles/acts_as_common.rb +28 -0
  36. data/lib/activity_notification/roles/acts_as_group.rb +38 -0
  37. data/lib/activity_notification/roles/acts_as_notifiable.rb +56 -22
  38. data/lib/activity_notification/roles/acts_as_notifier.rb +25 -2
  39. data/lib/activity_notification/roles/acts_as_target.rb +27 -9
  40. data/lib/activity_notification/version.rb +1 -1
  41. data/lib/generators/templates/activity_notification.rb +1 -1
  42. data/spec/concerns/apis/notification_api_spec.rb +361 -2
  43. data/spec/concerns/common_spec.rb +36 -0
  44. data/spec/concerns/models/group_spec.rb +61 -0
  45. data/spec/concerns/models/notifiable_spec.rb +37 -0
  46. data/spec/concerns/models/notifier_spec.rb +48 -0
  47. data/spec/concerns/models/target_spec.rb +81 -31
  48. data/spec/factories/dummy/dummy_group.rb +4 -0
  49. data/spec/helpers/view_helpers_spec.rb +13 -0
  50. data/spec/mailers/mailer_spec.rb +8 -1
  51. data/spec/models/dummy/dummy_group_spec.rb +6 -0
  52. data/spec/rails_app/app/assets/stylesheets/application.css +15 -0
  53. data/spec/rails_app/app/assets/stylesheets/reset.css +85 -0
  54. data/spec/rails_app/app/assets/stylesheets/style.css +244 -0
  55. data/spec/rails_app/app/controllers/articles_controller.rb +1 -1
  56. data/spec/rails_app/app/models/admin.rb +2 -1
  57. data/spec/rails_app/app/models/article.rb +9 -2
  58. data/spec/rails_app/app/models/comment.rb +8 -2
  59. data/spec/rails_app/app/models/dummy/dummy_group.rb +4 -0
  60. data/spec/rails_app/app/models/user.rb +8 -3
  61. data/spec/rails_app/app/views/articles/_form.html.erb +14 -10
  62. data/spec/rails_app/app/views/articles/edit.html.erb +8 -6
  63. data/spec/rails_app/app/views/articles/index.html.erb +59 -67
  64. data/spec/rails_app/app/views/articles/new.html.erb +7 -5
  65. data/spec/rails_app/app/views/articles/show.html.erb +47 -36
  66. data/spec/rails_app/app/views/layouts/_header.html.erb +36 -9
  67. data/spec/rails_app/app/views/layouts/application.html.erb +8 -6
  68. data/spec/rails_app/config/environments/development.rb +9 -0
  69. data/spec/rails_app/config/initializers/activity_notification.rb +1 -1
  70. data/spec/rails_app/db/schema.rb +14 -20
  71. data/spec/rails_app/db/seeds.rb +5 -5
  72. data/spec/rails_app/lib/mailer_previews/mailer_preview.rb +13 -0
  73. data/spec/roles/acts_as_group_spec.rb +32 -0
  74. data/spec/roles/acts_as_notifiable_spec.rb +1 -1
  75. data/spec/roles/acts_as_notifier_spec.rb +15 -0
  76. data/spec/roles/acts_as_target_spec.rb +1 -1
  77. metadata +52 -2
@@ -6,11 +6,11 @@ Comment.delete_all
6
6
  Article.delete_all
7
7
  Admin.delete_all
8
8
  User.delete_all
9
- User.connection.execute("UPDATE sqlite_sequence SET seq = 0;")
9
+ ActivityNotification::Notification.connection.execute("UPDATE sqlite_sequence SET seq = 0;")
10
10
 
11
- ['ichiro', 'stephen', 'klay'].each do |name|
11
+ ['Ichiro', 'Stephen', 'Klay', 'Kevin'].each do |name|
12
12
  user = User.new(
13
- email: "#{name}@example.com",
13
+ email: "#{name.downcase}@example.com",
14
14
  password: 'changeit',
15
15
  password_confirmation: 'changeit',
16
16
  name: name,
@@ -19,7 +19,7 @@ User.connection.execute("UPDATE sqlite_sequence SET seq = 0;")
19
19
  user.save!
20
20
  end
21
21
 
22
- ['ichiro'].each do |name|
22
+ ['Ichiro'].each do |name|
23
23
  user = User.find_by_name(name)
24
24
  Admin.create(user: user)
25
25
  end
@@ -36,7 +36,7 @@ Article.all.each do |article|
36
36
  User.all.each do |user|
37
37
  comment = article.comments.create(
38
38
  user: user,
39
- body: "This is the first #{user.name}'s comment for #{article.user.name}'s article."
39
+ body: "This is the first #{user.name}'s comment to #{article.user.name}'s article."
40
40
  )
41
41
  comment.notify :users, send_email: false
42
42
  end
@@ -0,0 +1,13 @@
1
+ class ActivityNotification::MailerPreview < ActionMailer::Preview
2
+
3
+ def send_notification_email_single
4
+ target_notification = ActivityNotification::Notification.where(group: nil).first
5
+ ActivityNotification::Mailer.send_notification_email(target_notification)
6
+ end
7
+
8
+ def send_notification_email_with_group
9
+ target_notification = ActivityNotification::Notification.where.not(group: nil).first
10
+ ActivityNotification::Mailer.send_notification_email(target_notification)
11
+ end
12
+
13
+ end
@@ -0,0 +1,32 @@
1
+ describe ActivityNotification::ActsAsGroup do
2
+ let(:dummy_model_class) { Dummy::DummyBase }
3
+
4
+ describe "as public class methods" do
5
+ describe ".acts_as_group" do
6
+ it "have not included Group before calling" do
7
+ expect(dummy_model_class.respond_to?(:available_as_group?)).to be_falsey
8
+ end
9
+
10
+ it "includes Group" do
11
+ dummy_model_class.acts_as_group
12
+ expect(dummy_model_class.respond_to?(:available_as_group?)).to be_truthy
13
+ expect(dummy_model_class.available_as_group?).to be_truthy
14
+ end
15
+
16
+ context "with no options" do
17
+ it "returns hash of specified options" do
18
+ expect(dummy_model_class.acts_as_group).to eq({})
19
+ end
20
+ end
21
+
22
+ #TODO test other options
23
+ end
24
+
25
+ describe ".available_group_options" do
26
+ it "returns list of available options in acts_as_group" do
27
+ expect(dummy_model_class.available_group_options)
28
+ .to eq([:printable_notification_group_name, :printable_name])
29
+ end
30
+ end
31
+ end
32
+ end
@@ -25,7 +25,7 @@ describe ActivityNotification::ActsAsNotifiable do
25
25
  describe ".available_notifiable_options" do
26
26
  it "returns list of available options in acts_as_notifiable" do
27
27
  expect(dummy_model_class.available_notifiable_options)
28
- .to eq([:targets, :group, :notifier, :parameters, :email_allowed, :notifiable_path])
28
+ .to eq([:targets, :group, :notifier, :parameters, :email_allowed, :notifiable_path, :printable_notifiable_name, :printable_name, :dependent_notifications])
29
29
  end
30
30
  end
31
31
  end
@@ -12,6 +12,21 @@ describe ActivityNotification::ActsAsNotifier do
12
12
  expect(dummy_model_class.respond_to?(:available_as_notifier?)).to be_truthy
13
13
  expect(dummy_model_class.available_as_notifier?).to be_truthy
14
14
  end
15
+
16
+ context "with no options" do
17
+ it "returns hash of specified options" do
18
+ expect(dummy_model_class.acts_as_notifier).to eq({})
19
+ end
20
+ end
21
+
22
+ #TODO test other options
23
+ end
24
+
25
+ describe ".available_notifier_options" do
26
+ it "returns list of available options in acts_as_group" do
27
+ expect(dummy_model_class.available_notifier_options)
28
+ .to eq([:printable_notifier_name, :printable_name])
29
+ end
15
30
  end
16
31
  end
17
32
  end
@@ -33,7 +33,7 @@ describe ActivityNotification::ActsAsTarget do
33
33
  describe ".available_target_options" do
34
34
  it "returns list of available options in acts_as_target" do
35
35
  expect(dummy_model_class.available_target_options)
36
- .to eq([:email, :email_allowed, :devise_resource])
36
+ .to eq([:email, :email_allowed, :devise_resource, :printable_notification_target_name, :printable_name])
37
37
  end
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activity_notification
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Yamazaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-11 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -58,6 +58,34 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: 4.2.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: jquery-rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.1.1
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.1.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 1.3.11
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 1.3.11
61
89
  - !ruby/object:Gem::Dependency
62
90
  name: rspec-rails
63
91
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +194,7 @@ files:
166
194
  - app/controllers/activity_notification/notifications_with_devise_controller.rb
167
195
  - app/mailers/activity_notification/mailer.rb
168
196
  - app/views/activity_notification/mailer/default/default.html.erb
197
+ - app/views/activity_notification/mailer/default/default.text.erb
169
198
  - app/views/activity_notification/notifications/default/_default.html.erb
170
199
  - app/views/activity_notification/notifications/default/_index.html.erb
171
200
  - app/views/activity_notification/notifications/default/destroy.js.erb
@@ -186,6 +215,7 @@ files:
186
215
  - lib/activity_notification/helpers/view_helpers.rb
187
216
  - lib/activity_notification/mailers/helpers.rb
188
217
  - lib/activity_notification/models.rb
218
+ - lib/activity_notification/models/concerns/group.rb
189
219
  - lib/activity_notification/models/concerns/notifiable.rb
190
220
  - lib/activity_notification/models/concerns/notifier.rb
191
221
  - lib/activity_notification/models/concerns/target.rb
@@ -193,6 +223,8 @@ files:
193
223
  - lib/activity_notification/rails.rb
194
224
  - lib/activity_notification/rails/routes.rb
195
225
  - lib/activity_notification/renderable.rb
226
+ - lib/activity_notification/roles/acts_as_common.rb
227
+ - lib/activity_notification/roles/acts_as_group.rb
196
228
  - lib/activity_notification/roles/acts_as_notifiable.rb
197
229
  - lib/activity_notification/roles/acts_as_notifier.rb
198
230
  - lib/activity_notification/roles/acts_as_target.rb
@@ -213,6 +245,7 @@ files:
213
245
  - lib/tasks/activity_notification_tasks.rake
214
246
  - spec/concerns/apis/notification_api_spec.rb
215
247
  - spec/concerns/common_spec.rb
248
+ - spec/concerns/models/group_spec.rb
216
249
  - spec/concerns/models/notifiable_spec.rb
217
250
  - spec/concerns/models/notifier_spec.rb
218
251
  - spec/concerns/models/target_spec.rb
@@ -223,6 +256,7 @@ files:
223
256
  - spec/factories/admins.rb
224
257
  - spec/factories/articles.rb
225
258
  - spec/factories/comments.rb
259
+ - spec/factories/dummy/dummy_group.rb
226
260
  - spec/factories/dummy/dummy_notifiable.rb
227
261
  - spec/factories/dummy/dummy_notifier.rb
228
262
  - spec/factories/dummy/dummy_target.rb
@@ -236,12 +270,16 @@ files:
236
270
  - spec/helpers/polymorphic_helpers_spec.rb
237
271
  - spec/helpers/view_helpers_spec.rb
238
272
  - spec/mailers/mailer_spec.rb
273
+ - spec/models/dummy/dummy_group_spec.rb
239
274
  - spec/models/dummy/dummy_notifiable_spec.rb
240
275
  - spec/models/dummy/dummy_notifier_spec.rb
241
276
  - spec/models/dummy/dummy_target_spec.rb
242
277
  - spec/models/notification_spec.rb
243
278
  - spec/rails_app/Rakefile
244
279
  - spec/rails_app/app/assets/javascripts/application.js
280
+ - spec/rails_app/app/assets/stylesheets/application.css
281
+ - spec/rails_app/app/assets/stylesheets/reset.css
282
+ - spec/rails_app/app/assets/stylesheets/style.css
245
283
  - spec/rails_app/app/controllers/application_controller.rb
246
284
  - spec/rails_app/app/controllers/articles_controller.rb
247
285
  - spec/rails_app/app/controllers/comments_controller.rb
@@ -253,6 +291,7 @@ files:
253
291
  - spec/rails_app/app/models/article.rb
254
292
  - spec/rails_app/app/models/comment.rb
255
293
  - spec/rails_app/app/models/dummy/dummy_base.rb
294
+ - spec/rails_app/app/models/dummy/dummy_group.rb
256
295
  - spec/rails_app/app/models/dummy/dummy_notifiable.rb
257
296
  - spec/rails_app/app/models/dummy/dummy_notifier.rb
258
297
  - spec/rails_app/app/models/dummy/dummy_target.rb
@@ -298,10 +337,12 @@ files:
298
337
  - spec/rails_app/db/migrate/20160715050433_create_test_tables.rb
299
338
  - spec/rails_app/db/schema.rb
300
339
  - spec/rails_app/db/seeds.rb
340
+ - spec/rails_app/lib/mailer_previews/mailer_preview.rb
301
341
  - spec/rails_app/public/404.html
302
342
  - spec/rails_app/public/422.html
303
343
  - spec/rails_app/public/500.html
304
344
  - spec/rails_app/public/favicon.ico
345
+ - spec/roles/acts_as_group_spec.rb
305
346
  - spec/roles/acts_as_notifiable_spec.rb
306
347
  - spec/roles/acts_as_notifier_spec.rb
307
348
  - spec/roles/acts_as_target_spec.rb
@@ -333,6 +374,7 @@ summary: Integrated user activity notifications for Ruby on Rails
333
374
  test_files:
334
375
  - spec/concerns/apis/notification_api_spec.rb
335
376
  - spec/concerns/common_spec.rb
377
+ - spec/concerns/models/group_spec.rb
336
378
  - spec/concerns/models/notifiable_spec.rb
337
379
  - spec/concerns/models/notifier_spec.rb
338
380
  - spec/concerns/models/target_spec.rb
@@ -343,6 +385,7 @@ test_files:
343
385
  - spec/factories/admins.rb
344
386
  - spec/factories/articles.rb
345
387
  - spec/factories/comments.rb
388
+ - spec/factories/dummy/dummy_group.rb
346
389
  - spec/factories/dummy/dummy_notifiable.rb
347
390
  - spec/factories/dummy/dummy_notifier.rb
348
391
  - spec/factories/dummy/dummy_target.rb
@@ -356,12 +399,16 @@ test_files:
356
399
  - spec/helpers/polymorphic_helpers_spec.rb
357
400
  - spec/helpers/view_helpers_spec.rb
358
401
  - spec/mailers/mailer_spec.rb
402
+ - spec/models/dummy/dummy_group_spec.rb
359
403
  - spec/models/dummy/dummy_notifiable_spec.rb
360
404
  - spec/models/dummy/dummy_notifier_spec.rb
361
405
  - spec/models/dummy/dummy_target_spec.rb
362
406
  - spec/models/notification_spec.rb
363
407
  - spec/rails_app/Rakefile
364
408
  - spec/rails_app/app/assets/javascripts/application.js
409
+ - spec/rails_app/app/assets/stylesheets/application.css
410
+ - spec/rails_app/app/assets/stylesheets/reset.css
411
+ - spec/rails_app/app/assets/stylesheets/style.css
365
412
  - spec/rails_app/app/controllers/application_controller.rb
366
413
  - spec/rails_app/app/controllers/articles_controller.rb
367
414
  - spec/rails_app/app/controllers/comments_controller.rb
@@ -373,6 +420,7 @@ test_files:
373
420
  - spec/rails_app/app/models/article.rb
374
421
  - spec/rails_app/app/models/comment.rb
375
422
  - spec/rails_app/app/models/dummy/dummy_base.rb
423
+ - spec/rails_app/app/models/dummy/dummy_group.rb
376
424
  - spec/rails_app/app/models/dummy/dummy_notifiable.rb
377
425
  - spec/rails_app/app/models/dummy/dummy_notifier.rb
378
426
  - spec/rails_app/app/models/dummy/dummy_target.rb
@@ -418,10 +466,12 @@ test_files:
418
466
  - spec/rails_app/db/migrate/20160715050433_create_test_tables.rb
419
467
  - spec/rails_app/db/schema.rb
420
468
  - spec/rails_app/db/seeds.rb
469
+ - spec/rails_app/lib/mailer_previews/mailer_preview.rb
421
470
  - spec/rails_app/public/404.html
422
471
  - spec/rails_app/public/422.html
423
472
  - spec/rails_app/public/500.html
424
473
  - spec/rails_app/public/favicon.ico
474
+ - spec/roles/acts_as_group_spec.rb
425
475
  - spec/roles/acts_as_notifiable_spec.rb
426
476
  - spec/roles/acts_as_notifier_spec.rb
427
477
  - spec/roles/acts_as_target_spec.rb