activity_notification 2.1.4 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -16
- data/CHANGELOG.md +14 -0
- data/README.md +1 -1
- data/activity_notification.gemspec +1 -1
- data/app/controllers/activity_notification/notifications_controller.rb +0 -20
- data/bin/bundle_update.sh +0 -1
- data/lib/activity_notification/common.rb +11 -3
- 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/target.rb +5 -9
- data/lib/activity_notification/orm/active_record.rb +1 -1
- data/lib/activity_notification/orm/active_record/notification.rb +3 -3
- data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
- data/lib/activity_notification/orm/mongoid/notification.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/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/common_spec.rb +25 -3
- 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/environments/test.rb +2 -11
- data/spec/spec_helper.rb +1 -5
- metadata +5 -8
- data/gemfiles/Gemfile.rails-4.2 +0 -24
- data/spec/support/patch_rails_42_action_controller_test_response.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 771b080e7877b6a83105bc0f8842440fc4f2a12c0fa56b6e55f4d2b24b3e9d20
|
4
|
+
data.tar.gz: 2b8dcbeb13208ef8a44e3fa246ac464f1e36c8140cc1e087ebc6b39e55da1107
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e573698b449a5aef558b312c4fd0a7023d28adf2ab4210f941efc6a3025c4126cf4428ca561addf760e4e6a875696ffe6ba06d0bc0501007f663f4e59f3c0a07
|
7
|
+
data.tar.gz: 7c8d4771871af1dedd7440fcb670b9a50b5820fa9f09e3be5df9d2f6618002174dfaf00d7f71f6e725aecc28267b8a2263050ecbed662d3c6038a7dabd9383fe
|
data/.travis.yml
CHANGED
@@ -5,14 +5,13 @@ branches:
|
|
5
5
|
- images
|
6
6
|
|
7
7
|
rvm:
|
8
|
-
|
9
|
-
- 2.6.
|
10
|
-
# - 2.5.
|
11
|
-
# - 2.4.
|
8
|
+
- 2.7.2
|
9
|
+
# - 2.6.6
|
10
|
+
# - 2.5.8
|
11
|
+
# - 2.4.10 #EOL
|
12
12
|
# - 2.3.8 #EOL
|
13
13
|
|
14
14
|
gemfile:
|
15
|
-
- gemfiles/Gemfile.rails-4.2
|
16
15
|
- gemfiles/Gemfile.rails-5.0
|
17
16
|
- gemfiles/Gemfile.rails-5.1
|
18
17
|
- gemfiles/Gemfile.rails-5.2
|
@@ -27,9 +26,6 @@ env:
|
|
27
26
|
- AN_ORM=dynamoid
|
28
27
|
|
29
28
|
matrix:
|
30
|
-
exclude:
|
31
|
-
- gemfile: gemfiles/Gemfile.rails-4.2
|
32
|
-
env: AN_ORM=dynamoid
|
33
29
|
include:
|
34
30
|
- rvm: ruby-head
|
35
31
|
gemfile: Gemfile
|
@@ -53,18 +49,12 @@ sudo: false
|
|
53
49
|
|
54
50
|
cache: bundler
|
55
51
|
|
56
|
-
before_install:
|
57
|
-
# Specify bundler version as '< 2.0' for Rails 4.2
|
58
|
-
- gem install bundler --no-document -v '1.17.3'
|
59
|
-
|
60
52
|
install:
|
61
|
-
|
62
|
-
- bundle _1.17.3_ install
|
53
|
+
- bundle install
|
63
54
|
- if [ "$AN_ORM" = "dynamoid" ]; then bin/install_dynamodblocal.sh; fi
|
64
55
|
|
65
56
|
before_script:
|
66
|
-
|
67
|
-
- bundle _1.17.3_ update
|
57
|
+
- bundle update
|
68
58
|
- if [ "$AN_TEST_DB" = "mysql" ]; then mysql -e 'create database activity_notification_test'; fi
|
69
59
|
- if [ "$AN_TEST_DB" = "postgresql" ]; then psql -c 'create database activity_notification_test' -U postgres; fi
|
70
60
|
- if [ "$AN_ORM" = "dynamoid" ]; then bin/start_dynamodblocal.sh; fi
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## 2.2.0 / 2020-12-05
|
2
|
+
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.4...v2.2.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Remove support for Rails 4.2 - [#151](https://github.com/simukappu/activity_notification/issues/151)
|
7
|
+
* Turn on deprecation warnings in RSpec testing for Ruby 2.7 - [#122](https://github.com/simukappu/activity_notification/issues/122)
|
8
|
+
* Remove Ruby 2.7 deprecation warnings - [#122](https://github.com/simukappu/activity_notification/issues/122)
|
9
|
+
|
10
|
+
Breaking Changes:
|
11
|
+
|
12
|
+
* Specify DynamoDB global secondary index name
|
13
|
+
* Update additional fields to store into DynamoDB when *config.store_with_associated_records* is true
|
14
|
+
|
1
15
|
## 2.1.4 / 2020-11-07
|
2
16
|
[Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.3...v2.1.4)
|
3
17
|
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
|
11
11
|
*activity_notification* provides integrated user activity notifications for [Ruby on Rails](https://rubyonrails.org). 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
|
13
|
+
*activity_notification* supports Rails 5.0+ with [ActiveRecord](https://guides.rubyonrails.org/active_record_basics.html), [Mongoid](https://mongoid.org) and [Dynamoid](https://github.com/Dynamoid/dynamoid) ORM. It is tested for [MySQL](https://www.mysql.com), [PostgreSQL](https://www.postgresql.org), [SQLite3](https://www.sqlite.org) with ActiveRecord, [MongoDB](https://www.mongodb.com) with Mongoid and [Amazon DynamoDB](https://aws.amazon.com/dynamodb) with Dynamoid. If you are using Rails 4.2, use [v2.1.4](https://rubygems.org/gems/activity_notification/versions/2.1.4) or older version of *activity_notification*.
|
14
14
|
|
15
15
|
|
16
16
|
## About
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
s.required_ruby_version = '>= 2.1.0'
|
22
22
|
|
23
|
-
s.add_dependency 'railties', '>=
|
23
|
+
s.add_dependency 'railties', '>= 5.0.0', '< 6.1'
|
24
24
|
s.add_dependency 'i18n', '>= 0.5.0'
|
25
25
|
s.add_dependency 'jquery-rails', '>= 3.1.1'
|
26
26
|
s.add_dependency 'swagger-blocks', '>= 3.0.0'
|
@@ -117,26 +117,6 @@ module ActivityNotification
|
|
117
117
|
super
|
118
118
|
end
|
119
119
|
|
120
|
-
# :nocov:
|
121
|
-
if Rails::VERSION::MAJOR == 4
|
122
|
-
# Defines custom renderer class method for Rails 4.2
|
123
|
-
def self.renderer
|
124
|
-
view_context = ActionView::Base.new(ActionController::Base.view_paths, {})
|
125
|
-
view_context.class_eval do
|
126
|
-
include Rails.application.routes.url_helpers
|
127
|
-
def default_url_options
|
128
|
-
ActionMailer::Base.default_url_options
|
129
|
-
end
|
130
|
-
def render(params = {})
|
131
|
-
assign(params[:assigns])
|
132
|
-
super(params)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
view_context
|
136
|
-
end
|
137
|
-
end
|
138
|
-
# :nocov:
|
139
|
-
|
140
120
|
protected
|
141
121
|
|
142
122
|
# Sets @notification instance variable from request parameters.
|
data/bin/bundle_update.sh
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
@@ -131,4 +139,4 @@ module ActivityNotification
|
|
131
139
|
"#{self.printable_type} (#{id})"
|
132
140
|
end
|
133
141
|
end
|
134
|
-
end
|
142
|
+
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
|
-
|
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
|
@@ -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 }
|
@@ -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
|
#
|
@@ -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
|
@@ -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, { polymorphic: true
|
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, { class_name: "ActivityNotification::Notification"
|
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, { polymorphic: true
|
45
|
+
belongs_to :notifier, **{ polymorphic: true, optional: true }
|
46
46
|
|
47
47
|
# Serialize parameters Hash
|
48
48
|
serialize :parameters, Hash
|
@@ -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
|
@@ -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.
|
@@ -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])
|
@@ -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
|