activity_notification 2.1.4 → 2.2.3
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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +120 -0
- data/CHANGELOG.md +38 -0
- data/README.md +2 -2
- data/activity_notification.gemspec +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +0 -20
- data/app/controllers/activity_notification/subscriptions_controller.rb +2 -2
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/index.html.erb +2 -2
- data/app/views/activity_notification/subscriptions/default/show.html.erb +2 -2
- data/bin/bundle_update.sh +0 -1
- data/docs/Functions.md +17 -1
- data/gemfiles/{Gemfile.rails-4.2 → Gemfile.rails-6.1} +2 -4
- data/gemfiles/Gemfile.rails-7.0 +28 -0
- data/lib/activity_notification/apis/notification_api.rb +5 -1
- data/lib/activity_notification/apis/subscription_api.rb +5 -5
- data/lib/activity_notification/common.rb +11 -3
- data/lib/activity_notification/config.rb +63 -23
- data/lib/activity_notification/controllers/common_controller.rb +1 -17
- data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
- data/lib/activity_notification/models/concerns/subscriber.rb +6 -4
- data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +16 -16
- data/lib/activity_notification/models/concerns/target.rb +8 -12
- data/lib/activity_notification/orm/active_record/notification.rb +3 -3
- data/lib/activity_notification/orm/active_record.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
- data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
- data/lib/activity_notification/orm/mongoid/notification.rb +1 -1
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/renderable.rb +2 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +11 -15
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/templates/activity_notification.rb +15 -1
- data/lib/generators/templates/migrations/migration.rb +1 -1
- data/spec/channels/notification_api_channel_spec.rb +42 -44
- data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
- data/spec/channels/notification_channel_spec.rb +41 -43
- data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
- data/spec/concerns/apis/notification_api_spec.rb +26 -3
- data/spec/concerns/apis/subscription_api_spec.rb +144 -2
- data/spec/concerns/common_spec.rb +25 -3
- data/spec/concerns/models/subscriber_spec.rb +179 -6
- data/spec/concerns/models/target_spec.rb +10 -12
- data/spec/concerns/renderable_spec.rb +5 -5
- data/spec/controllers/controller_spec_utility.rb +15 -51
- data/spec/generators/migration/migration_generator_spec.rb +2 -10
- data/spec/helpers/view_helpers_spec.rb +1 -1
- data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
- data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
- data/spec/rails_app/config/application.rb +2 -6
- data/spec/rails_app/config/database.yml +1 -1
- data/spec/rails_app/config/environments/test.rb +2 -11
- data/spec/rails_app/config/initializers/activity_notification.rb +14 -0
- data/spec/rails_app/package.json +14 -14
- data/spec/spec_helper.rb +1 -5
- metadata +13 -14
- data/.travis.yml +0 -76
- data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
|
@@ -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
|
-
|
|
459
|
+
throw(:abort)
|
|
460
460
|
end
|
|
461
461
|
when :destroy
|
|
462
462
|
generated_notifications.each { |n| n.destroy }
|
|
@@ -61,7 +61,9 @@ module ActivityNotification
|
|
|
61
61
|
def build_subscription(subscription_params = {})
|
|
62
62
|
created_at = Time.current
|
|
63
63
|
if subscription_params[:subscribing] == false && subscription_params[:subscribing_to_email].nil?
|
|
64
|
-
subscription_params[:subscribing_to_email] = subscription_params[:subscribing]
|
|
64
|
+
subscription_params[:subscribing_to_email] = subscription_params[:subscribing]
|
|
65
|
+
elsif subscription_params[:subscribing_to_email].nil?
|
|
66
|
+
subscription_params[:subscribing_to_email] = ActivityNotification.config.subscribe_to_email_as_default
|
|
65
67
|
end
|
|
66
68
|
subscription = Subscription.new(subscription_params)
|
|
67
69
|
subscription.assign_attributes(target: self)
|
|
@@ -157,7 +159,7 @@ module ActivityNotification
|
|
|
157
159
|
# @param [String] key Key of the notification
|
|
158
160
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
159
161
|
# @return [Boolean] If the target subscribes to the notification
|
|
160
|
-
def _subscribes_to_notification_email?(key, subscribe_as_default = ActivityNotification.config.
|
|
162
|
+
def _subscribes_to_notification_email?(key, subscribe_as_default = ActivityNotification.config.subscribe_to_email_as_default)
|
|
161
163
|
evaluate_subscription(subscriptions.where(key: key).first, :subscribing_to_email?, subscribe_as_default)
|
|
162
164
|
end
|
|
163
165
|
alias_method :_subscribes_to_email?, :_subscribes_to_notification_email?
|
|
@@ -170,7 +172,7 @@ module ActivityNotification
|
|
|
170
172
|
# @param [String, Symbol] optional_target_name Class name of the optional target implementation (e.g. :amazon_sns, :slack)
|
|
171
173
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
172
174
|
# @return [Boolean] If the target subscribes to the specified optional target
|
|
173
|
-
def _subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default = ActivityNotification.config.
|
|
175
|
+
def _subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_to_optional_targets_as_default)
|
|
174
176
|
_subscribes_to_notification?(key, subscribe_as_default) &&
|
|
175
177
|
evaluate_subscription(subscriptions.where(key: key).first, :subscribing_to_optional_target?, subscribe_as_default, optional_target_name, subscribe_as_default)
|
|
176
178
|
end
|
|
@@ -189,4 +191,4 @@ module ActivityNotification
|
|
|
189
191
|
end
|
|
190
192
|
|
|
191
193
|
end
|
|
192
|
-
end
|
|
194
|
+
end
|
|
@@ -49,22 +49,22 @@ module ActivityNotification
|
|
|
49
49
|
key :example, "Article"
|
|
50
50
|
end
|
|
51
51
|
property :group_id do
|
|
52
|
-
key :oneOf, [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
]
|
|
52
|
+
# key :oneOf, [
|
|
53
|
+
# { type: :integer },
|
|
54
|
+
# { type: :string },
|
|
55
|
+
# { nullable: true }
|
|
56
|
+
# ]
|
|
57
57
|
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
|
58
58
|
key :nullable, true
|
|
59
59
|
key :example, 11
|
|
60
60
|
end
|
|
61
61
|
property :group_owner_id do
|
|
62
|
-
key :oneOf, [
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
]
|
|
62
|
+
# key :oneOf, [
|
|
63
|
+
# { type: :integer },
|
|
64
|
+
# { type: :string },
|
|
65
|
+
# { type: :object },
|
|
66
|
+
# { nullable: true }
|
|
67
|
+
# ]
|
|
68
68
|
key :description, "This parameter type is integer with ActiveRecord, but will be string or object including $oid with Mongoid or Dynamoid ORMs."
|
|
69
69
|
key :nullable, true
|
|
70
70
|
key :example, 123
|
|
@@ -75,11 +75,11 @@ module ActivityNotification
|
|
|
75
75
|
key :example, "User"
|
|
76
76
|
end
|
|
77
77
|
property :notifier_id do
|
|
78
|
-
key :oneOf, [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
]
|
|
78
|
+
# key :oneOf, [
|
|
79
|
+
# { type: :integer },
|
|
80
|
+
# { type: :string },
|
|
81
|
+
# { nullable: true }
|
|
82
|
+
# ]
|
|
83
83
|
key :description, "This parameter type is integer with ActiveRecord, but will be string with Mongoid or Dynamoid ORMs."
|
|
84
84
|
key :nullable, true
|
|
85
85
|
key :example, 2
|
|
@@ -213,16 +213,12 @@ module ActivityNotification
|
|
|
213
213
|
resolve_value(_notification_action_cable_with_devise)
|
|
214
214
|
end
|
|
215
215
|
|
|
216
|
-
#
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
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
|
#
|
|
@@ -545,7 +541,7 @@ module ActivityNotification
|
|
|
545
541
|
# @param [String] key Key of the notification
|
|
546
542
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
547
543
|
# @return [Boolean] If the target subscribes the notification email or the subscription management is not allowed for the target
|
|
548
|
-
def subscribes_to_notification_email?(key, subscribe_as_default = ActivityNotification.config.
|
|
544
|
+
def subscribes_to_notification_email?(key, subscribe_as_default = ActivityNotification.config.subscribe_to_email_as_default)
|
|
549
545
|
!subscription_allowed?(key) || _subscribes_to_notification_email?(key, subscribe_as_default)
|
|
550
546
|
end
|
|
551
547
|
alias_method :subscribes_to_email?, :subscribes_to_notification_email?
|
|
@@ -557,7 +553,7 @@ module ActivityNotification
|
|
|
557
553
|
# @param [String, Symbol] optional_target_name Class name of the optional target implementation (e.g. :amazon_sns, :slack)
|
|
558
554
|
# @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
|
|
559
555
|
# @return [Boolean] If the target subscribes the notification email or the subscription management is not allowed for the target
|
|
560
|
-
def subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default = ActivityNotification.config.
|
|
556
|
+
def subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_to_optional_targets_as_default)
|
|
561
557
|
!subscription_allowed?(key) || _subscribes_to_optional_target?(key, optional_target_name, subscribe_as_default)
|
|
562
558
|
end
|
|
563
559
|
|
|
@@ -693,4 +689,4 @@ module ActivityNotification
|
|
|
693
689
|
end
|
|
694
690
|
|
|
695
691
|
end
|
|
696
|
-
end
|
|
692
|
+
end
|
|
@@ -23,14 +23,14 @@ module ActivityNotification
|
|
|
23
23
|
# Belongs to group instance of this notification as polymorphic association.
|
|
24
24
|
# @scope instance
|
|
25
25
|
# @return [Object] Group instance of this notification
|
|
26
|
-
belongs_to :group,
|
|
26
|
+
belongs_to :group, polymorphic: true, optional: true
|
|
27
27
|
|
|
28
28
|
# Belongs to group owner notification instance of this notification.
|
|
29
29
|
# Only group member instance has :group_owner value.
|
|
30
30
|
# Group owner instance has nil as :group_owner association.
|
|
31
31
|
# @scope instance
|
|
32
32
|
# @return [Notification] Group owner notification instance of this notification
|
|
33
|
-
belongs_to :group_owner,
|
|
33
|
+
belongs_to :group_owner, class_name: "ActivityNotification::Notification", optional: true
|
|
34
34
|
|
|
35
35
|
# Has many group member notification instances of this notification.
|
|
36
36
|
# Only group owner instance has :group_members value.
|
|
@@ -42,7 +42,7 @@ module ActivityNotification
|
|
|
42
42
|
# Belongs to :notifier instance of this notification.
|
|
43
43
|
# @scope instance
|
|
44
44
|
# @return [Object] Notifier instance of this notification
|
|
45
|
-
belongs_to :notifier,
|
|
45
|
+
belongs_to :notifier, polymorphic: true, optional: true
|
|
46
46
|
|
|
47
47
|
# Serialize parameters Hash
|
|
48
48
|
serialize :parameters, Hash
|
|
@@ -6,7 +6,7 @@ module ActivityNotification
|
|
|
6
6
|
# Defines has_many association with ActivityNotification models.
|
|
7
7
|
# @return [ActiveRecord_AssociationRelation<Object>] Database query of associated model instances
|
|
8
8
|
def has_many_records(name, options = {})
|
|
9
|
-
has_many name, options
|
|
9
|
+
has_many name, **options
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -42,7 +42,7 @@ module ActivityNotification
|
|
|
42
42
|
# Group owner instance has nil as :group_owner association.
|
|
43
43
|
# @scope instance
|
|
44
44
|
# @return [Notification] Group owner notification instance of this notification
|
|
45
|
-
belongs_to :group_owner, { class_name: "ActivityNotification::Notification", foreign_key: :group_owner_id
|
|
45
|
+
belongs_to :group_owner, { class_name: "ActivityNotification::Notification", foreign_key: :group_owner_id, optional: true }
|
|
46
46
|
|
|
47
47
|
# Customized method that belongs to group owner notification instance of this notification.
|
|
48
48
|
# @raise [Errors::RecordNotFound] Record not found error
|
|
@@ -21,7 +21,7 @@ module ActivityNotification
|
|
|
21
21
|
|
|
22
22
|
field :key, :string
|
|
23
23
|
field :subscribing, :boolean, default: ActivityNotification.config.subscribe_as_default
|
|
24
|
-
field :subscribing_to_email, :boolean, default: ActivityNotification.config.
|
|
24
|
+
field :subscribing_to_email, :boolean, default: ActivityNotification.config.subscribe_to_email_as_default
|
|
25
25
|
field :subscribed_at, :datetime
|
|
26
26
|
field :unsubscribed_at, :datetime
|
|
27
27
|
field :subscribed_to_email_at, :datetime
|
|
@@ -41,7 +41,7 @@ module ActivityNotification
|
|
|
41
41
|
# Group owner instance has nil as :group_owner association.
|
|
42
42
|
# @scope instance
|
|
43
43
|
# @return [Notification] Group owner notification instance of this notification
|
|
44
|
-
belongs_to :group_owner, { class_name: "ActivityNotification::Notification"
|
|
44
|
+
belongs_to :group_owner, { class_name: "ActivityNotification::Notification", optional: true }
|
|
45
45
|
|
|
46
46
|
# Has many group member notification instances of this notification.
|
|
47
47
|
# Only group owner instance has :group_members value.
|
|
@@ -20,7 +20,7 @@ module ActivityNotification
|
|
|
20
20
|
|
|
21
21
|
field :key, type: String
|
|
22
22
|
field :subscribing, type: Boolean, default: ActivityNotification.config.subscribe_as_default
|
|
23
|
-
field :subscribing_to_email, type: Boolean, default: ActivityNotification.config.
|
|
23
|
+
field :subscribing_to_email, type: Boolean, default: ActivityNotification.config.subscribe_to_email_as_default
|
|
24
24
|
field :subscribed_at, type: DateTime
|
|
25
25
|
field :unsubscribed_at, type: DateTime
|
|
26
26
|
field :subscribed_to_email_at, type: DateTime
|
|
@@ -29,8 +29,8 @@ module ActivityNotification
|
|
|
29
29
|
)
|
|
30
30
|
|
|
31
31
|
# Generate the :default fallback key without using pluralization key :count
|
|
32
|
-
default = I18n.t(k, attrs)
|
|
33
|
-
I18n.t(k, attrs.merge(count: group_notification_count, default: default))
|
|
32
|
+
default = I18n.t(k, **attrs)
|
|
33
|
+
I18n.t(k, **attrs.merge(count: group_notification_count, default: default))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# Renders notification from views.
|
|
@@ -239,25 +239,21 @@ module ActivityNotification
|
|
|
239
239
|
configured_params.update(add_destroy_dependency(target_type, options[:dependent_notifications]))
|
|
240
240
|
end
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
unless options[:optional_targets].has_key?(ActivityNotification::OptionalTarget::ActionCableChannel)
|
|
248
|
-
options[:optional_targets][ActivityNotification::OptionalTarget::ActionCableChannel] = {}
|
|
249
|
-
end
|
|
242
|
+
if options[:action_cable_allowed] || (ActivityNotification.config.action_cable_enabled && options[:action_cable_allowed] != false)
|
|
243
|
+
options[:optional_targets] ||= {}
|
|
244
|
+
require 'activity_notification/optional_targets/action_cable_channel'
|
|
245
|
+
unless options[:optional_targets].has_key?(ActivityNotification::OptionalTarget::ActionCableChannel)
|
|
246
|
+
options[:optional_targets][ActivityNotification::OptionalTarget::ActionCableChannel] = {}
|
|
250
247
|
end
|
|
248
|
+
end
|
|
251
249
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
end
|
|
250
|
+
if options[:action_cable_api_allowed] || (ActivityNotification.config.action_cable_api_enabled && options[:action_cable_api_allowed] != false)
|
|
251
|
+
options[:optional_targets] ||= {}
|
|
252
|
+
require 'activity_notification/optional_targets/action_cable_api_channel'
|
|
253
|
+
unless options[:optional_targets].has_key?(ActivityNotification::OptionalTarget::ActionCableApiChannel)
|
|
254
|
+
options[:optional_targets][ActivityNotification::OptionalTarget::ActionCableApiChannel] = {}
|
|
258
255
|
end
|
|
259
256
|
end
|
|
260
|
-
# :nocov:
|
|
261
257
|
|
|
262
258
|
if options[:optional_targets].is_a?(Hash)
|
|
263
259
|
options[:optional_targets] = arrange_optional_targets_option(options[:optional_targets])
|
|
@@ -31,6 +31,16 @@ ActivityNotification.configure do |config|
|
|
|
31
31
|
# Set false when you want to unsubscribe to any notifications as default.
|
|
32
32
|
config.subscribe_as_default = true
|
|
33
33
|
|
|
34
|
+
# Configure default email subscription value to use when the subscription record does not configured.
|
|
35
|
+
# Note that you can configure them for each method calling as default argument.
|
|
36
|
+
# Set false when you want to unsubscribe to email notifications as default.
|
|
37
|
+
# config.subscribe_to_email_as_default = true
|
|
38
|
+
|
|
39
|
+
# Configure default optional target subscription value to use when the subscription record does not configured.
|
|
40
|
+
# Note that you can configure them for each method calling as default argument.
|
|
41
|
+
# Set false when you want to unsubscribe to optinal target notifications as default.
|
|
42
|
+
# config.subscribe_to_optional_targets_as_default = true
|
|
43
|
+
|
|
34
44
|
# Configure the e-mail address which will be shown in ActivityNotification::Mailer,
|
|
35
45
|
# note that it will be overwritten if you use your own mailer class with default "from" parameter.
|
|
36
46
|
config.mailer_sender = 'please-change-me-at-config-initializers-activity_notification@example.com'
|
|
@@ -76,7 +86,7 @@ ActivityNotification.configure do |config|
|
|
|
76
86
|
# Set true when you want to turn on WebSocket API subscription using ActionCable as default.
|
|
77
87
|
config.action_cable_api_enabled = false
|
|
78
88
|
|
|
79
|
-
# Configure if
|
|
89
|
+
# Configure if activity_notification publishes WebSocket notifications using ActionCable only to authenticated target with Devise.
|
|
80
90
|
# Note that you can configure them for each model by acts_as roles.
|
|
81
91
|
# Set true when you want to use Device integration with WebSocket subscription using ActionCable as default.
|
|
82
92
|
config.action_cable_with_devise = false
|
|
@@ -87,4 +97,8 @@ ActivityNotification.configure do |config|
|
|
|
87
97
|
# Configure notification API channel prefix for ActionCable.
|
|
88
98
|
config.notification_api_channel_prefix = 'activity_notification_api_channel'
|
|
89
99
|
|
|
100
|
+
# Configure if activity_notification internally rescues optional target errors. Default value is true.
|
|
101
|
+
# See https://github.com/simukappu/activity_notification/issues/155 for more details.
|
|
102
|
+
config.rescue_optional_target_errors = true
|
|
103
|
+
|
|
90
104
|
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Migration responsible for creating a table with notifications
|
|
2
|
-
class <%= @migration_name %> < ActiveRecord::Migration<%=
|
|
2
|
+
class <%= @migration_name %> < ActiveRecord::Migration<%= "[#{Rails.version.to_f}]" %>
|
|
3
3
|
# Create tables
|
|
4
4
|
def change
|
|
5
5
|
<% if @migration_tables.include?('notifications') %>create_table :notifications do |t|
|
|
@@ -1,51 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
User._notification_action_cable_with_devise = true
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
after do
|
|
18
|
-
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
it "rejects subscription even if target_type and target_id parameters are passed" do
|
|
22
|
-
subscribe({ target_type: target_type, target_id: test_target.id })
|
|
23
|
-
expect(subscription).to be_rejected
|
|
24
|
-
expect {
|
|
25
|
-
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
26
|
-
}.to raise_error(/Must be subscribed!/)
|
|
27
|
-
end
|
|
1
|
+
require 'channels/notification_api_channel_shared_examples'
|
|
2
|
+
|
|
3
|
+
# @See https://github.com/palkan/action-cable-testing
|
|
4
|
+
describe ActivityNotification::NotificationApiChannel, type: :channel do
|
|
5
|
+
let(:test_target) { create(:user) }
|
|
6
|
+
let(:target_type) { "User" }
|
|
7
|
+
let(:typed_target_param) { "user_id" }
|
|
8
|
+
let(:extra_params) { {} }
|
|
9
|
+
|
|
10
|
+
context "when target.notification_action_cable_with_devise? returns true" do
|
|
11
|
+
before do
|
|
12
|
+
@user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
|
|
13
|
+
User._notification_action_cable_with_devise = true
|
|
28
14
|
end
|
|
29
15
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
User._notification_action_cable_with_devise = false
|
|
34
|
-
@auth_headers = {}
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
after do
|
|
38
|
-
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
39
|
-
end
|
|
16
|
+
after do
|
|
17
|
+
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
18
|
+
end
|
|
40
19
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
20
|
+
it "rejects subscription even if target_type and target_id parameters are passed" do
|
|
21
|
+
subscribe({ target_type: target_type, target_id: test_target.id })
|
|
22
|
+
expect(subscription).to be_rejected
|
|
23
|
+
expect {
|
|
44
24
|
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
45
|
-
|
|
46
|
-
|
|
25
|
+
}.to raise_error(/Must be subscribed!/)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
47
28
|
|
|
48
|
-
|
|
29
|
+
context "when target.notification_action_cable_with_devise? returns false" do
|
|
30
|
+
before do
|
|
31
|
+
@user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
|
|
32
|
+
User._notification_action_cable_with_devise = false
|
|
33
|
+
@auth_headers = {}
|
|
49
34
|
end
|
|
35
|
+
|
|
36
|
+
after do
|
|
37
|
+
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "successfully subscribes with target_type and target_id parameters" do
|
|
41
|
+
subscribe({ target_type: target_type, target_id: test_target.id })
|
|
42
|
+
expect(subscription).to be_confirmed
|
|
43
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
44
|
+
expect(subscription).to have_stream_from("activity_notification_api_channel_User##{test_target.id}")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it_behaves_like :notification_api_channel
|
|
50
48
|
end
|
|
51
|
-
end
|
|
49
|
+
end
|
|
@@ -1,78 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
require 'channels/notification_api_channel_shared_examples'
|
|
1
|
+
require 'channels/notification_api_channel_shared_examples'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
# @See https://github.com/palkan/action-cable-testing
|
|
4
|
+
describe ActivityNotification::NotificationApiWithDeviseChannel, type: :channel do
|
|
5
|
+
let(:test_user) { create(:confirmed_user) }
|
|
6
|
+
let(:unauthenticated_user) { create(:confirmed_user) }
|
|
7
|
+
let(:test_target) { create(:admin, user: test_user) }
|
|
8
|
+
let(:target_type) { "Admin" }
|
|
9
|
+
let(:typed_target_param) { "admin_id" }
|
|
10
|
+
let(:extra_params) { { devise_type: :users } }
|
|
11
|
+
let(:valid_session) {}
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
# @See https://github.com/lynndylanhurley/devise_token_auth
|
|
14
|
+
def sign_in(current_target)
|
|
15
|
+
@auth_headers = current_target.create_new_auth_token
|
|
16
|
+
end
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
before do
|
|
19
|
+
@user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
|
|
20
|
+
User._notification_action_cable_with_devise = true
|
|
21
|
+
end
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
after do
|
|
24
|
+
User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
|
|
25
|
+
end
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it_behaves_like :notification_api_channel
|
|
27
|
+
context "signed in with devise as authenticated user" do
|
|
28
|
+
before do
|
|
29
|
+
sign_in test_user
|
|
34
30
|
end
|
|
31
|
+
|
|
32
|
+
it_behaves_like :notification_api_channel
|
|
33
|
+
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
context "signed in with devise as unauthenticated user" do
|
|
36
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
before do
|
|
39
|
+
sign_in unauthenticated_user
|
|
40
|
+
end
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
42
|
+
it "rejects subscription" do
|
|
43
|
+
subscribe(target_params.merge({ typed_target_param => test_target }).merge(@auth_headers))
|
|
44
|
+
expect(subscription).to be_rejected
|
|
45
|
+
expect {
|
|
46
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
47
|
+
}.to raise_error(/Must be subscribed!/)
|
|
50
48
|
end
|
|
49
|
+
end
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
context "unsigned in with devise" do
|
|
52
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
end
|
|
54
|
+
it "rejects subscription" do
|
|
55
|
+
subscribe(target_params.merge({ typed_target_param => test_target }))
|
|
56
|
+
expect(subscription).to be_rejected
|
|
57
|
+
expect {
|
|
58
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
59
|
+
}.to raise_error(/Must be subscribed!/)
|
|
62
60
|
end
|
|
61
|
+
end
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
context "without target_id and (typed_target)_id parameters for devise integrated channel with devise_type option" do
|
|
64
|
+
let(:target_params) { { target_type: target_type, devise_type: :users } }
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
before do
|
|
67
|
+
sign_in test_target.user
|
|
68
|
+
end
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
end
|
|
70
|
+
it "successfully subscribes" do
|
|
71
|
+
subscribe(target_params.merge(@auth_headers))
|
|
72
|
+
expect(subscription).to have_stream_from("#{ActivityNotification.config.notification_api_channel_prefix}_#{test_target.to_class_name}#{ActivityNotification.config.composite_key_delimiter}#{test_target.id}")
|
|
73
|
+
expect(subscription).to have_stream_from("activity_notification_api_channel_Admin##{test_target.id}")
|
|
76
74
|
end
|
|
77
75
|
end
|
|
78
76
|
end
|