activity_notification 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -16
  3. data/CHANGELOG.md +53 -0
  4. data/Gemfile +2 -3
  5. data/README.md +1 -1
  6. data/activity_notification.gemspec +1 -1
  7. data/app/channels/activity_notification/notification_api_with_devise_channel.rb +1 -1
  8. data/app/channels/activity_notification/notification_channel.rb +1 -1
  9. data/app/channels/activity_notification/notification_with_devise_channel.rb +1 -1
  10. data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +1 -1
  11. data/app/controllers/activity_notification/notifications_controller.rb +0 -20
  12. data/app/controllers/activity_notification/subscriptions_api_controller.rb +1 -1
  13. data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +1 -1
  14. data/bin/bundle_update.sh +0 -1
  15. data/docs/Functions.md +2 -2
  16. data/docs/Setup.md +190 -63
  17. data/gemfiles/Gemfile.rails-5.0 +3 -1
  18. data/gemfiles/Gemfile.rails-5.1 +3 -1
  19. data/gemfiles/Gemfile.rails-5.2 +3 -1
  20. data/gemfiles/Gemfile.rails-6.0 +2 -3
  21. data/gemfiles/Gemfile.rails-6.1 +24 -0
  22. data/lib/activity_notification/apis/notification_api.rb +7 -0
  23. data/lib/activity_notification/common.rb +15 -4
  24. data/lib/activity_notification/controllers/common_controller.rb +2 -18
  25. data/lib/activity_notification/models/concerns/notifiable.rb +12 -12
  26. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +34 -34
  27. data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +17 -17
  28. data/lib/activity_notification/models/concerns/target.rb +5 -9
  29. data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +1 -1
  30. data/lib/activity_notification/optional_targets/action_cable_channel.rb +1 -1
  31. data/lib/activity_notification/orm/active_record.rb +1 -1
  32. data/lib/activity_notification/orm/active_record/notification.rb +3 -3
  33. data/lib/activity_notification/orm/dynamoid.rb +10 -3
  34. data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
  35. data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
  36. data/lib/activity_notification/orm/mongoid.rb +10 -3
  37. data/lib/activity_notification/orm/mongoid/notification.rb +8 -6
  38. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  39. data/lib/activity_notification/renderable.rb +2 -2
  40. data/lib/activity_notification/roles/acts_as_notifiable.rb +13 -16
  41. data/lib/activity_notification/version.rb +1 -1
  42. data/lib/generators/templates/migrations/migration.rb +1 -1
  43. data/spec/channels/notification_api_channel_spec.rb +42 -44
  44. data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
  45. data/spec/channels/notification_channel_spec.rb +41 -43
  46. data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
  47. data/spec/concerns/common_spec.rb +25 -3
  48. data/spec/concerns/models/notifiable_spec.rb +35 -35
  49. data/spec/concerns/models/target_spec.rb +10 -12
  50. data/spec/concerns/renderable_spec.rb +5 -5
  51. data/spec/config_spec.rb +26 -15
  52. data/spec/controllers/controller_spec_utility.rb +15 -51
  53. data/spec/generators/migration/migration_generator_spec.rb +2 -10
  54. data/spec/helpers/view_helpers_spec.rb +1 -1
  55. data/spec/models/subscription_spec.rb +8 -0
  56. data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
  57. data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
  58. data/spec/rails_app/app/controllers/users_controller.rb +5 -0
  59. data/spec/rails_app/app/javascript/App.vue +8 -72
  60. data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +3 -4
  61. data/spec/rails_app/app/javascript/components/Top.vue +2 -3
  62. data/spec/rails_app/app/javascript/packs/spa.js +6 -3
  63. data/spec/rails_app/app/javascript/router/index.js +73 -0
  64. data/spec/rails_app/app/javascript/store/{auth.js → index.js} +0 -0
  65. data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
  66. data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
  67. data/spec/rails_app/app/models/user.rb +2 -1
  68. data/spec/rails_app/config/application.rb +6 -7
  69. data/spec/rails_app/config/dynamoid.rb +11 -3
  70. data/spec/rails_app/config/environments/production.rb +3 -0
  71. data/spec/rails_app/config/environments/test.rb +2 -11
  72. data/spec/rails_app/config/initializers/activity_notification.rb +3 -3
  73. data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
  74. data/spec/rails_app/config/routes.rb +5 -1
  75. data/spec/rails_app/db/seeds.rb +9 -2
  76. data/spec/roles/acts_as_notifiable_spec.rb +5 -5
  77. data/spec/spec_helper.rb +1 -5
  78. metadata +14 -12
  79. data/gemfiles/Gemfile.rails-4.2 +0 -23
  80. data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
