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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -16
  3. data/CHANGELOG.md +14 -0
  4. data/README.md +1 -1
  5. data/activity_notification.gemspec +1 -1
  6. data/app/controllers/activity_notification/notifications_controller.rb +0 -20
  7. data/bin/bundle_update.sh +0 -1
  8. data/lib/activity_notification/common.rb +11 -3
  9. data/lib/activity_notification/controllers/common_controller.rb +1 -17
  10. data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
  11. data/lib/activity_notification/models/concerns/target.rb +5 -9
  12. data/lib/activity_notification/orm/active_record.rb +1 -1
  13. data/lib/activity_notification/orm/active_record/notification.rb +3 -3
  14. data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
  15. data/lib/activity_notification/orm/mongoid/notification.rb +1 -1
  16. data/lib/activity_notification/renderable.rb +2 -2
  17. data/lib/activity_notification/roles/acts_as_notifiable.rb +11 -15
  18. data/lib/activity_notification/version.rb +1 -1
  19. data/lib/generators/templates/migrations/migration.rb +1 -1
  20. data/spec/channels/notification_api_channel_spec.rb +42 -44
  21. data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
  22. data/spec/channels/notification_channel_spec.rb +41 -43
  23. data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
  24. data/spec/concerns/common_spec.rb +25 -3
  25. data/spec/concerns/models/target_spec.rb +10 -12
  26. data/spec/concerns/renderable_spec.rb +5 -5
  27. data/spec/controllers/controller_spec_utility.rb +15 -51
  28. data/spec/generators/migration/migration_generator_spec.rb +2 -10
  29. data/spec/helpers/view_helpers_spec.rb +1 -1
  30. data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
  31. data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
  32. data/spec/rails_app/config/application.rb +2 -6
  33. data/spec/rails_app/config/environments/test.rb +2 -11
  34. data/spec/spec_helper.rb +1 -5
  35. metadata +5 -8
  36. data/gemfiles/Gemfile.rails-4.2 +0 -24
  37. 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: c77b0e25a955b70ea7753d4591e26eebaa5d8ac3ebd858fc0dbb1457a1443543
4
- data.tar.gz: c3f39d43832aca955a9904cc9918ba247bc34b32fb5b9e2a99efdd11fb04fea5
3
+ metadata.gz: 771b080e7877b6a83105bc0f8842440fc4f2a12c0fa56b6e55f4d2b24b3e9d20
4
+ data.tar.gz: 2b8dcbeb13208ef8a44e3fa246ac464f1e36c8140cc1e087ebc6b39e55da1107
5
5
  SHA512:
6
- metadata.gz: 4ff3b5496a2f94cdc794c5fac124cdeb749738eb3b244f58e4622882dfbfdcddeb35518f41d7f801ad0f4c47d8695cc4c157e6d4244ae394fc2797f08f20a826
7
- data.tar.gz: 93cf90f670ebca89d40812870f2e4ad526f5f373609a56ece0199ef50f63383204bd624a1e3af3ac65f31d431494fdac19a7c5b1bc62887fd20c961a3cb8daa2
6
+ metadata.gz: e573698b449a5aef558b312c4fd0a7023d28adf2ab4210f941efc6a3025c4126cf4428ca561addf760e4e6a875696ffe6ba06d0bc0501007f663f4e59f3c0a07
7
+ data.tar.gz: 7c8d4771871af1dedd7440fcb670b9a50b5820fa9f09e3be5df9d2f6618002174dfaf00d7f71f6e725aecc28267b8a2263050ecbed662d3c6038a7dabd9383fe
@@ -5,14 +5,13 @@ branches:
5
5
  - images
6
6
 
7
7
  rvm:
8
- # - 2.7.0 # Need to respond to warnings for Ruby 3.0
9
- - 2.6.5
10
- # - 2.5.7
11
- # - 2.4.9
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
- # Specify bundler version as '< 2.0' for Rails 4.2
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
- # Specify bundler version as '< 2.0' for Rails 4.2
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
@@ -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 4.2+ 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. The latest *activity_notification* [v2](https://rubygems.org/gems/activity_notification) is almost compatible with [v1](https://rubygems.org/gems/activity_notification/versions/1.7.1).
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', '>= 4.2.0', '< 6.1'
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.
@@ -1,7 +1,6 @@
1
1
  #!/bin/bash
2
2
 
3
3
  bundle update
4
- BUNDLE_GEMFILE=gemfiles/Gemfile.rails-4.2 bundle update
5
4
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.0 bundle update
6
5
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.1 bundle update
7
6
  BUNDLE_GEMFILE=gemfiles/Gemfile.rails-5.2 bundle update
@@ -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
@@ -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
- 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
@@ -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 }
@@ -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
  #
