activity_notification 2.0.0 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- data/.github/pull_request_template.md +13 -0
- data/.gitignore +10 -3
- data/.travis.yml +6 -5
- data/CHANGELOG.md +60 -0
- data/Gemfile +8 -3
- data/Procfile +1 -1
- data/README.md +153 -1510
- data/activity_notification.gemspec +4 -1
- data/app/channels/activity_notification/notification_api_channel.rb +12 -0
- data/app/channels/activity_notification/notification_api_with_devise_channel.rb +46 -0
- data/app/channels/activity_notification/notification_channel.rb +2 -2
- data/app/channels/activity_notification/notification_with_devise_channel.rb +2 -2
- data/app/controllers/activity_notification/apidocs_controller.rb +75 -0
- data/app/controllers/activity_notification/notifications_api_controller.rb +143 -0
- data/app/controllers/activity_notification/notifications_api_with_devise_controller.rb +7 -0
- data/app/controllers/activity_notification/notifications_controller.rb +79 -53
- data/app/controllers/activity_notification/subscriptions_api_controller.rb +197 -0
- data/app/controllers/activity_notification/subscriptions_api_with_devise_controller.rb +7 -0
- data/app/controllers/activity_notification/subscriptions_controller.rb +78 -69
- data/app/views/activity_notification/notifications/default/_default.html.erb +18 -18
- data/app/views/activity_notification/notifications/default/_default_without_grouping.html.erb +14 -14
- data/app/views/activity_notification/notifications/default/index.html.erb +6 -6
- data/app/views/activity_notification/optional_targets/default/action_cable_channel/_default.html.erb +176 -0
- data/app/views/activity_notification/subscriptions/default/_form.html.erb +1 -1
- data/app/views/activity_notification/subscriptions/default/_notification_keys.html.erb +3 -31
- data/app/views/activity_notification/subscriptions/default/_subscription.html.erb +7 -7
- data/app/views/activity_notification/subscriptions/default/index.html.erb +11 -7
- data/bin/deploy_on_heroku.sh +3 -1
- data/docs/CODE_OF_CONDUCT.md +76 -0
- data/docs/CONTRIBUTING.md +36 -0
- data/docs/Functions.md +1130 -0
- data/docs/Setup.md +801 -0
- data/docs/Testing.md +148 -0
- data/gemfiles/Gemfile.rails-4.2 +5 -1
- data/gemfiles/Gemfile.rails-5.0 +6 -1
- data/gemfiles/Gemfile.rails-5.1 +6 -1
- data/gemfiles/Gemfile.rails-5.2 +6 -1
- data/gemfiles/{Gemfile.rails-6.0.rc → Gemfile.rails-6.0} +6 -5
- data/lib/activity_notification.rb +13 -0
- data/lib/activity_notification/apis/notification_api.rb +37 -93
- data/lib/activity_notification/apis/subscription_api.rb +20 -8
- data/lib/activity_notification/apis/swagger.rb +6 -0
- data/lib/activity_notification/common.rb +4 -1
- data/lib/activity_notification/config.rb +41 -21
- data/lib/activity_notification/controllers/common_api_controller.rb +30 -0
- data/lib/activity_notification/controllers/common_controller.rb +45 -21
- data/lib/activity_notification/controllers/concerns/swagger/error_responses.rb +55 -0
- data/lib/activity_notification/controllers/concerns/swagger/notifications_api.rb +273 -0
- data/lib/activity_notification/controllers/concerns/swagger/notifications_parameters.rb +92 -0
- data/lib/activity_notification/controllers/concerns/swagger/subscriptions_api.rb +405 -0
- data/lib/activity_notification/controllers/concerns/swagger/subscriptions_parameters.rb +50 -0
- data/lib/activity_notification/controllers/devise_authentication_controller.rb +7 -6
- data/lib/activity_notification/gem_version.rb +14 -0
- data/lib/activity_notification/helpers/errors.rb +2 -0
- data/lib/activity_notification/helpers/view_helpers.rb +4 -0
- data/lib/activity_notification/mailers/helpers.rb +17 -10
- data/lib/activity_notification/models/concerns/notifiable.rb +31 -15
- data/lib/activity_notification/models/concerns/subscriber.rb +12 -1
- data/lib/activity_notification/models/concerns/swagger/error_schema.rb +36 -0
- data/lib/activity_notification/models/concerns/swagger/notification_schema.rb +209 -0
- data/lib/activity_notification/models/concerns/swagger/subscription_schema.rb +162 -0
- data/lib/activity_notification/models/concerns/target.rb +36 -10
- data/lib/activity_notification/models/notification.rb +1 -0
- data/lib/activity_notification/models/subscription.rb +1 -0
- data/lib/activity_notification/optional_targets/action_cable_api_channel.rb +69 -0
- data/lib/activity_notification/optional_targets/action_cable_channel.rb +68 -0
- data/lib/activity_notification/optional_targets/base.rb +7 -13
- data/lib/activity_notification/orm/active_record/notification.rb +17 -1
- data/lib/activity_notification/orm/active_record/subscription.rb +1 -1
- data/lib/activity_notification/orm/dynamoid.rb +38 -3
- data/lib/activity_notification/orm/dynamoid/extension.rb +79 -1
- data/lib/activity_notification/orm/dynamoid/notification.rb +49 -14
- data/lib/activity_notification/orm/dynamoid/subscription.rb +2 -2
- data/lib/activity_notification/orm/mongoid.rb +32 -3
- data/lib/activity_notification/orm/mongoid/notification.rb +24 -6
- data/lib/activity_notification/orm/mongoid/subscription.rb +1 -1
- data/lib/activity_notification/rails/routes.rb +132 -48
- data/lib/activity_notification/renderable.rb +13 -2
- data/lib/activity_notification/roles/acts_as_notifiable.rb +39 -20
- data/lib/activity_notification/version.rb +1 -1
- data/lib/generators/activity_notification/controllers_generator.rb +2 -1
- data/lib/generators/templates/activity_notification.rb +8 -0
- data/lib/generators/templates/controllers/notifications_api_controller.rb +31 -0
- data/lib/generators/templates/controllers/notifications_api_with_devise_controller.rb +31 -0
- data/lib/generators/templates/controllers/notifications_controller.rb +1 -37
- data/lib/generators/templates/controllers/notifications_with_devise_controller.rb +1 -45
- data/lib/generators/templates/controllers/subscriptions_api_controller.rb +61 -0
- data/lib/generators/templates/controllers/subscriptions_api_with_devise_controller.rb +61 -0
- data/lib/generators/templates/controllers/subscriptions_controller.rb +14 -37
- data/lib/generators/templates/controllers/subscriptions_with_devise_controller.rb +14 -45
- data/lib/generators/templates/models/README +8 -4
- data/lib/generators/templates/models/notification.rb +1 -1
- data/lib/generators/templates/models/subscription.rb +1 -1
- data/package.json +8 -0
- data/spec/channels/notification_api_channel_shared_examples.rb +59 -0
- data/spec/channels/notification_api_channel_spec.rb +51 -0
- data/spec/channels/notification_api_with_devise_channel_spec.rb +78 -0
- data/spec/concerns/apis/notification_api_spec.rb +38 -3
- data/spec/concerns/models/notifiable_spec.rb +82 -18
- data/spec/concerns/models/subscriber_spec.rb +13 -16
- data/spec/concerns/models/target_spec.rb +32 -0
- data/spec/concerns/renderable_spec.rb +2 -2
- data/spec/config_spec.rb +26 -15
- data/spec/controllers/controller_spec_utility.rb +136 -0
- data/spec/controllers/notifications_api_controller_shared_examples.rb +506 -0
- data/spec/controllers/notifications_api_controller_spec.rb +19 -0
- data/spec/controllers/notifications_api_with_devise_controller_spec.rb +60 -0
- data/spec/controllers/notifications_controller_shared_examples.rb +54 -79
- data/spec/controllers/notifications_controller_spec.rb +1 -2
- data/spec/controllers/notifications_with_devise_controller_spec.rb +3 -12
- data/spec/controllers/subscriptions_api_controller_shared_examples.rb +750 -0
- data/spec/controllers/subscriptions_api_controller_spec.rb +19 -0
- data/spec/controllers/subscriptions_api_with_devise_controller_spec.rb +60 -0
- data/spec/controllers/subscriptions_controller_shared_examples.rb +94 -121
- data/spec/controllers/subscriptions_controller_spec.rb +1 -2
- data/spec/controllers/subscriptions_with_devise_controller_spec.rb +3 -12
- data/spec/helpers/view_helpers_spec.rb +4 -11
- data/spec/mailers/mailer_spec.rb +41 -0
- data/spec/models/notification_spec.rb +17 -0
- data/spec/models/subscription_spec.rb +8 -13
- data/spec/optional_targets/action_cable_api_channel_spec.rb +37 -0
- data/spec/optional_targets/action_cable_channel_spec.rb +44 -0
- data/spec/optional_targets/amazon_sns_spec.rb +0 -2
- data/spec/optional_targets/slack_spec.rb +0 -2
- data/spec/rails_app/Rakefile +9 -0
- data/spec/rails_app/app/assets/config/manifest.js +3 -0
- data/spec/rails_app/app/assets/images/.keep +0 -0
- data/spec/rails_app/app/controllers/admins_controller.rb +21 -0
- data/spec/rails_app/app/controllers/application_controller.rb +1 -1
- data/spec/rails_app/app/controllers/articles_controller.rb +6 -3
- data/spec/rails_app/app/controllers/spa_controller.rb +7 -0
- data/spec/rails_app/app/controllers/users/notifications_controller.rb +0 -65
- data/spec/rails_app/app/controllers/users/notifications_with_devise_controller.rb +0 -73
- data/spec/rails_app/app/controllers/users/subscriptions_controller.rb +0 -77
- data/spec/rails_app/app/controllers/users/subscriptions_with_devise_controller.rb +0 -85
- data/spec/rails_app/app/controllers/users_controller.rb +26 -0
- data/spec/rails_app/app/javascript/App.vue +40 -0
- data/spec/rails_app/app/javascript/components/DeviseTokenAuth.vue +82 -0
- data/spec/rails_app/app/javascript/components/Top.vue +98 -0
- data/spec/rails_app/app/javascript/components/notifications/Index.vue +200 -0
- data/spec/rails_app/app/javascript/components/notifications/Notification.vue +133 -0
- data/spec/rails_app/app/javascript/components/notifications/NotificationContent.vue +122 -0
- data/spec/rails_app/app/javascript/components/subscriptions/Index.vue +279 -0
- data/spec/rails_app/app/javascript/components/subscriptions/NewSubscription.vue +112 -0
- data/spec/rails_app/app/javascript/components/subscriptions/NotificationKey.vue +141 -0
- data/spec/rails_app/app/javascript/components/subscriptions/Subscription.vue +226 -0
- data/spec/rails_app/app/javascript/config/development.js +5 -0
- data/spec/rails_app/app/javascript/config/environment.js +7 -0
- data/spec/rails_app/app/javascript/config/production.js +5 -0
- data/spec/rails_app/app/javascript/config/test.js +5 -0
- data/spec/rails_app/app/javascript/packs/application.js +18 -0
- data/spec/rails_app/app/javascript/packs/spa.js +14 -0
- data/spec/rails_app/app/javascript/router/index.js +73 -0
- data/spec/rails_app/app/javascript/store/index.js +37 -0
- data/spec/rails_app/app/models/admin.rb +16 -15
- data/spec/rails_app/app/models/article.rb +26 -21
- data/spec/rails_app/app/models/comment.rb +24 -71
- data/spec/rails_app/app/models/dummy/dummy_group.rb +8 -0
- data/spec/rails_app/app/models/dummy/dummy_notifiable_target.rb +8 -0
- data/spec/rails_app/app/models/user.rb +44 -20
- data/spec/rails_app/app/views/activity_notification/notifications/default/article/_update.html.erb +146 -0
- data/spec/rails_app/app/views/articles/index.html.erb +51 -7
- data/spec/rails_app/app/views/articles/show.html.erb +1 -1
- data/spec/rails_app/app/views/layouts/_header.html.erb +8 -10
- data/spec/rails_app/app/views/spa/index.html.erb +2 -0
- data/spec/rails_app/babel.config.js +72 -0
- data/spec/rails_app/bin/webpack +18 -0
- data/spec/rails_app/bin/webpack-dev-server +18 -0
- data/spec/rails_app/config/application.rb +18 -2
- data/spec/rails_app/config/dynamoid.rb +11 -3
- data/spec/rails_app/config/environment.rb +2 -1
- data/spec/rails_app/config/environments/development.rb +5 -0
- data/spec/rails_app/config/environments/production.rb +6 -0
- data/spec/rails_app/config/environments/test.rb +5 -0
- data/spec/rails_app/config/initializers/activity_notification.rb +11 -3
- data/spec/rails_app/config/initializers/copy_it.aws.rb.template +6 -0
- data/spec/rails_app/config/initializers/devise_token_auth.rb +55 -0
- data/spec/rails_app/config/initializers/mysql.rb +9 -0
- data/spec/rails_app/config/locales/activity_notification.en.yml +2 -2
- data/spec/rails_app/config/routes.rb +37 -1
- data/spec/rails_app/config/webpack/development.js +5 -0
- data/spec/rails_app/config/webpack/environment.js +7 -0
- data/spec/rails_app/config/webpack/loaders/vue.js +6 -0
- data/spec/rails_app/config/webpack/production.js +5 -0
- data/spec/rails_app/config/webpack/test.js +5 -0
- data/spec/rails_app/config/webpacker.yml +97 -0
- data/spec/rails_app/db/migrate/20191201000000_add_tokens_to_users.rb +10 -0
- data/spec/rails_app/db/schema.rb +4 -1
- data/spec/rails_app/db/seeds.rb +10 -2
- data/spec/rails_app/lib/custom_optional_targets/raise_error.rb +14 -0
- data/spec/rails_app/package.json +23 -0
- data/spec/rails_app/postcss.config.js +12 -0
- data/spec/roles/acts_as_group_spec.rb +0 -2
- data/spec/roles/acts_as_notifiable_spec.rb +6 -8
- data/spec/roles/acts_as_notifier_spec.rb +0 -2
- data/spec/roles/acts_as_target_spec.rb +0 -4
- data/spec/spec_helper.rb +7 -15
- data/spec/version_spec.rb +31 -0
- metadata +191 -13
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'controllers/subscriptions_controller_shared_examples'
|
2
2
|
|
3
3
|
describe ActivityNotification::SubscriptionsWithDeviseController, type: :controller do
|
4
|
+
include ActivityNotification::ControllerSpec::RequestUtility
|
5
|
+
|
4
6
|
let(:test_user) { create(:confirmed_user) }
|
5
7
|
let(:unauthenticated_user) { create(:confirmed_user) }
|
6
8
|
let(:test_target) { create(:admin, user: test_user) }
|
@@ -14,7 +16,7 @@ describe ActivityNotification::SubscriptionsWithDeviseController, type: :control
|
|
14
16
|
sign_in test_user
|
15
17
|
end
|
16
18
|
|
17
|
-
it_behaves_like :
|
19
|
+
it_behaves_like :subscriptions_controller
|
18
20
|
end
|
19
21
|
|
20
22
|
context "signed in with devise as unauthenticated user" do
|
@@ -92,15 +94,4 @@ describe ActivityNotification::SubscriptionsWithDeviseController, type: :control
|
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def get_with_compatibility action, params, session
|
99
|
-
if Rails::VERSION::MAJOR <= 4
|
100
|
-
get action, params, session
|
101
|
-
else
|
102
|
-
get action, params: params, session: session
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
97
|
end
|
@@ -72,9 +72,9 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
72
72
|
|
73
73
|
it "interpolates from parameters" do
|
74
74
|
notification.parameters = { "article_title" => "custom title" }
|
75
|
-
notification.key = 'article.
|
75
|
+
notification.key = 'article.destroy'
|
76
76
|
expect(render_notification notification, fallback: :text)
|
77
|
-
.to eq(
|
77
|
+
.to eq('The author removed an article "custom title"')
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -113,6 +113,7 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
113
113
|
expect(self).to receive(:render).with({
|
114
114
|
layout: 'layouts/test',
|
115
115
|
partial: 'activity_notification/notifications/default/custom/test',
|
116
|
+
assigns: {},
|
116
117
|
locals: notification.prepare_locals({ layout: 'test' })
|
117
118
|
})
|
118
119
|
render_notification notification, layout: 'test'
|
@@ -170,16 +171,8 @@ describe ActivityNotification::ViewHelpers, type: :helper do
|
|
170
171
|
@target = target_user
|
171
172
|
end
|
172
173
|
|
173
|
-
#TODO make better test using content_for
|
174
174
|
it "renders custom notification view for specified target" do
|
175
|
-
|
176
|
-
# notification_2 = target_user.notifications.last
|
177
|
-
# notification_1.update(key: 'custom.test')
|
178
|
-
# notification_2.update(key: 'custom.test')
|
179
|
-
expect(render_notification_of target_user, partial: 'custom_index', fallback: :default)
|
180
|
-
.to eq("Custom index: ")
|
181
|
-
# .to eq("Custom index: Custom template root for user target: #{notification_1.id}"\
|
182
|
-
# "Custom template root for user target: #{notification_2.id}")
|
175
|
+
expect(render_notification_of target_user, partial: 'custom_index', fallback: :default).to eq("Custom index: ")
|
183
176
|
end
|
184
177
|
|
185
178
|
it "uses layout of layout parameter" do
|
data/spec/mailers/mailer_spec.rb
CHANGED
@@ -102,6 +102,47 @@ describe ActivityNotification::Mailer do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
+
context "with defined overriding_notification_email_from in notifiable model" do
|
106
|
+
it "sends with updated from" do
|
107
|
+
module AdditionalMethods
|
108
|
+
def overriding_notification_email_from(target, key)
|
109
|
+
'test05@example.com'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
notification.notifiable.extend(AdditionalMethods)
|
113
|
+
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
114
|
+
expect(ActivityNotification::Mailer.deliveries.last.from.first)
|
115
|
+
.to eq('test05@example.com')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with defined overriding_notification_email_reply_to in notifiable model" do
|
120
|
+
it "sends with updated reply_to" do
|
121
|
+
module AdditionalMethods
|
122
|
+
def overriding_notification_email_reply_to(target, key)
|
123
|
+
'test06@example.com'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
notification.notifiable.extend(AdditionalMethods)
|
127
|
+
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
128
|
+
expect(ActivityNotification::Mailer.deliveries.last.reply_to.first)
|
129
|
+
.to eq('test06@example.com')
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with defined overriding_notification_email_message_id in notifiable model" do
|
134
|
+
it "sends with specific message id" do
|
135
|
+
module AdditionalMethods
|
136
|
+
def overriding_notification_email_message_id(target, key)
|
137
|
+
"https://www.example.com/test@example.com/"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
notification.notifiable.extend(AdditionalMethods)
|
141
|
+
ActivityNotification::Mailer.send_notification_email(notification).deliver_now
|
142
|
+
expect(ActivityNotification::Mailer.deliveries.last.message_id)
|
143
|
+
.to eq("https://www.example.com/test@example.com/")
|
144
|
+
end
|
145
|
+
end
|
105
146
|
context "when fallback option is :none and the template is missing" do
|
106
147
|
it "raise ActionView::MissingTemplate" do
|
107
148
|
expect { ActivityNotification::Mailer.send_notification_email(notification, fallback: :none).deliver_now }
|
@@ -56,6 +56,23 @@ describe ActivityNotification::Notification, type: :model do
|
|
56
56
|
notification = create(:notification, notifier: notifier)
|
57
57
|
expect(notification.reload.notifier).to eq(notifier)
|
58
58
|
end
|
59
|
+
|
60
|
+
context "returns as_json including associated models" do
|
61
|
+
it "returns as_json with include option as Symbol" do
|
62
|
+
notification = create(:notification)
|
63
|
+
expect(notification.as_json(include: :target)["target"]["id"].to_s).to eq(notification.target.id.to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns as_json with include option as Array" do
|
67
|
+
notification = create(:notification)
|
68
|
+
expect(notification.as_json(include: [:target])["target"]["id"].to_s).to eq(notification.target.id.to_s)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns as_json with include option as Hash" do
|
72
|
+
notification = create(:notification)
|
73
|
+
expect(notification.as_json(include: { target: { methods: [:printable_target_name] } })["target"]["id"].to_s).to eq(notification.target.id.to_s)
|
74
|
+
end
|
75
|
+
end
|
59
76
|
end
|
60
77
|
|
61
78
|
describe "with serializable column" do
|
@@ -11,6 +11,14 @@ describe ActivityNotification::Subscription, type: :model do
|
|
11
11
|
subscription = create(:subscription, target: target)
|
12
12
|
expect(subscription.reload.target).to eq(target)
|
13
13
|
end
|
14
|
+
|
15
|
+
it "several targets can subscribe to the same key" do
|
16
|
+
target = create(:confirmed_user)
|
17
|
+
target2 = create(:confirmed_user)
|
18
|
+
subscription_1 = create(:subscription, target: target, key: 'key.1')
|
19
|
+
subscription_2 = create(:subscription, target: target2, key: 'key.1')
|
20
|
+
expect(subscription_2).to be_valid
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
describe "with validation" do
|
@@ -32,19 +40,6 @@ describe ActivityNotification::Subscription, type: :model do
|
|
32
40
|
expect(@subscription.errors[:key].size).to eq(1)
|
33
41
|
end
|
34
42
|
|
35
|
-
#TODO
|
36
|
-
# it "is invalid with non boolean value of subscribing" do
|
37
|
-
# @subscription.subscribing = 'hoge'
|
38
|
-
# expect(@subscription).to be_invalid
|
39
|
-
# expect(@subscription.errors[:subscribing].size).to eq(1)
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# it "is invalid with non boolean value of subscribing_to_email" do
|
43
|
-
# @subscription.subscribing_to_email = 'hoge'
|
44
|
-
# expect(@subscription).to be_invalid
|
45
|
-
# expect(@subscription.errors[:subscribing_to_email].size).to eq(1)
|
46
|
-
# end
|
47
|
-
|
48
43
|
it "is invalid with true as subscribing_to_email and false as subscribing" do
|
49
44
|
@subscription.subscribing = false
|
50
45
|
@subscription.subscribing_to_email = true
|
@@ -0,0 +1,37 @@
|
|
1
|
+
if Rails::VERSION::MAJOR >= 5
|
2
|
+
require 'activity_notification/optional_targets/action_cable_api_channel'
|
3
|
+
describe ActivityNotification::OptionalTarget::ActionCableApiChannel do
|
4
|
+
let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableApiChannel.new(skip_initializing_target: true) }
|
5
|
+
|
6
|
+
describe "as public instance methods" do
|
7
|
+
describe "#to_optional_target_name" do
|
8
|
+
it "is return demodulized symbol class name" do
|
9
|
+
expect(test_instance.to_optional_target_name).to eq(:action_cable_api_channel)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#initialize_target" do
|
14
|
+
it "does not raise NotImplementedError" do
|
15
|
+
test_instance.initialize_target
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#notify" do
|
20
|
+
it "does not raise NotImplementedError" do
|
21
|
+
test_instance.notify(create(:notification))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "as protected instance methods" do
|
27
|
+
describe "#render_notification_message" do
|
28
|
+
context "as default" do
|
29
|
+
it "renders notification message as formatted JSON" do
|
30
|
+
expect(test_instance.send(:render_notification_message, create(:notification)).with_indifferent_access[:notification].has_key?(:id)).to be_truthy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
if Rails::VERSION::MAJOR >= 5
|
2
|
+
require 'activity_notification/optional_targets/action_cable_channel'
|
3
|
+
describe ActivityNotification::OptionalTarget::ActionCableChannel do
|
4
|
+
let(:test_instance) { ActivityNotification::OptionalTarget::ActionCableChannel.new(skip_initializing_target: true) }
|
5
|
+
|
6
|
+
describe "as public instance methods" do
|
7
|
+
describe "#to_optional_target_name" do
|
8
|
+
it "is return demodulized symbol class name" do
|
9
|
+
expect(test_instance.to_optional_target_name).to eq(:action_cable_channel)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#initialize_target" do
|
14
|
+
it "does not raise NotImplementedError" do
|
15
|
+
test_instance.initialize_target
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#notify" do
|
20
|
+
it "does not raise NotImplementedError" do
|
21
|
+
test_instance.notify(create(:notification))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "as protected instance methods" do
|
27
|
+
describe "#render_notification_message" do
|
28
|
+
context "as default" do
|
29
|
+
it "renders notification message with default template" do
|
30
|
+
expect(test_instance.send(:render_notification_message, create(:notification))).to be_include("<div class='notification_list")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with unexisting template as fallback option" do
|
35
|
+
it "raise ActionView::MissingTemplate" do
|
36
|
+
expect { expect(test_instance.send(:render_notification_message, create(:notification), fallback: :hoge)) }
|
37
|
+
.to raise_error(ActionView::MissingTemplate)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -10,7 +10,6 @@ describe ActivityNotification::OptionalTarget::AmazonSNS do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#initialize_target" do
|
13
|
-
#TODO
|
14
13
|
it "does not raise NotImplementedError" do
|
15
14
|
begin
|
16
15
|
test_instance.initialize_target
|
@@ -21,7 +20,6 @@ describe ActivityNotification::OptionalTarget::AmazonSNS do
|
|
21
20
|
end
|
22
21
|
|
23
22
|
describe "#notify" do
|
24
|
-
#TODO
|
25
23
|
it "does not raise NotImplementedError but NoMethodError" do
|
26
24
|
expect { test_instance.notify(create(:notification)) }
|
27
25
|
.to raise_error(NoMethodError)
|
@@ -10,7 +10,6 @@ describe ActivityNotification::OptionalTarget::Slack do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "#initialize_target" do
|
13
|
-
#TODO
|
14
13
|
it "does not raise NotImplementedError but URI::InvalidURIError" do
|
15
14
|
expect { test_instance.initialize_target }
|
16
15
|
.to raise_error(URI::InvalidURIError)
|
@@ -18,7 +17,6 @@ describe ActivityNotification::OptionalTarget::Slack do
|
|
18
17
|
end
|
19
18
|
|
20
19
|
describe "#notify" do
|
21
|
-
#TODO
|
22
20
|
it "does not raise NotImplementedError but NoMethodError" do
|
23
21
|
expect { test_instance.notify(create(:notification)) }
|
24
22
|
.to raise_error(NoMethodError)
|
data/spec/rails_app/Rakefile
CHANGED
@@ -3,4 +3,13 @@
|
|
3
3
|
|
4
4
|
require File.expand_path('../config/application', __FILE__)
|
5
5
|
|
6
|
+
# Define dummy module for Webpacker Rake tasks
|
7
|
+
require 'devise_token_auth'
|
8
|
+
unless defined?(DeviseTokenAuth::Concerns::User)
|
9
|
+
module DeviseTokenAuth::Concerns
|
10
|
+
module User
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
6
15
|
Rails.application.load_tasks
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class AdminsController < ApplicationController
|
2
|
+
before_action :set_admin, only: [:show]
|
3
|
+
|
4
|
+
# GET /admins
|
5
|
+
def index
|
6
|
+
render json: {
|
7
|
+
users: Admin.all.as_json(include: :user, methods: [:printable_target_name, :notification_action_cable_allowed?, :notification_action_cable_with_devise?])
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /admins/:id
|
12
|
+
def show
|
13
|
+
render json: @admin.as_json(include: :user, methods: [:printable_target_name, :notification_action_cable_allowed?, :notification_action_cable_with_devise?])
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
# Use callbacks to share common setup or constraints between actions.
|
18
|
+
def set_admin
|
19
|
+
@admin = Admin.find(params[:id])
|
20
|
+
end
|
21
|
+
end
|
@@ -4,8 +4,10 @@ class ArticlesController < ApplicationController
|
|
4
4
|
|
5
5
|
# GET /articles
|
6
6
|
def index
|
7
|
-
@
|
8
|
-
@
|
7
|
+
@exists_notifications_routes = respond_to?('notifications_path')
|
8
|
+
@exists_user_notifications_routes = respond_to?('user_notifications_path')
|
9
|
+
@exists_admins_notifications_routes = respond_to?('admins_notifications_path')
|
10
|
+
@exists_admin_notifications_routes = respond_to?('admin_notifications_path')
|
9
11
|
@articles = Article.all.includes(:user)
|
10
12
|
end
|
11
13
|
|
@@ -29,7 +31,7 @@ class ArticlesController < ApplicationController
|
|
29
31
|
@article.user = current_user
|
30
32
|
|
31
33
|
if @article.save
|
32
|
-
@article.notify :users
|
34
|
+
@article.notify :users, key: 'article.create'
|
33
35
|
redirect_to @article, notice: 'Article was successfully created.'
|
34
36
|
else
|
35
37
|
render :new
|
@@ -39,6 +41,7 @@ class ArticlesController < ApplicationController
|
|
39
41
|
# PATCH/PUT /articles/1
|
40
42
|
def update
|
41
43
|
if @article.update(article_params)
|
44
|
+
@article.notify :users, key: 'article.update'
|
42
45
|
redirect_to @article, notice: 'Article was successfully updated.'
|
43
46
|
else
|
44
47
|
render :edit
|
@@ -1,67 +1,2 @@
|
|
1
1
|
class Users::NotificationsController < ActivityNotification::NotificationsController
|
2
|
-
# GET /:target_type/:target_id/notifications
|
3
|
-
# def index
|
4
|
-
# super
|
5
|
-
# end
|
6
|
-
|
7
|
-
# POST /:target_type/:target_id/notifications/open_all
|
8
|
-
# def open_all
|
9
|
-
# super
|
10
|
-
# end
|
11
|
-
|
12
|
-
# GET /:target_type/:target_id/notifications/:id
|
13
|
-
# def show
|
14
|
-
# super
|
15
|
-
# end
|
16
|
-
|
17
|
-
# DELETE /:target_type/:target_id/notifications/:id
|
18
|
-
# def destroy
|
19
|
-
# super
|
20
|
-
# end
|
21
|
-
|
22
|
-
# POST /:target_type/:target_id/notifications/:id/open
|
23
|
-
# def open
|
24
|
-
# super
|
25
|
-
# end
|
26
|
-
|
27
|
-
# GET /:target_type/:target_id/notifications/:id/move
|
28
|
-
# def move
|
29
|
-
# super
|
30
|
-
# end
|
31
|
-
|
32
|
-
# No action routing
|
33
|
-
# This method needs to be public since it is called from view helper
|
34
|
-
# def target_view_path
|
35
|
-
# super
|
36
|
-
# end
|
37
|
-
|
38
|
-
# protected
|
39
|
-
|
40
|
-
# def set_target
|
41
|
-
# super
|
42
|
-
# end
|
43
|
-
|
44
|
-
# def set_notification
|
45
|
-
# super
|
46
|
-
# end
|
47
|
-
|
48
|
-
# def set_index_options
|
49
|
-
# super
|
50
|
-
# end
|
51
|
-
|
52
|
-
# def load_notification_index(options = {})
|
53
|
-
# super(options)
|
54
|
-
# end
|
55
|
-
|
56
|
-
# def controller_path
|
57
|
-
# super
|
58
|
-
# end
|
59
|
-
|
60
|
-
# def set_view_prefixes
|
61
|
-
# super
|
62
|
-
# end
|
63
|
-
|
64
|
-
# def return_back_or_ajax
|
65
|
-
# super
|
66
|
-
# end
|
67
2
|
end
|