activity_notification 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- activity_notification (1.4.1)
4
+ activity_notification (1.4.2)
5
5
  i18n (>= 0.5.0)
6
6
  jquery-rails (>= 3.1.1)
7
7
  railties (>= 4.2.0, < 5.2)
@@ -9,39 +9,39 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (5.1.1)
13
- actionpack (= 5.1.1)
12
+ actioncable (5.1.2)
13
+ actionpack (= 5.1.2)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (~> 0.6.1)
16
- actionmailer (5.1.1)
17
- actionpack (= 5.1.1)
18
- actionview (= 5.1.1)
19
- activejob (= 5.1.1)
16
+ actionmailer (5.1.2)
17
+ actionpack (= 5.1.2)
18
+ actionview (= 5.1.2)
19
+ activejob (= 5.1.2)
20
20
  mail (~> 2.5, >= 2.5.4)
21
21
  rails-dom-testing (~> 2.0)
22
- actionpack (5.1.1)
23
- actionview (= 5.1.1)
24
- activesupport (= 5.1.1)
22
+ actionpack (5.1.2)
23
+ actionview (= 5.1.2)
24
+ activesupport (= 5.1.2)
25
25
  rack (~> 2.0)
26
26
  rack-test (~> 0.6.3)
27
27
  rails-dom-testing (~> 2.0)
28
28
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
- actionview (5.1.1)
30
- activesupport (= 5.1.1)
29
+ actionview (5.1.2)
30
+ activesupport (= 5.1.2)
31
31
  builder (~> 3.1)
32
32
  erubi (~> 1.4)
33
33
  rails-dom-testing (~> 2.0)
34
34
  rails-html-sanitizer (~> 1.0, >= 1.0.3)
35
- activejob (5.1.1)
36
- activesupport (= 5.1.1)
35
+ activejob (5.1.2)
36
+ activesupport (= 5.1.2)
37
37
  globalid (>= 0.3.6)
38
- activemodel (5.1.1)
39
- activesupport (= 5.1.1)
40
- activerecord (5.1.1)
41
- activemodel (= 5.1.1)
42
- activesupport (= 5.1.1)
38
+ activemodel (5.1.2)
39
+ activesupport (= 5.1.2)
40
+ activerecord (5.1.2)
41
+ activemodel (= 5.1.2)
42
+ activesupport (= 5.1.2)
43
43
  arel (~> 8.0)
44
- activesupport (5.1.1)
44
+ activesupport (5.1.2)
45
45
  concurrent-ruby (~> 1.0, >= 1.0.2)
46
46
  i18n (~> 0.7)
47
47
  minitest (~> 5.1)
@@ -51,18 +51,18 @@ GEM
51
51
  railties (>= 3.0)
52
52
  rspec-rails (>= 2.2)
53
53
  arel (8.0.0)
54
- aws-sdk (2.9.19)
55
- aws-sdk-resources (= 2.9.19)
56
- aws-sdk-core (2.9.19)
54
+ aws-sdk (2.10.15)
55
+ aws-sdk-resources (= 2.10.15)
56
+ aws-sdk-core (2.10.15)
57
57
  aws-sigv4 (~> 1.0)
58
58
  jmespath (~> 1.0)
59
- aws-sdk-resources (2.9.19)
60
- aws-sdk-core (= 2.9.19)
61
- aws-sigv4 (1.0.0)
59
+ aws-sdk-resources (2.10.15)
60
+ aws-sdk-core (= 2.10.15)
61
+ aws-sigv4 (1.0.1)
62
62
  bcrypt (3.1.11)
63
- bson (4.2.1)
63
+ bson (4.2.2)
64
64
  builder (3.2.3)
65
- bullet (5.5.1)
65
+ bullet (5.6.0)
66
66
  activesupport (>= 3.0.0)
67
67
  uniform_notifier (~> 1.10.0)
68
68
  concurrent-ruby (1.0.5)
@@ -84,7 +84,7 @@ GEM
84
84
  dotenv-rails (2.2.1)
85
85
  dotenv (= 2.2.1)
86
86
  railties (>= 3.2, < 5.2)
