activity_notification 2.1.4 → 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +120 -0
  3. data/CHANGELOG.md +38 -0
  4. data/README.md +2 -2
  5. data/activity_notification.gemspec +1 -1
  6. data/app/controllers/activity_notification/notifications_controller.rb +0 -20
  7. data/app/controllers/activity_notification/subscriptions_controller.rb +2 -2
  8. data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
  9. data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +2 -2
  10. data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +2 -2
  11. data/app/views/activity_notification/subscriptions/default/index.html.erb +2 -2
  12. data/app/views/activity_notification/subscriptions/default/show.html.erb +2 -2
  13. data/bin/bundle_update.sh +0 -1
  14. data/docs/Functions.md +17 -1
  15. data/gemfiles/{Gemfile.rails-4.2 → Gemfile.rails-6.1} +2 -4
  16. data/gemfiles/Gemfile.rails-7.0 +28 -0
  17. data/lib/activity_notification/apis/notification_api.rb +5 -1
  18. data/lib/activity_notification/apis/subscription_api.rb +5 -5
  19. data/lib/activity_notification/common.rb +11 -3
  20. data/lib/activity_notification/config.rb +63 -23
  21. data/lib/activity_notification/controllers/common_controller.rb +1 -17
  22. data/lib/activity_notification/models/concerns/notifiable.rb +1 -1
  23. data/lib/activity_notification/models/concerns/subscriber.rb +6 -4
  24. data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +16 -16
  25. data/lib/activity_notification/models/concerns/target.rb +8 -12
  26. data/lib/activity_notification/orm/active_record/notification.rb +3 -3
  27. data/lib/activity_notification/orm/active_record.rb +1 -1
  28. data/lib/activity_notification/orm/dynamoid/notification.rb +1 -1
  29. data/lib/activity_notification/orm/dynamoid/subscription.rb +1 -1
  30. data/lib/activity_notification/orm/mongoid/notification.rb +1 -1
  31. data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
  32. data/lib/activity_notification/renderable.rb +2 -2
  33. data/lib/activity_notification/roles/acts_as_notifiable.rb +11 -15
  34. data/lib/activity_notification/version.rb +1 -1
  35. data/lib/generators/templates/activity_notification.rb +15 -1
  36. data/lib/generators/templates/migrations/migration.rb +1 -1
  37. data/spec/channels/notification_api_channel_spec.rb +42 -44
  38. data/spec/channels/notification_api_with_devise_channel_spec.rb +57 -59
  39. data/spec/channels/notification_channel_spec.rb +41 -43
  40. data/spec/channels/notification_with_devise_channel_spec.rb +75 -77
  41. data/spec/concerns/apis/notification_api_spec.rb +26 -3
  42. data/spec/concerns/apis/subscription_api_spec.rb +144 -2
  43. data/spec/concerns/common_spec.rb +25 -3
  44. data/spec/concerns/models/subscriber_spec.rb +179 -6
  45. data/spec/concerns/models/target_spec.rb +10 -12
  46. data/spec/concerns/renderable_spec.rb +5 -5
  47. data/spec/controllers/controller_spec_utility.rb +15 -51
  48. data/spec/generators/migration/migration_generator_spec.rb +2 -10
  49. data/spec/helpers/view_helpers_spec.rb +1 -1
  50. data/spec/optional_targets/action_cable_api_channel_spec.rb +21 -24
  51. data/spec/optional_targets/action_cable_channel_spec.rb +26 -29
  52. data/spec/rails_app/config/application.rb +2 -6
  53. data/spec/rails_app/config/database.yml +1 -1
  54. data/spec/rails_app/config/environments/test.rb +2 -11
  55. data/spec/rails_app/config/initializers/activity_notification.rb +14 -0
  56. data/spec/rails_app/package.json +14 -14
  57. data/spec/spec_helper.rb +1 -5
  58. metadata +13 -14
  59. data/.travis.yml +0 -76
  60. 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: 30c5b3d148d4606e3ebd7c26a14a746180f2ccde5c6197bf28c95aaeceba8d48