@@ -11,13 +11,15 @@ group :development do
11
11
  end
12
12
 
13
13
  group :test do
14
+ gem 'rspec-rails', '< 4.0.0'
14
15
  gem 'rails-controller-testing'
15
16
  gem 'action-cable-testing'
16
17
  gem 'ammeter'
17
18
  gem 'timecop'
18
19
  gem 'committee'
19
20
  gem 'committee-rails'
20
- gem 'coveralls', require: false
21
+ # gem 'coveralls', require: false
22
+ gem 'coveralls_reborn', require: false
21
23
  end
22
24
 
23
25
  gem 'dotenv-rails', groups: [:development, :test]
@@ -10,13 +10,15 @@ group :development do
10
10
  end
11
11
 
12
12
  group :test do
13
+ gem 'rspec-rails', '< 4.0.0'
13
14
  gem 'rails-controller-testing'
14
15
  gem 'action-cable-testing'
15
16
  gem 'ammeter'
16
17
  gem 'timecop'
17
18
  gem 'committee'
18
19
  gem 'committee-rails'
19
- gem 'coveralls', require: false
20
+ # gem 'coveralls', require: false
21
+ gem 'coveralls_reborn', require: false
20
22
  end
21
23
 
22
24
  gem 'dotenv-rails', groups: [:development, :test]
@@ -10,13 +10,15 @@ group :development do
10
10
  end
11
11
 
12
12
  group :test do
13
+ gem 'rspec-rails', '< 4.0.0'
13
14
  gem 'rails-controller-testing'
14
15
  gem 'action-cable-testing'
15
16
  gem 'ammeter'
16
17
  gem 'timecop'
17
18
  gem 'committee'
18
19
  gem 'committee-rails'
19
- gem 'coveralls', require: false
20
+ # gem 'coveralls', require: false
21
+ gem 'coveralls_reborn', require: false
20
22
  end
21
23
 
22
24
  gem 'dotenv-rails', groups: [:development, :test]
@@ -10,14 +10,13 @@ group :development do
10
10
  end
11
11
 
12
12
  group :test do
13
- #TODO https://github.com/rails/rails/issues/35417
14
- gem 'rspec-rails', '4.0.0.beta4'
15
13
  gem 'rails-controller-testing'
16
14
  gem 'ammeter'
17
15
  gem 'timecop'
18
16
  gem 'committee'
19
17
  gem 'committee-rails'
20
- gem 'coveralls', require: false
18
+ # gem 'coveralls', require: false
19
+ gem 'coveralls_reborn', require: false
21
20
  end
22
21
 
23
22
  gem 'dotenv-rails', groups: [:development, :test]
@@ -0,0 +1,24 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'rails', '~> 6.1.0'
6
+ gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git'
7
+ gem 'devise_token_auth', git: 'https://github.com/lynndylanhurley/devise_token_auth'
8
+
9
+ group :development do
10
+ gem 'bullet'
11
+ gem 'rack-cors'
12
+ end
13
+
14
+ group :test do
15
+ gem 'rails-controller-testing'
16
+ gem 'ammeter'
17
+ gem 'timecop'
18
+ gem 'committee'
19
+ gem 'committee-rails'
20
+ # gem 'coveralls', require: false
21
+ gem 'coveralls_reborn', require: false
22
+ end
23
+
24
+ gem 'dotenv-rails', groups: [:development, :test]
@@ -495,16 +495,23 @@ module ActivityNotification
495
495
 
496
496
  notification = new({ target: target, notifiable: notifiable, key: key, group: group, parameters: parameters, notifier: notifier, group_owner: group_owner })
497
497
  notification.prepare_to_store.save
498
+ notification.after_store
498
499
  notification
499
500
  end
500
501
  end
501
502
 
503
+ # :nocov:
502
504
  # Returns prepared notification object to store
503
505
  # @return [Object] prepared notification object to store
504
506
  def prepare_to_store
505
507
  self
506
508
  end
507
509
 
510
+ # Call after store action with stored notification
511
+ def after_store
512
+ end
513
+ # :nocov:
514
+
508
515
  # Sends notification email to the target.
509
516
  #
510
517
  # @param [Hash] options Options for notification email
@@ -16,7 +16,11 @@ module ActivityNotification
16
16
  when Symbol
17
17
  symbol_method = context.method(thing)
18
18
  if symbol_method.arity > 1