87
- erubi (1.6.0)
87
+ erubi (1.6.1)
88
88
  factory_girl (4.8.0)
89
89
  activesupport (>= 3.0.0)
90
90
  factory_girl_rails (4.8.0)
@@ -92,7 +92,7 @@ GEM
92
92
  railties (>= 3.0.0)
93
93
  globalid (0.4.0)
94
94
  activesupport (>= 4.2.0)
95
- i18n (0.8.1)
95
+ i18n (0.8.6)
96
96
  jmespath (1.3.1)
97
97
  jquery-rails (4.3.1)
98
98
  rails-dom-testing (>= 1, < 3)
@@ -101,39 +101,39 @@ GEM
101
101
  json (2.1.0)
102
102
  loofah (2.0.3)
103
103
  nokogiri (>= 1.5.9)
104
- mail (2.6.5)
104
+ mail (2.6.6)
105
105
  mime-types (>= 1.16, < 4)
106
106
  method_source (0.8.2)
107
107
  mime-types (3.1)
108
108
  mime-types-data (~> 3.2015)
109
109
  mime-types-data (3.2016.0521)
110
- mini_portile2 (2.1.0)
111
- minitest (5.10.2)
112
- mongo (2.4.1)
110
+ mini_portile2 (2.2.0)
111
+ minitest (5.10.3)
112
+ mongo (2.4.2)
113
113
  bson (>= 4.2.1, < 5.0.0)
114
- mongoid (6.1.0)
115
- activemodel (~> 5.0)
114
+ mongoid (6.2.0)
115
+ activemodel (~> 5.1)
116
116
  mongo (>= 2.4.1, < 3.0.0)
117
- mysql2 (0.4.6)
118
- nio4r (2.0.0)
119
- nokogiri (1.7.2)
120
- mini_portile2 (~> 2.1.0)
117
+ mysql2 (0.4.8)
118
+ nio4r (2.1.0)
119
+ nokogiri (1.8.0)
120
+ mini_portile2 (~> 2.2.0)
121
121
  orm_adapter (0.5.0)
122
- pg (0.20.0)
122
+ pg (0.21.0)
123
123
  rack (2.0.3)
124
124
  rack-test (0.6.3)
125
125
  rack (>= 1.0)
126
- rails (5.1.1)
127
- actioncable (= 5.1.1)
128
- actionmailer (= 5.1.1)
129
- actionpack (= 5.1.1)
130
- actionview (= 5.1.1)
131
- activejob (= 5.1.1)
132
- activemodel (= 5.1.1)
133
- activerecord (= 5.1.1)
134
- activesupport (= 5.1.1)
126
+ rails (5.1.2)
127
+ actioncable (= 5.1.2)
128
+ actionmailer (= 5.1.2)
129
+ actionpack (= 5.1.2)
130
+ actionview (= 5.1.2)
131
+ activejob (= 5.1.2)
132
+ activemodel (= 5.1.2)
133
+ activerecord (= 5.1.2)
134
+ activesupport (= 5.1.2)
135
135
  bundler (>= 1.3.0, < 2.0)
136
- railties (= 5.1.1)
136
+ railties (= 5.1.2)
137
137
  sprockets-rails (>= 2.0.0)
138
138
  rails-controller-testing (1.0.2)
139
139
  actionpack (~> 5.x, >= 5.0.1)
@@ -144,9 +144,9 @@ GEM
144
144
  nokogiri (>= 1.6)
145
145
  rails-html-sanitizer (1.0.3)
146
146
  loofah (~> 2.0)
147
- railties (5.1.1)
148
- actionpack (= 5.1.1)
149
- activesupport (= 5.1.1)
147
+ railties (5.1.2)
148
+ actionpack (= 5.1.2)
149
+ activesupport (= 5.1.2)
150
150
  method_source
151
151
  rake (>= 0.8.7)
152
152
  thor (>= 0.18.1, < 2.0)
@@ -175,8 +175,8 @@ GEM
175
175
  docile (~> 1.1.0)
176
176
  json (>= 1.8, < 3)
177
177
  simplecov-html (~> 0.10.0)