4
+ data.tar.gz: 63454217d875157c64d22dd0e15e947912a73d7f6a1bba371cba05a0973ba680
5
5
  SHA512:
6
- metadata.gz: 4ff3b5496a2f94cdc794c5fac124cdeb749738eb3b244f58e4622882dfbfdcddeb35518f41d7f801ad0f4c47d8695cc4c157e6d4244ae394fc2797f08f20a826
7
- data.tar.gz: 93cf90f670ebca89d40812870f2e4ad526f5f373609a56ece0199ef50f63383204bd624a1e3af3ac65f31d431494fdac19a7c5b1bc62887fd20c961a3cb8daa2
6
+ metadata.gz: 2c7c724cdf1acb560ed8d02c56f80bc5cddee91fc0537779480efae64a40108f14fdcd55850ca121bf766416dad818dc664bdad196c17ef6ebe38d31c18ed2f2
7
+ data.tar.gz: 604d78217049389797f3508f621b54e0efd0962c075cf8c500d2b957c52e677584f1ec1eeea326bb12570cbe953c02581b248b9dfff54a80328bbf509b9871ee
@@ -0,0 +1,120 @@
1
+ name: build
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - '**'
7
+ - '!images'
8
+ pull_request:
9
+ branches:
10
+ - '**'
11
+ - '!images'
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ gemfile:
20
+ - gemfiles/Gemfile.rails-5.0
21
+ - gemfiles/Gemfile.rails-5.1
22
+ - gemfiles/Gemfile.rails-5.2
23
+ - gemfiles/Gemfile.rails-6.0
24
+ - gemfiles/Gemfile.rails-6.1
25
+ - gemfiles/Gemfile.rails-7.0
26
+ orm:
27
+ - active_record
28
+ - mongoid
29
+ - dynamoid
30
+ include:
31
+ # https://www.ruby-lang.org/en/downloads
32
+ - gemfile: gemfiles/Gemfile.rails-5.0
33
+ ruby-version: 2.7.5
34
+ - gemfile: gemfiles/Gemfile.rails-5.1
35
+ ruby-version: 2.7.5
36
+ - gemfile: gemfiles/Gemfile.rails-5.2
37
+ ruby-version: 2.7.5
38
+ - gemfile: gemfiles/Gemfile.rails-6.0
39
+ ruby-version: 3.0.3
40
+ - gemfile: gemfiles/Gemfile.rails-6.1
41
+ ruby-version: 3.0.3
42
+ - gemfile: gemfiles/Gemfile.rails-7.0
43
+ ruby-version: 3.0.3
44
+ - gemfile: Gemfile
45
+ ruby-version: 3.0.3
46
+ orm: active_record
47
+ test-db: mysql
48
+ - gemfile: Gemfile
49
+ ruby-version: 3.0.3
50
+ orm: active_record
51
+ test-db: postgresql
52
+ - gemfile: Gemfile
53
+ ruby-version: 3.0.3
54
+ orm: mongoid
55
+ test-db: mongodb
56
+ - gemfile: Gemfile
57
+ ruby-version: head
58
+ orm: active_record
59
+ allow_failures: 'true'
60
+ exclude:
61
+ - gemfile: gemfiles/Gemfile.rails-6.0
62
+ orm: dynamoid
63
+ - gemfile: gemfiles/Gemfile.rails-6.1
64
+ orm: dynamoid
65
+ - gemfile: gemfiles/Gemfile.rails-7.0
66
+ orm: dynamoid
67
+
68
+ env:
69
+ RAILS_ENV: test
70
+ BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}
71
+ AN_ORM: ${{ matrix.orm }}
72
+ AN_TEST_DB: ${{ matrix.test-db }}
73
+ AWS_DEFAULT_REGION: ap-northeast-1
74
+ AWS_ACCESS_KEY_ID: dummy
75
+ AWS_SECRET_ACCESS_KEY: dummy
76
+
77
+ services:
78
+ mysql:
79
+ image: mysql
80
+ ports:
81
+ - 3306:3306
82
+ env:
83
+ MYSQL_ALLOW_EMPTY_PASSWORD: yes
84
+ MYSQL_DATABASE: activity_notification_test
85
+ options: --health-cmd "mysqladmin ping -h 127.0.0.1" --health-interval 10s --health-timeout 5s --health-retries 5
86
+ postgres:
87
+ image: postgres
88
+ ports:
89
+ - 5432:5432
90
+ env:
91
+ POSTGRES_HOST_AUTH_METHOD: trust
92
+ POSTGRES_DB: activity_notification_test
93
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
94
+ mongodb:
95
+ image: mongo
96
+ ports:
97
+ - 27017:27017
98
+ env:
99
+ MONGO_INITDB_DATABASE: activity_notification_test
100
+ options: --health-cmd mongo --health-interval 10s --health-timeout 5s --health-retries 5
101
+
102
+ steps:
103
+ - uses: actions/checkout@v2
104
+ - name: Set up Ruby
105
+ uses: ruby/setup-ruby@v1
106
+ with:
107
+ ruby-version: ${{ matrix.ruby-version }}
108
+ bundler-cache: true
109
+ - name: Install dependencies
110
+ run: |
111
+ bundle install
112
+ bundle update
113
+ - name: Setup Amazon DynamoDB Local
114
+ if: matrix.orm == 'dynamoid'
115
+ run: |
116
+ bin/install_dynamodblocal.sh
117
+ bin/start_dynamodblocal.sh
118
+ - name: Run tests with RSpec
119
+ run: bundle exec rspec
120
+ continue-on-error: ${{ matrix.allow_failures == 'true' }}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ ## 2.2.3 / 2022-02-12
2
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.2.2...v2.2.3)
3
+
4
+ Enhancements:
5
+
6
+ * Allow use with Rails 7.0 - [#164](https://github.com/simukappu/activity_notification/issues/164) [#165](https://github.com/simukappu/activity_notification/pull/165)
7
+ * Add *rescue_optional_target_errors* config option to capture errors on optional targets - [#155](https://github.com/simukappu/activity_notification/issues/155) [#156](https://github.com/simukappu/activity_notification/pull/156)
8
+ * Remove type definition from several columns with nullable and multiple type in OpenAPI schema
9
+
10
+ ## 2.2.2 / 2021-04-18
11
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.2.1...v2.2.2)
12
+
13
+ Enhancements:
14
+
15
+ * Configure default subscriptions for emails and optional targets - [#159](https://github.com/simukappu/activity_notification/issues/159) [#160](https://github.com/simukappu/activity_notification/pull/160)
16
+ * Upgrade gem dependency in tests with Rails 6.1 - [#152](https://github.com/simukappu/activity_notification/issues/152)
17
+
18
+ ## 2.2.1 / 2021-01-24
19
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.2.0...v2.2.1)
20
+
21
+ Enhancements:
22
+
23
+ * Allow use with Rails 6.1 - [#152](https://github.com/simukappu/activity_notification/issues/152)
24
+
25
+ ## 2.2.0 / 2020-12-05
26
+ [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.4...v2.2.0)
27
+
28
+ Enhancements:
29
+
30
+ * Remove support for Rails 4.2 - [#151](https://github.com/simukappu/activity_notification/issues/151)
31
+ * Turn on deprecation warnings in RSpec testing for Ruby 2.7 - [#122](https://github.com/simukappu/activity_notification/issues/122)
32
+ * Remove Ruby 2.7 deprecation warnings - [#122](https://github.com/simukappu/activity_notification/issues/122)
33
+
34
+ Breaking Changes:
35
+
36
+ * Specify DynamoDB global secondary index name
37
+ * Update additional fields to store into DynamoDB when *config.store_with_associated_records* is true
38
+
1
39
  ## 2.1.4 / 2020-11-07
2
40
  [Full Changelog](http://github.com/simukappu/activity_notification/compare/v2.1.3...v2.1.4)
3
41
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActivityNotification
2
2
 
3
- [![Build Status](https://travis-ci.org/simukappu/activity_notification.svg?branch=master)](https://travis-ci.org/simukappu/activity_notification)
3
+ [![Build Status](https://github.com/simukappu/activity_notification/actions/workflows/build.yml/badge.svg)](https://github.com/simukappu/activity_notification/actions/workflows/build.yml)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/simukappu/activity_notification/badge.svg?branch=master)](https://coveralls.io/github/simukappu/activity_notification?branch=master)
5
5
  [![Dependency](https://img.shields.io/depfu/simukappu/activity_notification.svg)](https://depfu.com/repos/simukappu/activity_notification)
6
6
  [![Inline docs](http://inch-ci.org/github/simukappu/activity_notification.svg?branch=master)](http://inch-ci.org/github/simukappu/activity_notification)
@@ -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', '< 7.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.
@@ -91,8 +91,8 @@ module ActivityNotification
91
91
  # @option params [String] :filtered_by_key (nil) Key of the subscription for filter
92
92
  # @return [Response] JavaScript view for ajax request or redirects to back as default
93
93
  def subscribe
94
- @subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(true),
95
- with_optional_targets: params[:with_optional_targets].to_s.to_boolean(true))
94
+ @subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(ActivityNotification.config.subscribe_to_email_as_default),
95
+ with_optional_targets: params[:with_optional_targets].to_s.to_boolean(ActivityNotification.config.subscribe_to_optional_targets_as_default))
96
96
  return_back_or_ajax
97
97
  end
98
98
 
@@ -37,7 +37,7 @@
37
37
  <div class="field">
38
38
  <div class="ui checkbox">
39
39
  <label>
40
- <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_as_default }, 'true', 'false' %>
40
+ <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_to_email_as_default }, 'true', 'false' %>
41
41
  <div class="slider"></div>
42
42
  </label>
43
43
  </div>
@@ -38,7 +38,7 @@
38
38
  <div class="field">
39
39
  <div class="ui checkbox">
40
40
  <label>
41
- <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_as_default }, 'true', 'false' %>
41
+ <%= f.check_box :subscribing_to_email, { checked: ActivityNotification.config.subscribe_to_email_as_default }, 'true', 'false' %>
42
42
  <div class="slider"></div>
43
43
  </label>
44
44
  </div>
@@ -56,7 +56,7 @@
56
56
  <div class="ui checkbox">
57
57
  <label>
58
58
  <%= hidden_field_tag "subscription[optional_targets][#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}]", 'false', id: "#{key}_subscription_optional_targets_subscribing_to_#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}_hidden" %>
59
- <%= check_box_tag "subscription[optional_targets][#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}]", 'true', ActivityNotification.config.subscribe_as_default, id: "#{key}_subscription_optional_targets_subscribing_to_#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}_check_box" %>
59
+ <%= check_box_tag "subscription[optional_targets][#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}]", 'true', ActivityNotification.config.subscribe_to_optional_targets_as_default, id: "#{key}_subscription_optional_targets_subscribing_to_#{ActivityNotification::Subscription.to_optional_target_key(optional_target_name)}_check_box" %>
60
60
  <div class="slider"></div>
61
61
  </label>
62
62
  </div>
@@ -24,12 +24,12 @@
24
24
  <% end %>
25
25
  <% else %>
26
26
  <% if ActivityNotification.config.subscribe_as_default %>
27
- <%= link_to subscribe_path_for(subscription, option_params), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().find("input").prop("checked", true);$(this).parent().parent().parent().next().next().slideDown();$(this).parent().parent().parent().next().next().find("input").prop("checked", true);', method: :put, remote: true do %>
27
+ <%= link_to subscribe_path_for(subscription, option_params), onclick: "$(this).find(\"input\").prop(\"checked\", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().find(\"input\").prop(\"checked\", #{ActivityNotification.config.subscribe_to_email_as_default.to_s});$(this).parent().parent().parent().next().next().slideDown();$(this).parent().parent().parent().next().next().find(\"input\").prop(\"checked\", #{ActivityNotification.config.subscribe_to_optional_targets_as_default});", method: :put, remote: true do %>
28
28
  <%= check_box :subscribing, "", { checked: false }, 'true', 'false' %>
29
29
  <div class="slider"></div>
30
30
  <% end %>
31
31
  <% else %>
32
- <%= link_to subscribe_path_for(subscription, option_params.merge(with_email_subscription: false)), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().next().slideDown();', method: :put, remote: true do %>
32
+ <%= link_to subscribe_path_for(subscription, option_params), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().next().slideDown();', method: :put, remote: true do %>
33
33
  <%= check_box :subscribing, "", { checked: false }, 'true', 'false' %>
34
34
  <div class="slider"></div>
35
35
  <% end %>
@@ -189,9 +189,9 @@
189
189
  $thisFieldWrapper = $(this).parent().parent().parent().parent();
190
190
  if ($(this).prop('checked')) {
191
191
  $thisFieldWrapper.next().slideDown();
192
- $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
192
+ $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_email_as_default %>);
193
193
  $thisFieldWrapper.next().next().slideDown();
194
- $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
194
+ $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_optional_targets_as_default %>);
195
195
  } else {
196
196
  $thisFieldWrapper.next().slideUp();
197
197
  $thisFieldWrapper.next().next().slideUp();
@@ -165,9 +165,9 @@
165
165
  $thisFieldWrapper = $(this).parent().parent().parent().parent();
166
166
  if ($(this).prop('checked')) {
167
167
  $thisFieldWrapper.next().slideDown();
168
- $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
168
+ $thisFieldWrapper.next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_email_as_default %>);
169
169
  $thisFieldWrapper.next().next().slideDown();
170
- $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_as_default %>);
170
+ $thisFieldWrapper.next().next().find("input[type='checkbox']").prop("checked", <%= ActivityNotification.config.subscribe_to_optional_targets_as_default %>);
171
171
  } else {
172
172
  $thisFieldWrapper.next().slideUp();
173
173
  $thisFieldWrapper.next().next().slideUp();
data/bin/bundle_update.sh CHANGED
@@ -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
data/docs/Functions.md CHANGED
@@ -308,6 +308,8 @@ Subscriptions are managed by instances of **ActivityNotification::Subscription**
308
308
  *true* means the target will receive the notification email with this key including batch notification email with this *batch_key*.
309
309
  *false* means the target will not receive these notification email.
310
310
 
311
+ ##### Subscription defaults
312
+
311
313
  As default, all target subscribes to notification and notification email when subscription record does not exist in your database.
312
314
  You can change this **subscribe_as_default** parameter in initializer *activity_notification.rb*.
313
315
 
@@ -317,6 +319,20 @@ config.subscribe_as_default = false
317
319
 
318
320
  Then, all target does not subscribe to notification and notification email and will not receive any notifications as default.
319
321
 
322
+ As default, email and optional target subscriptions will use the same default subscription value as defined in **subscribe_as_default**.
323
+ You can disable them by providing **subscribe_to_email_as_default** or **subscribe_to_optional_targets_as_default** parameter(s) in initializer *activity_notification.rb*.
324
+
325
+ ```ruby
326
+ # Enable subscribe as default, but disable it for emails
327
+ config.subscribe_as_default = true
328
+ config.subscribe_to_email_as_default = false
329
+ config.subscribe_to_optional_targets_as_default = true
330
+ ```
331
+
332
+ However if **subscribe_as_default** is not enabled, **subscribe_to_email_as_default** and **subscribe_to_optional_targets_as_default** won't change anything.
333
+
334
+ ##### Creating and updating subscriptions
335
+
320
336
  You can create subscription record from subscription API in your target model like this:
321
337
 
322
338
  ```ruby
@@ -574,7 +590,7 @@ To sign in and get *access-token* from Devise Token Auth, call *sign_in* API whi
574
590
  ```console
575
591
  $ curl -X POST -H "Content-Type: application/json" -D - -d '{"email": "ichiro@example.com","password": "changeit"}' https://activity-notification-example.herokuapp.com/api/v2/auth/sign_in
576
592
 
577
-
593
+
578
594
  HTTP/1.1 200 OK
579
595
  ...
580
596
  Content-Type: application/json; charset=utf-8
@@ -2,10 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '../'
4
4
 
5
- gem 'rails', '~> 4.2.0'
6
- gem 'sqlite3', '~> 1.3.13'
7
- gem 'mysql2', '~> 0.4.10'
8
- gem 'pg', '~> 0.21.0'
5
+ gem 'rails', '~> 6.1.0'
9
6
 
10
7
  group :development do
11
8
  gem 'bullet'
@@ -13,6 +10,7 @@ group :development do
13
10
  end
14
11
 
15
12
  group :test do
13
+ gem 'rails-controller-testing'
16
14
  gem 'ammeter'
17
15
  gem 'timecop'
18
16
  gem 'committee'
@@ -0,0 +1,28 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'rails', '~> 7.0.0'
6
+ # https://github.com/lynndylanhurley/devise_token_auth/pull/1517
7
+ gem 'devise_token_auth', git: 'https://github.com/lynndylanhurley/devise_token_auth.git'
8
+ # https://jira.mongodb.org/browse/MONGOID-5193
9
+ gem 'mongoid', git: 'https://github.com/mongodb/mongoid.git'
10
+
11
+ gem 'sprockets-rails'
12
+
13
+ group :development do
14
+ gem 'bullet'
15
+ gem 'rack-cors'
16
+ end
17
+
18
+ group :test do
19
+ gem 'rails-controller-testing'
20
+ gem 'ammeter'
21
+ gem 'timecop'
22
+ gem 'committee'
23
+ gem 'committee-rails'
24
+ # gem 'coveralls', require: false
25
+ gem 'coveralls_reborn', require: false
26
+ end
27
+
28
+ gem 'dotenv-rails', groups: [:development, :test]
@@ -542,7 +542,11 @@ module ActivityNotification
542
542
  [optional_target_name, true]
543
543
  rescue => e
544
544
  Rails.logger.error(e)
545
- [optional_target_name, e]
545
+ if ActivityNotification.config.rescue_optional_target_errors
546
+ [optional_target_name, e]
547
+ else
548
+ raise e
549
+ end
546
550
  end
547
551
  else
548
552
  [optional_target_name, false]
@@ -21,7 +21,7 @@ module ActivityNotification
21
21
  # @subscriptions = @user.subscriptions.filtered_by_options({ custom_filter: ["created_at >= ?", time.hour.ago] })
22
22
  # @scope class
23
23
  # @param [Hash] options Options for filter
24
- # @option options [String] :filtered_by_key (nil) Key of the subscription for filter
24
+ # @option options [String] :filtered_by_key (nil) Key of the subscription for filter
25
25
  # @option options [Array|Hash] :custom_filter (nil) Custom subscription filter (e.g. ["created_at >= ?", time.hour.ago] or ['created_at.gt': time.hour.ago])
26
26
  # @return [ActiveRecord_AssociationRelation<Subscription>, Mongoid::Criteria<Notificaion>] Database query of filtered subscriptions
27
27
  scope :filtered_by_options, ->(options = {}) {
@@ -127,8 +127,8 @@ module ActivityNotification
127
127
  # @return [Boolean] If successfully updated subscription instance
128
128
  def subscribe(options = {})
129
129
  subscribed_at = options[:subscribed_at] || Time.current
130
- with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : true
131
- with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : true
130
+ with_email_subscription = options.has_key?(:with_email_subscription) ? options[:with_email_subscription] : ActivityNotification.config.subscribe_to_email_as_default
131
+ with_optional_targets = options.has_key?(:with_optional_targets) ? options[:with_optional_targets] : ActivityNotification.config.subscribe_to_optional_targets_as_default
132
132
  new_attributes = { subscribing: true, subscribed_at: subscribed_at, optional_targets: optional_targets }
133
133
  new_attributes = new_attributes.merge(subscribing_to_email: true, subscribed_to_email_at: subscribed_at) if with_email_subscription
134
134
  if with_optional_targets
@@ -184,7 +184,7 @@ module ActivityNotification
184
184
  # @param [Symbol] optional_target_name Symbol class name of the optional target implementation (e.g. :amazon_sns, :slack)
185
185
  # @param [Boolean] subscribe_as_default Default subscription value to use when the subscription record does not configured
186
186
  # @return [Boolean] If the target subscribes to the specified optional target
187
- def subscribing_to_optional_target?(optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_as_default)
187
+ def subscribing_to_optional_target?(optional_target_name, subscribe_as_default = ActivityNotification.config.subscribe_to_optional_targets_as_default)
188
188
  optional_target_key = Subscription.to_optional_target_key(optional_target_name)
189
189
  subscribe_as_default ?
190
190
  !optional_targets.has_key?(optional_target_key) || optional_targets[optional_target_key] :
@@ -244,4 +244,4 @@ module ActivityNotification
244
244
  end
245
245
 
246
246
  end
247
- end
247
+ end
@@ -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
@@ -61,6 +61,18 @@ module ActivityNotification
61
61
  # @return [Boolean] Default subscription value to use when the subscription record does not configured.
62
62
  attr_accessor :subscribe_as_default
63
63
 
64
+ # @overload subscribe_to_email_as_default=(value)
65
+ # Sets default email subscription value to use when the subscription record does not configured
66
+ # @param [Boolean] subscribe_to_email_as_default The new subscribe_to_email_as_default
67
+ # @return [Boolean] Default email subscription value to use when the subscription record does not configured.
68
+ attr_writer :subscribe_to_email_as_default
69
+
70
+ # @overload subscribe_to_optional_targets_as_default=(value)
71
+ # Sets default optional target subscription value to use when the subscription record does not configured
72
+ # @param [Boolean] subscribe_to_optional_targets_as_default The new subscribe_to_optional_targets_as_default
73
+ # @return [Boolean] Default optional target subscription value to use when the subscription record does not configured.
74
+ attr_writer :subscribe_to_optional_targets_as_default
75
+
64
76
  # @overload mailer_sender
65
77
  # Returns email address as sender of notification email
66
78
  # @return [String] Email address as sender of notification email.
@@ -201,33 +213,45 @@ module ActivityNotification
201
213
  # @return [String] Notification API channel prefix for ActionCable.
202
214
  attr_accessor :notification_api_channel_prefix
203
215
 
216
+ # @overload rescue_optional_target_errors
217
+ # Returns whether activity_notification internally rescues optional target errors
218
+ # @return [Boolean] Whether activity_notification internally rescues optional target errors.
219
+ # @overload rescue_optional_target_errors=(value)
220
+ # Sets whether activity_notification internally rescues optional target errors
221
+ # @param [Boolean] rescue_optional_target_errors The new rescue_optional_target_errors
222
+ # @return [Boolean] Whether activity_notification internally rescues optional target errors.
223
+ attr_accessor :rescue_optional_target_errors
224
+
204
225
  # Initialize configuration for ActivityNotification.
205
226
  # These configuration can be overridden in initializer.
206
227
  # @return [Config] A new instance of Config
207
228
  def initialize
208
- @enabled = true
209
- @orm = :active_record
210
- @notification_table_name = 'notifications'
211
- @subscription_table_name = 'subscriptions'
212
- @email_enabled = false
213
- @subscription_enabled = false
214
- @subscribe_as_default = true
215
- @mailer_sender = nil
216
- @mailer = 'ActivityNotification::Mailer'
217
- @parent_mailer = 'ActionMailer::Base'
218
- @parent_job = 'ActiveJob::Base'
219
- @parent_controller = 'ApplicationController'
220
- @parent_channel = 'ActionCable::Channel::Base'
221
- @mailer_templates_dir = 'activity_notification/mailer'
222
- @opened_index_limit = 10
223
- @active_job_queue = :activity_notification
224
- @composite_key_delimiter = '#'
225
- @store_with_associated_records = false
226
- @action_cable_enabled = false
227
- @action_cable_api_enabled = false
228
- @action_cable_with_devise = false
229
- @notification_channel_prefix = 'activity_notification_channel'
230
- @notification_api_channel_prefix = 'activity_notification_api_channel'
229
+ @enabled = true
230
+ @orm = :active_record
231
+ @notification_table_name = 'notifications'
232
+ @subscription_table_name = 'subscriptions'
233
+ @email_enabled = false
234
+ @subscription_enabled = false
235
+ @subscribe_as_default = true
236
+ @subscribe_to_email_as_default = nil
237
+ @subscribe_to_optional_targets_as_default = nil
238
+ @mailer_sender = nil
239
+ @mailer = 'ActivityNotification::Mailer'
240
+ @parent_mailer = 'ActionMailer::Base'
241
+ @parent_job = 'ActiveJob::Base'
242
+ @parent_controller = 'ApplicationController'
243
+ @parent_channel = 'ActionCable::Channel::Base'
244
+ @mailer_templates_dir = 'activity_notification/mailer'
245
+ @opened_index_limit = 10
246
+ @active_job_queue = :activity_notification
247
+ @composite_key_delimiter = '#'
248
+ @store_with_associated_records = false
249
+ @action_cable_enabled = false
250
+ @action_cable_api_enabled = false
251
+ @action_cable_with_devise = false
252
+ @notification_channel_prefix = 'activity_notification_channel'
253
+ @notification_api_channel_prefix = 'activity_notification_api_channel'
254
+ @rescue_optional_target_errors = true
231
255
  end
232
256
 
233
257
  # Sets ORM name for ActivityNotification (:active_record, :mongoid or :dynamodb)
@@ -245,5 +269,21 @@ module ActivityNotification
245
269
  if store_with_associated_records && [:mongoid, :dynamoid].exclude?(@orm) then raise ActivityNotification::ConfigError, "config.store_with_associated_records can be set true only when you use mongoid or dynamoid ORM." end
246
270
  @store_with_associated_records = store_with_associated_records
247
271
  end
272
+
273
+ # Returns default email subscription value to use when the subscription record does not configured
274
+ # @return [Boolean] Default email subscription value to use when the subscription record does not configured.
275
+ def subscribe_to_email_as_default
276
+ return false unless @subscribe_as_default
277
+
278
+ @subscribe_to_email_as_default.nil? ? @subscribe_as_default : @subscribe_to_email_as_default
279
+ end
280
+
281
+ # Returns default optional target subscription value to use when the subscription record does not configured
282
+ # @return [Boolean] Default optinal target subscription value to use when the subscription record does not configured.
283
+ def subscribe_to_optional_targets_as_default
284
+ return false unless @subscribe_as_default
285
+
286
+ @subscribe_to_optional_targets_as_default.nil? ? @subscribe_as_default : @subscribe_to_optional_targets_as_default
287
+ end
248
288
  end
249
289
  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