19
- symbol_method.call(ActivityNotification.get_controller, *args)
19
+ if args.last.kind_of?(Hash)
20
+ symbol_method.call(ActivityNotification.get_controller, *args[0...-1], **args[-1])
21
+ else
22
+ symbol_method.call(ActivityNotification.get_controller, *args)
23
+ end
20
24
  elsif symbol_method.arity > 0
21
25
  symbol_method.call(ActivityNotification.get_controller)
22
26
  else
@@ -74,7 +78,11 @@ module ActivityNotification
74
78
  when Symbol
75
79
  symbol_method = method(thing)
76
80
  if symbol_method.arity > 0
77
- symbol_method.call(*args)
81
+ if args.last.kind_of?(Hash)
82
+ symbol_method.call(*args[0...-1], **args[-1])
83
+ else
84
+ symbol_method.call(*args)
85
+ end
78
86
  else
79
87
  symbol_method.call
80
88
  end
@@ -98,9 +106,12 @@ module ActivityNotification
98
106
  end
99
107
 
100
108
  # Convets to class name.
109
+ # This function returns base_class name for STI models if the class responds to base_class method.
110
+ # @see https://github.com/simukappu/activity_notification/issues/89
111
+ # @see https://github.com/simukappu/activity_notification/pull/139
101
112
  # @return [String] Class name
102
113
  def to_class_name
103
- self.class.name
114
+ self.class.respond_to?(:base_class) ? self.class.base_class.name : self.class.name
104
115
  end
105
116
 
106
117
  # Convets to singularized model name (resource name).
@@ -128,4 +139,4 @@ module ActivityNotification
128
139
  "#{self.printable_type} (#{id})"
129
140
  end
130
141
  end
131
- end
142
+ end
@@ -26,7 +26,7 @@ module ActivityNotification
26
26
  target_class = target_type.to_model_class
27
27
  @target = params[:target_id].present? ?
28
28
  target_class.find_by!(id: params[:target_id]) :
29
- target_class.find_by!(id: params["#{target_type.to_resource_name}_id"])
29
+ target_class.find_by!(id: params["#{target_type.to_resource_name[/([^\/]+)$/]}_id"])
30
30
  else
31
31
  render status: 400, json: error_response(code: 400, message: "Invalid parameter", type: "Parameter is missing or the value is empty: target_type")
32
32
  end
@@ -130,25 +130,9 @@ module ActivityNotification
130
130
  load_index if params[:reload].to_s.to_boolean(true)
131
131
  format.js
132
132
  else
133
- compatibly_redirect_back(@index_options) and return
133
+ redirect_back(fallback_location: { action: :index }, **@index_options) and return
134
134
  end
135
135
  end
136
136
  end
137
-
138
- # Redirect to back.
139
- # @api protected
140
- # @return [Boolean] True
141
- def compatibly_redirect_back(request_params = {})
142
- # :nocov:
143
- if Rails::VERSION::MAJOR >= 5
144
- redirect_back fallback_location: { action: :index }, **request_params
145
- elsif request.referer
146
- redirect_to :back, **request_params
147
- else
148
- redirect_to action: :index, **request_params
149
- end
150
- # :nocov:
151
- true
152
- end
153
137
  end
154
138
  end
@@ -25,8 +25,8 @@ module ActivityNotification
25
25
  :_notifier,
26
26
  :_notification_parameters,
27
27
  :_notification_email_allowed,
28
- :_notification_action_cable_allowed,
29
- :_notification_action_cable_api_allowed,
28
+ :_notifiable_action_cable_allowed,
29
+ :_notifiable_action_cable_api_allowed,
30
30
  :_notifiable_path,
31
31
  :_printable_notifiable_name,
32
32
  :_optional_targets
@@ -55,8 +55,8 @@ module ActivityNotification
55
55
  self._notifier = {}
56
56
  self._notification_parameters = {}
57
57
  self._notification_email_allowed = {}
58
- self._notification_action_cable_allowed = {}
59
- self._notification_action_cable_api_allowed = {}
58
+ self._notifiable_action_cable_allowed = {}
59
+ self._notifiable_action_cable_api_allowed = {}
60
60
  self._notifiable_path = {}
61
61
  self._printable_notifiable_name = {}
62
62
  self._optional_targets = {}
@@ -162,10 +162,10 @@ module ActivityNotification
162
162
  # @param [Object] target Target instance to notify
163
163
  # @param [String] key Key of the notification
164
164
  # @return [Boolean] If publishing WebSocket using ActionCable is allowed for the notifiable