178
- simplecov-html (0.10.0)
179
- slack-notifier (2.1.0)
178
+ simplecov-html (0.10.1)
179
+ slack-notifier (2.2.2)
180
180
  sprockets (3.7.1)
181
181
  concurrent-ruby (~> 1.0)
182
182
  rack (> 1, < 3)
@@ -189,8 +189,8 @@ GEM
189
189
  tins (~> 1.0)
190
190
  thor (0.19.4)
191
191
  thread_safe (0.3.6)
192
- timecop (0.8.1)
193
- tins (1.14.0)
192
+ timecop (0.9.1)
193
+ tins (1.15.0)
194
194
  tzinfo (1.2.3)
195
195
  thread_safe (~> 0.1)
196
196
  uniform_notifier (1.10.0)
@@ -216,8 +216,8 @@ DEPENDENCIES
216
216
  dotenv-rails
217
217
  factory_girl_rails (~> 4.8.0)
218
218
  mongoid (>= 4.0.0)
219
- mysql2 (~> 0.4.6)
220
- pg (~> 0.20.0)
219
+ mysql2 (~> 0.4.8)
220
+ pg (~> 0.21.0)
221
221
  rails (~> 5.1.0)
222
222
  rails-controller-testing
223
223
  rspec-rails (~> 3.6.0)
@@ -7,6 +7,9 @@ module ActivityNotification
7
7
  # Defines store_notification as private clas method
8
8
  private_class_method :store_notification
9
9
 
10
+ # Defines mailer class to send notification
11
+ set_notification_mailer
12
+
10
13
  # Selects all notification index.
11
14
  # ActivityNotification::Notification.all_index!
12
15
  # is defined same as
@@ -285,8 +288,8 @@ module ActivityNotification
285
288
  target.subscribes_to_notification_email?(batch_key)
286
289
  send_later = options.has_key?(:send_later) ? options[:send_later] : true
287
290
  send_later ?
288
- Mailer.send_batch_notification_email(target, notifications, batch_key, options).deliver_later :
289
- Mailer.send_batch_notification_email(target, notifications, batch_key, options).deliver_now
291
+ @@notification_mailer.send_batch_notification_email(target, notifications, batch_key, options).deliver_later :
292
+ @@notification_mailer.send_batch_notification_email(target, notifications, batch_key, options).deliver_now
290
293
  end
291
294
  end
292
295
 
@@ -297,6 +300,11 @@ module ActivityNotification
297
300
  [:key, :group, :parameters, :notifier, :send_email, :send_later].freeze
298
301
  end
299
302
 
303
+ # Defines mailer class to send notification
304
+ def set_notification_mailer
305
+ @@notification_mailer = ActivityNotification.config.mailer.constantize
306
+ end
307
+
300
308
  # Stores notifications to datastore
301
309
  # @api private
302
310
  def store_notification(target, notifiable, key, options = {})
@@ -321,7 +329,6 @@ module ActivityNotification
321
329
  end
322
330
  end
323
331
 
324
-
325
332
  # Sends notification email to the target.
326
333
  #
327
334
  # @param [Hash] options Options for notification email
@@ -334,8 +341,8 @@ module ActivityNotification
334
341
  email_subscribed?
335
342
  send_later = options.has_key?(:send_later) ? options[:send_later] : true
336
343
  send_later ?
337
- Mailer.send_notification_email(self, options).deliver_later :
338
- Mailer.send_notification_email(self, options).deliver_now
344
+ @@notification_mailer.send_notification_email(self, options).deliver_later :
345
+ @@notification_mailer.send_notification_email(self, options).deliver_now
339
346
  end
340
347
  end
341
348
 
@@ -1,6 +1,6 @@
1
1
  module ActivityNotification
2
2
  # Module included in controllers to authenticate with Devise module
3
- module DeviceAuthenticationController
3
+ module DeviseAuthenticationController
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
@@ -58,8 +58,14 @@ module ActivityNotification
58
58
  @notification.notifiable.overriding_notification_email_key(@target, key).present?
59
59
  key = @notification.notifiable.overriding_notification_email_key(@target, key)
60
60
  end