@@ -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 }.merge(Rails::VERSION::MAJOR >= 5 ? { optional: 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" }.merge(Rails::VERSION::MAJOR >= 5 ? { optional: true } : {})
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 }.merge(Rails::VERSION::MAJOR >= 5 ? { optional: 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 }.merge(Rails::VERSION::MAJOR >= 5 ? { optional: true } : {})
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" }.merge(Rails::VERSION::MAJOR >= 5 ? { optional: true } : {})
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
- # :nocov:
243
- if Rails::VERSION::MAJOR >= 5
244
- if options[:action_cable_allowed] || (ActivityNotification.config.action_cable_enabled && options[:action_cable_allowed] != false)
245
- options[:optional_targets] ||= {}
246
- require 'activity_notification/optional_targets/action_cable_channel'
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
- if options[:action_cable_api_allowed] || (ActivityNotification.config.action_cable_api_enabled && options[:action_cable_api_allowed] != false)
253
- options[:optional_targets] ||= {}
254
- require 'activity_notification/optional_targets/action_cable_api_channel'
255
- unless options[:optional_targets].has_key?(ActivityNotification::OptionalTarget::ActionCableApiChannel)
256
- options[:optional_targets][ActivityNotification::OptionalTarget::ActionCableApiChannel] = {}
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,3 +1,3 @@
1
1
  module ActivityNotification
2
- VERSION = "2.1.4"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # Migration responsible for creating a table with notifications
2
- class <%= @migration_name %> < ActiveRecord::Migration<%= Rails::VERSION::MAJOR >= 5 ? "[#{Rails.version.to_f}]" : "" %>
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
- if Rails::VERSION::MAJOR >= 5
2
- require 'channels/notification_api_channel_shared_examples'
3
-
4
- # @See https://github.com/palkan/action-cable-testing
5
- describe ActivityNotification::NotificationApiChannel, type: :channel do
6
- let(:test_target) { create(:user) }
7
- let(:target_type) { "User" }
8
- let(:typed_target_param) { "user_id" }
9
- let(:extra_params) { {} }
10
-
11
- context "when target.notification_action_cable_with_devise? returns true" do
12
- before do
13
- @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
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
- context "when target.notification_action_cable_with_devise? returns false" do
31
- before do
32
- @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
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
- it "successfully subscribes with target_type and target_id parameters" do
42
- subscribe({ target_type: target_type, target_id: test_target.id })
43
- expect(subscription).to be_confirmed
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
- expect(subscription).to have_stream_from("activity_notification_api_channel_User##{test_target.id}")
46
- end
25
+ }.to raise_error(/Must be subscribed!/)
26
+ end
27
+ end
47
28
 
48
- it_behaves_like :notification_api_channel
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
- if Rails::VERSION::MAJOR >= 5
2
- require 'channels/notification_api_channel_shared_examples'
1
+ require 'channels/notification_api_channel_shared_examples'
3
2
 
4
- # @See https://github.com/palkan/action-cable-testing
5
- describe ActivityNotification::NotificationApiWithDeviseChannel, type: :channel do
6
- let(:test_user) { create(:confirmed_user) }
7
- let(:unauthenticated_user) { create(:confirmed_user) }
8
- let(:test_target) { create(:admin, user: test_user) }
9
- let(:target_type) { "Admin" }
10
- let(:typed_target_param) { "admin_id" }
11
- let(:extra_params) { { devise_type: :users } }
12
- let(:valid_session) {}
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
- # @See https://github.com/lynndylanhurley/devise_token_auth
15
- def sign_in(current_target)
16
- @auth_headers = current_target.create_new_auth_token
17
- end
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
- before do
20
- @user_notification_action_cable_with_devise = User._notification_action_cable_with_devise
21
- User._notification_action_cable_with_devise = true
22
- end
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
- after do
25
- User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
26
- end
23
+ after do
24
+ User._notification_action_cable_with_devise = @user_notification_action_cable_with_devise
25
+ end
27
26
 
28
- context "signed in with devise as authenticated user" do
29
- before do
30
- sign_in test_user
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
- context "signed in with devise as unauthenticated user" do
37
- let(:target_params) { { target_type: target_type, devise_type: :users } }
35
+ context "signed in with devise as unauthenticated user" do
36
+ let(:target_params) { { target_type: target_type, devise_type: :users } }
38
37
 
39
- before do
40
- sign_in unauthenticated_user
41
- end
38
+ before do
39
+ sign_in unauthenticated_user
40
+ end
42
41
 
43
- it "rejects subscription" do
44
- subscribe(target_params.merge({ typed_target_param => test_target }).merge(@auth_headers))
45
- expect(subscription).to be_rejected
46
- expect {
47
- 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}")
48
- }.to raise_error(/Must be subscribed!/)
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
- context "unsigned in with devise" do
53
- let(:target_params) { { target_type: target_type, devise_type: :users } }
51
+ context "unsigned in with devise" do
52
+ let(:target_params) { { target_type: target_type, devise_type: :users } }
54
53
 
55
- it "rejects subscription" do
56
- subscribe(target_params.merge({ typed_target_param => test_target }))
57
- expect(subscription).to be_rejected
58
- expect {
59
- 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}")
60
- }.to raise_error(/Must be subscribed!/)
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
- context "without target_id and (typed_target)_id parameters for devise integrated channel with devise_type option" do
65
- let(:target_params) { { target_type: target_type, devise_type: :users } }
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
- before do
68
- sign_in test_target.user
69
- end
66
+ before do
67
+ sign_in test_target.user
68
+ end
70
69
 
71
- it "successfully subscribes" do
72
- subscribe(target_params.merge(@auth_headers))
73
- 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}")
74
- expect(subscription).to have_stream_from("activity_notification_api_channel_Admin##{test_target.id}")
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