165
- def notification_action_cable_allowed?(target, key = nil)
165
+ def notifiable_action_cable_allowed?(target, key = nil)
166
166
  resolve_parameter(
167
- "notification_action_cable_allowed_for_#{cast_to_resources_name(target.class)}?",
168
- _notification_action_cable_allowed[cast_to_resources_sym(target.class)],
167
+ "notifiable_action_cable_allowed_for_#{cast_to_resources_name(target.class)}?",
168
+ _notifiable_action_cable_allowed[cast_to_resources_sym(target.class)],
169
169
  ActivityNotification.config.action_cable_enabled,
170
170
  target, key)
171
171
  end
@@ -176,10 +176,10 @@ module ActivityNotification
176
176
  # @param [Object] target Target instance to notify
177
177
  # @param [String] key Key of the notification
178
178
  # @return [Boolean] If publishing WebSocket API using ActionCable is allowed for the notifiable
179
- def notification_action_cable_api_allowed?(target, key = nil)
179
+ def notifiable_action_cable_api_allowed?(target, key = nil)
180
180
  resolve_parameter(
181
- "notification_action_cable_api_allowed_for_#{cast_to_resources_name(target.class)}?",
182
- _notification_action_cable_api_allowed[cast_to_resources_sym(target.class)],
181
+ "notifiable_action_cable_api_allowed_for_#{cast_to_resources_name(target.class)}?",
182
+ _notifiable_action_cable_api_allowed[cast_to_resources_sym(target.class)],
183
183
  ActivityNotification.config.action_cable_api_enabled,
184
184
  target, key)
185
185
  end
@@ -456,7 +456,7 @@ module ActivityNotification
456
456
  unless generated_notifications.to_a.empty?
457
457
  record = self.class.human_attribute_name("generated_notifications_as_notifiable_for_#{target_type.to_s.pluralize.underscore}").downcase
458
458
  self.errors.add(:base, :'restrict_dependent_destroy.has_many', record: record)
459
- if Rails::VERSION::MAJOR >= 5 then throw(:abort) else false end
459
+ throw(:abort)
460
460
  end
461
461
  when :destroy
462
462
  generated_notifications.each { |n| n.destroy }
@@ -482,7 +482,7 @@ module ActivityNotification
482
482
  # Casts to symbol of resources name.
483
483
  # @api private
484
484
  def cast_to_resources_sym(target_type)
485
- target_type.to_s.to_resources_name.to_sym
485
+ cast_to_resources_name(target_type).to_sym
486
486
  end
487
487
  end
488
488
  end
@@ -90,7 +90,7 @@ module ActivityNotification
90
90
  type: :string
91
91
  }
92
92
  key :example, {
93
- "test_default_param": "1"
93
+ test_default_param: "1"
94
94
  }
95
95
  end
96
96
  property :opened_at do
@@ -139,28 +139,28 @@ module ActivityNotification
139
139
  key :type, :object
140
140
  key :description, "Associated target model in your application"
141
141
  key :example, {
142
- "id": 1,
143
- "email": "ichiro@example.com",
144
- "name": "Ichiro",
145
- "created_at": Time.current,
146
- "updated_at": Time.current,
147
- "provider": "email",
148
- "uid": "",
149
- "printable_type": "User",
150
- "printable_target_name": "Ichiro"
142
+ id: 1,
143
+ email: "ichiro@example.com",
144
+ name: "Ichiro",
145
+ created_at: Time.current,
146
+ updated_at: Time.current,
147
+ provider: "email",
148
+ uid: "",
149
+ printable_type: "User",
150
+ printable_target_name: "Ichiro"
151
151
  }
152
152
  end
153
153
  property :notifiable do
154
154
  key :type, :object
155
155
  key :description, "Associated notifiable model in your application"
156
156
  key :example, {
157
- "id": 22,
158
- "user_id": 2,
159
- "article_id": 11,
160
- "body": "This is the first Stephen's comment to Ichiro's article.",
161
- "created_at": Time.current,
162
- "updated_at": Time.current,
163
- "printable_type": "Comment"
157
+ id: 22,
158
+ user_id: 2,
159
+ article_id: 11,
160
+ body: "This is the first Stephen's comment to Ichiro's article.",
161
+ created_at: Time.current,
162
+ updated_at: Time.current,
163
+ printable_type: "Comment"
164
164
  }
165
165
  end
166
166
  property :group do
@@ -168,14 +168,14 @@ module ActivityNotification
168
168
  key :description, "Associated group model in your application"
169
169
  key :nullable, true