61
+ if @notification.notifiable.respond_to?(:overriding_notification_email_subject) &&
62
+ @notification.notifiable.overriding_notification_email_subject(@target, key).present?
63
+ subject = @notification.notifiable.overriding_notification_email_subject(@target, key)
64
+ else
65
+ subject = subject_for(key)
66
+ end
61
67
  headers = {
62
- subject: subject_for(key),
68
+ subject: subject,
63
69
  to: mailer_to(@target),
64
70
  from: mailer_from(key),
65
71
  reply_to: mailer_reply_to(key),
@@ -220,6 +220,12 @@ module ActivityNotification
220
220
  #
221
221
  # overriding_notification_email_key(target, key)
222
222
 
223
+ # overriding_notification_email_subject is the method to override subject definition for Mailer
224
+ # When respond_to?(:overriding_notification_email_subject) returns true,
225
+ # Mailer uses overriding_notification_email_subject instead of configured notification subject in locale file.
226
+ #
227
+ # overriding_notification_email_subject(target, key)
228
+
223
229
 
224
230
  # Generates notifications to configured targets with notifiable model.
225
231
  # This method calls NotificationApi#notify internally with self notifiable instance.
@@ -1,3 +1,3 @@
1
1
  module ActivityNotification
2
- VERSION = "1.4.1"
2
+ VERSION = "1.4.2"
3
3
  end
@@ -14,7 +14,6 @@ Some setup you must do manually if you haven't yet:
14
14
 
15
15
  - Add including statement and acts_as_target definition to your target model
16
16
 
17
- include ActivityNotification::Target
18
17
  acts_as_target email: :email, email_allowed: :confirmed_at
19
18
 
20
19
  - Add notification routing to config/routes.rb
@@ -29,8 +28,7 @@ Some setup you must do manually if you haven't yet:
29
28
  3. Setup your notifiable model (e.g. app/models/comment.rb)
30
29
 
31
30
  - Add including statement and acts_as_notifiable definition to your notifiable model
32
-
33
- include ActivityNotification::Notifiable
31
+
34
32
  acts_as_notifiable :users,
35
33
  targets: :custom_notification_users,
36
34
  group: :article,
@@ -2,7 +2,7 @@ ActivityNotification.configure do |config|
2
2
 
3
3
  # Configure ORM name for ActivityNotification.
4
4
  # Set :active_record or :mongoid.
5
- ENV['AN_ORM'] = 'active_record' if ENV['AN_ORM'] != 'mongoid'
5
+ ENV['AN_ORM'] = 'active_record' unless ENV['AN_ORM'] == 'mongoid'
6
6
  config.orm = ENV['AN_ORM']
7
7
 
8
8
  # Configure if all activity notifications are enabled.
@@ -41,6 +41,9 @@ ActivityNotification.configure do |config|
41
41
  # Configure the parent class responsible to send e-mails.
42
42
  # config.parent_mailer = 'ActionMailer::Base'
43
43
 
44
+ # Configure the parent class for activity_notification controllers.
45
+ # config.parent_controller = 'ApplicationController'
46
+
44
47
  # Configure default limit number of opened notifications you can get from opened* scope
45
48
  config.opened_index_limit = 10
46
49
 
@@ -0,0 +1,34 @@
1
+ describe ActivityNotification::Config do
2
+ describe "config.mailer" do
3
+ let(:notification) { create(:notification) }
4
+
5
+ context "as default" do
6
+ it "is configured with ActivityNotification::Mailer" do
7
+ expect(ActivityNotification::Mailer).to receive(:send_notification_email).and_call_original
8
+ notification.send_notification_email send_later: false
9
+ end
10
+
11
+ it "is not configured with CustomNotificationMailer" do
12
+ expect(CustomNotificationMailer).not_to receive(:send_notification_email).and_call_original
13
+ notification.send_notification_email send_later: false
14
+ end
15
+ end
16
+
17
+ context "when it is configured with CustomNotificationMailer" do
18
+ before do
19
+ ActivityNotification.config.mailer = 'CustomNotificationMailer'
20
+ ActivityNotification::Notification.set_notification_mailer
21
+ end
22
+
23
+ after do
24
+ ActivityNotification.config.mailer = 'ActivityNotification::Mailer'
25
+ ActivityNotification::Notification.set_notification_mailer
26
+ end
27
+
28
+ it "is configured with CustomMailer" do
29
+ expect(CustomNotificationMailer).to receive(:send_notification_email).and_call_original
30
+ notification.send_notification_email send_later: false
31
+ end
32
+ end
33
+ end
34
+ end
@@ -88,6 +88,20 @@ describe ActivityNotification::Mailer do
88
88
  end
89
89
  end
90
90
 
91
+ context "with defined overriding_notification_email_subject in notifiable model" do
92
+ it "sends with updated subject" do
93
+ module AdditionalMethods
94
+ def overriding_notification_email_subject(target, key)
95
+ 'Hi, You have got comment'
96
+ end
97
+ end
98
+ notification.notifiable.extend(AdditionalMethods)
99
+ ActivityNotification::Mailer.send_notification_email(notification).deliver_now
100
+ expect(ActivityNotification::Mailer.deliveries.last.subject)
101
+ .to eq("Hi, You have got comment")
102
+ end
103
+ end
104
+
91
105
  context "when fallback option is :none and the template is missing" do
92
106
  it "raise ActionView::MissingTemplate" do
93
107
  expect { ActivityNotification::Mailer.send_notification_email(notification, fallback: :none).deliver_now }
@@ -0,0 +1,5 @@
1
+ class CustomNotificationMailer < ActivityNotification::Mailer
2
+ def send_notification_email(notification, options = {})
3
+ 'This is CustomNotificationMailer'
4
+ end
5
+ end
@@ -41,6 +41,9 @@ ActivityNotification.configure do |config|
41
41
  # Configure the parent class responsible to send e-mails.
42
42
  # config.parent_mailer = 'ActionMailer::Base'
43
43
 
44
+ # Configure the parent class for activity_notification controllers.
45
+ # config.parent_controller = 'ApplicationController'
46
+
44
47
  # Configure default limit number of opened notifications you can get from opened* scope
45
48
  config.opened_index_limit = 10
46
49
 
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: 1.4.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Yamazaki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -78,28 +78,28 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: 0.4.6
81
+ version: 0.4.8
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: 0.4.6
88
+ version: 0.4.8
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: pg
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: 0.20.0
95
+ version: 0.21.0
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: 0.20.0
102
+ version: 0.21.0
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: mongoid
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -352,6 +352,7 @@ files:
352
352
  - spec/concerns/models/subscriber_spec.rb
353
353
  - spec/concerns/models/target_spec.rb
354
354
  - spec/concerns/renderable_spec.rb
355
+ - spec/config_spec.rb
355
356
  - spec/controllers/common_controller_spec.rb
356
357
  - spec/controllers/dummy_common_controller.rb
357
358
  - spec/controllers/notifications_controller_shared_examples.rb
@@ -404,6 +405,7 @@ files:
404
405
  - spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb
405
406
  - spec/rails_app/app/helpers/application_helper.rb
406
407
  - spec/rails_app/app/mailers/.keep
408
+ - spec/rails_app/app/mailers/custom_notification_mailer.rb
407
409
  - spec/rails_app/app/models/.keep
408
410
  - spec/rails_app/app/models/admin.rb
409
411
  - spec/rails_app/app/models/article.rb
@@ -506,6 +508,7 @@ test_files:
506
508
  - spec/concerns/models/subscriber_spec.rb
507
509
  - spec/concerns/models/target_spec.rb
508
510
  - spec/concerns/renderable_spec.rb
511
+ - spec/config_spec.rb
509
512
  - spec/controllers/common_controller_spec.rb
510
513
  - spec/controllers/dummy_common_controller.rb
511
514
  - spec/controllers/notifications_controller_shared_examples.rb
@@ -558,6 +561,7 @@ test_files:
558
561
  - spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb
559
562
  - spec/rails_app/app/helpers/application_helper.rb
560
563
  - spec/rails_app/app/mailers/.keep
564
+ - spec/rails_app/app/mailers/custom_notification_mailer.rb
561
565
  - spec/rails_app/app/models/.keep
562
566
  - spec/rails_app/app/models/admin.rb
563
567
  - spec/rails_app/app/models/article.rb