170
170
  key :example, {
171
- "id": 11,
172
- "user_id": 4,
173
- "title": "Ichiro's great article",
174
- "body": "This is Ichiro's great article. Please read it!",
175
- "created_at": Time.current,
176
- "updated_at": Time.current,
177
- "printable_type": "Article",
178
- "printable_group_name": "article \"Ichiro's great article\""
171
+ id: 11,
172
+ user_id: 4,
173
+ title: "Ichiro's great article",
174
+ body: "This is Ichiro's great article. Please read it!",
175
+ created_at: Time.current,
176
+ updated_at: Time.current,
177
+ printable_type: "Article",
178
+ printable_group_name: "article \"Ichiro's great article\""
179
179
  }
180
180
  end
181
181
  property :notifier do
@@ -183,15 +183,15 @@ module ActivityNotification
183
183
  key :description, "Associated notifier model in your application"
184
184
  key :nullable, true
185
185
  key :example, {
186
- "id": 2,
187
- "email": "stephen@example.com",
188
- "name": "Stephen",
189
- "created_at": Time.current,
190
- "updated_at": Time.current,
191
- "provider": "email",
192
- "uid": "",
193
- "printable_type": "User",
194
- "printable_notifier_name": "Stephen"
186
+ id: 2,
187
+ email: "stephen@example.com",
188
+ name: "Stephen",
189
+ created_at: Time.current,
190
+ updated_at: Time.current,
191
+ provider: "email",
192
+ uid: "",
193
+ printable_type: "User",
194
+ printable_notifier_name: "Stephen"
195
195
  }
196
196
  end
197
197
  property :group_members do
@@ -90,15 +90,15 @@ module ActivityNotification
90
90
  }
91
91
  }
92
92
  key :example, {
93
- "action_cable_channel": {
94
- "subscribing": true,
95
- "subscribed_at": Time.current,
96
- "unsubscribed_at": nil
93
+ action_cable_channel: {
94
+ subscribing: true,
95
+ subscribed_at: Time.current,
96
+ unsubscribed_at: nil
97
97
  },
98
- "slack": {
99
- "subscribing": false,
100
- "subscribed_at": nil,
101
- "unsubscribed_at": Time.current
98
+ slack: {
99
+ subscribing: false,
100
+ subscribed_at: nil,
101
+ unsubscribed_at: Time.current
102
102
  }
103
103
  }
104
104
  end
@@ -114,11 +114,11 @@ module ActivityNotification
114
114
  key :type, :object
115
115
  key :description, "Associated target model in your application"
116
116
  key :example, {
117
- "id": 1,
118
- "email": "ichiro@example.com",
119
- "name": "Ichiro",
120
- "created_at": Time.current,
121
- "updated_at": Time.current
117
+ id: 1,
118
+ email: "ichiro@example.com",
119
+ name: "Ichiro",
120
+ created_at: Time.current,
121
+ updated_at: Time.current
122
122
  }
123
123
  end
124
124
  end
@@ -145,11 +145,11 @@ module ActivityNotification
145
145
  }
146
146
  }
147
147
  key :example, {
148
- "action_cable_channel": {
149
- "subscribing": true
148
+ action_cable_channel: {
149
+ subscribing: true
150
150
  },
151
- "slack": {
152
- "subscribing": false
151
+ slack: {
152
+ subscribing: false
153
153
  }
154
154
  }
155
155
  end
@@ -213,16 +213,12 @@ module ActivityNotification
213
213
  resolve_value(_notification_action_cable_with_devise)
214
214
  end
215
215
 
216
- # :nocov:
217
- if Rails::VERSION::MAJOR >= 5
218
- # Returns notification ActionCable channel class name from action_cable_with_devise? configuration.
219
- #
220
- # @return [String] Notification ActionCable channel class name from action_cable_with_devise? configuration
221
- def notification_action_cable_channel_class_name
222
- notification_action_cable_with_devise? ? "ActivityNotification::NotificationWithDeviseChannel" : "ActivityNotification::NotificationChannel"
223
- end
216
+ # Returns notification ActionCable channel class name from action_cable_with_devise? configuration.
217
+ #
218
+ # @return [String] Notification ActionCable channel class name from action_cable_with_devise? configuration
219
+ def notification_action_cable_channel_class_name
220
+ notification_action_cable_with_devise? ? "ActivityNotification::NotificationWithDeviseChannel" : "ActivityNotification::NotificationChannel"
224
221
  end
225
- # :nocov:
226
222
 
227
223
  # Returns Devise resource model associated with this target.
228
224
  #