web47core 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -14
- data/Gemfile.lock +30 -9
- data/README.md +27 -4
- data/lib/app/models/concerns/app47_logger.rb +175 -0
- data/lib/app/models/concerns/core_account.rb +51 -0
- data/lib/app/models/concerns/standard_model.rb +104 -6
- data/lib/app/models/email_notification.rb +253 -0
- data/lib/app/models/email_template.rb +6 -0
- data/lib/app/models/notification.rb +276 -0
- data/lib/app/models/notification_template.rb +20 -0
- data/lib/app/models/slack_notification.rb +89 -0
- data/lib/app/models/sms_notification.rb +56 -0
- data/lib/app/models/smtp_configuration.rb +148 -0
- data/lib/app/models/template.rb +21 -0
- data/lib/templates/email/notification_failure.liquid +10 -0
- data/lib/templates/email/notification_failure.subject.liquid +1 -0
- data/lib/templates/slack/error_message.liquid +1 -0
- data/lib/web47core.rb +10 -2
- data/test/factories/account_factories.rb +9 -0
- data/test/factories/notification_factories.rb +14 -0
- data/test/models/app47_logger_test.rb +88 -0
- data/test/models/concerns/{formable_test.rb → standard_model_test.rb} +24 -5
- data/test/models/email_notification_test.rb +297 -0
- data/test/models/notification_test.rb +127 -0
- data/test/models/slack_notification_test.rb +50 -0
- data/test/notification_test_helper.rb +146 -0
- data/test/rails_setup.rb +4 -0
- data/test/test_helper.rb +10 -4
- data/test/test_models_helper.rb +14 -0
- data/web47core.gemspec +5 -2
- metadata +87 -14
- data/lib/app/models/concerns/auto_clear_cache.rb +0 -34
- data/lib/app/models/concerns/formable.rb +0 -111
- data/test/models/concerns/auto_clear_cache_test.rb +0 -27
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NotificationTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
should_have_field :retries, type: Integer, default: 0, klass: Notification
|
6
|
+
should_have_field :state, type: String, default: 'new', klass: Notification
|
7
|
+
should_have_field :to, type: String, klass: Notification
|
8
|
+
should_have_field :message, type: String, klass: Notification
|
9
|
+
should_have_field :error_message, type: String, klass: Notification
|
10
|
+
should_have_field :last_viewed_at, type: Time, klass: Notification
|
11
|
+
should_have_field :viewed_count, type: Integer, default: 0, klass: Notification
|
12
|
+
|
13
|
+
setup do
|
14
|
+
@account = FactoryBot.create(:account)
|
15
|
+
end
|
16
|
+
|
17
|
+
should 'Determine which states are deletable' do
|
18
|
+
notification = FactoryBot.create(:notification)
|
19
|
+
assert notification.deletable?
|
20
|
+
notification.set(state: Notification::STATE_SUBMITTED)
|
21
|
+
refute notification.deletable?
|
22
|
+
notification.set(state: Notification::STATE_PROCESSING)
|
23
|
+
refute notification.deletable?
|
24
|
+
notification.set(state: Notification::STATE_PROCESSED)
|
25
|
+
assert notification.deletable?
|
26
|
+
notification.set(state: Notification::STATE_INVALID)
|
27
|
+
assert notification.deletable?
|
28
|
+
notification.set(state: Notification::STATE_RETRYING)
|
29
|
+
refute notification.deletable?
|
30
|
+
notification.set(state: Notification::STATE_VIEWED)
|
31
|
+
assert notification.deletable?
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'Determine which states are sendable' do
|
35
|
+
notification = FactoryBot.create(:notification)
|
36
|
+
assert notification.sendable?
|
37
|
+
notification.set(state: Notification::STATE_SUBMITTED)
|
38
|
+
refute notification.sendable?
|
39
|
+
notification.set(state: Notification::STATE_PROCESSING)
|
40
|
+
refute notification.sendable?
|
41
|
+
notification.set(state: Notification::STATE_PROCESSED)
|
42
|
+
assert notification.sendable?
|
43
|
+
notification.set(state: Notification::STATE_INVALID)
|
44
|
+
assert notification.sendable?
|
45
|
+
notification.set(state: Notification::STATE_RETRYING)
|
46
|
+
refute notification.sendable?
|
47
|
+
notification.set(state: Notification::STATE_VIEWED)
|
48
|
+
assert notification.sendable?
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
should 'find file based template' do
|
53
|
+
notification = FactoryBot.create(:notification, account: @account)
|
54
|
+
notification.message_from_template('notification_failure', {error_message: 'Yo, Adrian'})
|
55
|
+
assert notification.message.include? 'Failed to send the following notification'
|
56
|
+
assert notification.message.include? 'Yo, Adrian'
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# should 'find account based template' do
|
61
|
+
# template = AccountEmailTemplate.new
|
62
|
+
# template.account = @account
|
63
|
+
# template.name = 'enterprise_app_store_user_invite'
|
64
|
+
# template.template = 'custom baby {{ name }}'
|
65
|
+
# template.subject = 'yo'
|
66
|
+
# assert template.save
|
67
|
+
#
|
68
|
+
# notification = FactoryBot.create(:notification, account: @account)
|
69
|
+
# notification.message_from_template('enterprise_app_store_user_invite', {'name'=> 'foo'})
|
70
|
+
# assert_equal '<body><pre>custom baby foo</pre></body>', notification.message
|
71
|
+
# end
|
72
|
+
|
73
|
+
should 'mark notification as viewed' do
|
74
|
+
notification = FactoryBot.create(:notification, account:@account)
|
75
|
+
assert_not_nil notification
|
76
|
+
assert_equal 0, notification.viewed_count
|
77
|
+
assert_nil notification.last_viewed_at
|
78
|
+
|
79
|
+
# Allow some breather room
|
80
|
+
sleep 1
|
81
|
+
|
82
|
+
notification.viewed
|
83
|
+
assert_not_nil notification.reload
|
84
|
+
assert_equal Notification::STATE_VIEWED, notification.state
|
85
|
+
assert_equal 1, notification.viewed_count
|
86
|
+
first_date = notification.last_viewed_at
|
87
|
+
|
88
|
+
# Allow some breather room
|
89
|
+
sleep 1
|
90
|
+
|
91
|
+
# view it a second time, should up the counter
|
92
|
+
notification.viewed
|
93
|
+
assert_not_nil notification.reload
|
94
|
+
assert_equal Notification::STATE_VIEWED, notification.state
|
95
|
+
assert_equal 2, notification.viewed_count
|
96
|
+
assert_not_equal first_date, notification.last_viewed_at, notification.inspect
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
context 'use both token and strings' do
|
101
|
+
setup do
|
102
|
+
@liquid_text = 'Yo {{ name }}'
|
103
|
+
@notification = Notification.new
|
104
|
+
end
|
105
|
+
|
106
|
+
should 'work with strings' do
|
107
|
+
params = { 'name' => 'chris' }
|
108
|
+
assert_equal 'Yo chris', @notification.send(:render_liquid_text, @liquid_text, params)
|
109
|
+
end
|
110
|
+
|
111
|
+
should 'work with tokens' do
|
112
|
+
params = { name: 'chris' }
|
113
|
+
assert_equal 'Yo chris', @notification.send(:render_liquid_text, @liquid_text, params)
|
114
|
+
end
|
115
|
+
|
116
|
+
should 'handle true values' do
|
117
|
+
liquid_text = 'Yo{% if show %} {{ name }}{% endif %}'
|
118
|
+
params = { name: 'chris', show: true}
|
119
|
+
assert_equal 'Yo chris', @notification.send(:render_liquid_text, liquid_text, params)
|
120
|
+
end
|
121
|
+
should 'handle false values' do
|
122
|
+
liquid_text = 'Yo{% if show %} {{ name }}{% endif %}'
|
123
|
+
params = { name: 'chris', show: false}
|
124
|
+
assert_equal 'Yo', @notification.send(:render_liquid_text, liquid_text, params)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'notification_test_helper'
|
3
|
+
|
4
|
+
class SlackNotificationTest < ActiveSupport::TestCase
|
5
|
+
include App47Logger
|
6
|
+
include NotificationTestHelper
|
7
|
+
|
8
|
+
should_have_field :from, type: String, klass: SlackNotification
|
9
|
+
|
10
|
+
setup do
|
11
|
+
config = SystemConfiguration.configuration
|
12
|
+
config.update_attribute :slack_api_url, 'https://slack.com?api_key'
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'No slack notification' do
|
16
|
+
should 'not create a slack notification with log_debug' do
|
17
|
+
App47Logger.expects(:log_message).with(:warn, 'Test log message').once
|
18
|
+
log_warn 'Test log message'
|
19
|
+
assert_no_slacks
|
20
|
+
end
|
21
|
+
end
|
22
|
+
context 'send notification' do
|
23
|
+
should 'Log error message' do
|
24
|
+
stub = stub_request(:post, "https://slack.com/?api_key").
|
25
|
+
with(body: "{\"text\":\"*ERROR:* `Test log message`\",\"channel\":\"support\",\"username\":\"test\"}").
|
26
|
+
to_return(status: 200, body: "", headers: {})
|
27
|
+
App47Logger.expects(:log_message).with(:error, 'Test log message').once
|
28
|
+
log_error 'Test log message'
|
29
|
+
assert_slacks_count
|
30
|
+
assert_slacks_includes('Test log message')
|
31
|
+
assert_requested stub
|
32
|
+
end
|
33
|
+
should 'Log error with exception' do
|
34
|
+
stub = stub_request(:post, "https://slack.com/?api_key").
|
35
|
+
with(body: "{\"text\":\"*ERROR:* `Test log message` - `Ex`\",\"channel\":\"support\",\"username\":\"test\"}").
|
36
|
+
to_return(status: 200, body: "", headers: {})
|
37
|
+
App47Logger.expects(:log_message).with(:error, 'Test log message').once
|
38
|
+
App47Logger.expects(:log_message).with(:error, 'Ex').once
|
39
|
+
ex = Exception.new('Ex')
|
40
|
+
log_error 'Test log message', ex
|
41
|
+
assert_slacks_count
|
42
|
+
assert_slacks_includes(['Test log message', ex.message])
|
43
|
+
assert_requested stub
|
44
|
+
end
|
45
|
+
should 'send a message to slack' do
|
46
|
+
stub_request(:post, SystemConfiguration.slack_api_url).to_return(status: 200)
|
47
|
+
SlackNotification.say 'mess'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module NotificationTestHelper
|
2
|
+
# helper to assert no emails were sent.
|
3
|
+
def assert_no_emails(account = nil)
|
4
|
+
assert_emails_count(account, 0)
|
5
|
+
end
|
6
|
+
|
7
|
+
def assert_emails_count(account = nil, count = 1)
|
8
|
+
assert_equal count, email_notifications(account).count
|
9
|
+
end
|
10
|
+
|
11
|
+
def assert_emails_subject(subject, account = nil)
|
12
|
+
assert_emails_field(:subject, subject, account)
|
13
|
+
end
|
14
|
+
|
15
|
+
def assert_emails_from(from, account = nil)
|
16
|
+
assert_emails_field(:from, from, account)
|
17
|
+
end
|
18
|
+
|
19
|
+
def assert_emails_to(to, account = nil)
|
20
|
+
assert_emails_field(:to, to, account)
|
21
|
+
end
|
22
|
+
|
23
|
+
def assert_emails_reply_to(reply_to, account = nil)
|
24
|
+
assert_emails_field(:reply_to, reply_to, account)
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_emails_includes(parts, account = nil)
|
28
|
+
assert_notifications_includes(email_notifications(account), parts)
|
29
|
+
end
|
30
|
+
|
31
|
+
def assert_emails_excludes(parts, account = nil)
|
32
|
+
assert_notifications_excludes(email_notifications(account), parts)
|
33
|
+
end
|
34
|
+
|
35
|
+
def assert_emails_attachment_count(account = nil, count = 1)
|
36
|
+
email_notifications(account).each do |email|
|
37
|
+
assert_equal count, email.attachments.count
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
########################
|
42
|
+
# Slack notifications
|
43
|
+
#
|
44
|
+
# helper to assert no slack messages were sent.
|
45
|
+
def assert_no_slacks(account = nil)
|
46
|
+
assert_slacks_count(account, 0)
|
47
|
+
end
|
48
|
+
|
49
|
+
def assert_slacks_count(account = nil, count = 1)
|
50
|
+
assert_equal count, slack_notifications(account).where(state:'processed').count, 'Incorrect number of notifications sent'
|
51
|
+
end
|
52
|
+
|
53
|
+
def assert_slacks_includes(parts, account = nil)
|
54
|
+
assert_notifications_includes(slack_notifications(account), parts)
|
55
|
+
end
|
56
|
+
|
57
|
+
def assert_slacks_excludes(parts, account = nil)
|
58
|
+
assert_notifications_excludes(slack_notifications(account), parts)
|
59
|
+
end
|
60
|
+
|
61
|
+
########################
|
62
|
+
# SMS notifications
|
63
|
+
#
|
64
|
+
def assert_no_sms(account = nil)
|
65
|
+
assert_sms_count(account, 0)
|
66
|
+
end
|
67
|
+
|
68
|
+
def assert_sms_count(account = nil, count = 1)
|
69
|
+
assert_equal count, sms_notifications(account).count, 'Incorrect number of notifications sent'
|
70
|
+
end
|
71
|
+
|
72
|
+
def assert_sms_includes(parts, account = nil)
|
73
|
+
assert_notifications_includes(sms_notifications(account), parts)
|
74
|
+
end
|
75
|
+
|
76
|
+
def assert_sms_excludes(parts, account = nil)
|
77
|
+
assert_notifications_excludes(sms_notifications(account), parts)
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def assert_emails_field(field, value, account = nil)
|
83
|
+
email_notifications(account).each do |email|
|
84
|
+
assert_equal value, email.send(field), "Incorrect #{field}: #{email.inspect}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
# Assert the list of notifications include parts in the message of the notification
|
90
|
+
#
|
91
|
+
def assert_notifications_includes(notifications, parts)
|
92
|
+
raise 'No matching notifications to compare' if notifications.blank?
|
93
|
+
|
94
|
+
notifications.each do |notification|
|
95
|
+
message = notification.message
|
96
|
+
assert_not_nil message, "Message should not be nil: #{notification.inspect}"
|
97
|
+
parts = [parts] unless parts.is_a?(Array)
|
98
|
+
parts.each do |part|
|
99
|
+
assert message.to_s.include?(part), "Does not have message part '#{part}' in message: \n#{message}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
#
|
105
|
+
# Assert the list of notifications exclude parts in the message of the notification
|
106
|
+
#
|
107
|
+
def assert_notifications_excludes(notifications, parts)
|
108
|
+
raise 'No matching notifications to compare' if notifications.blank?
|
109
|
+
|
110
|
+
notifications.each do |notification|
|
111
|
+
message = notification.message
|
112
|
+
assert_not_nil message, "Message should not be nil: #{notification.inspect}"
|
113
|
+
parts = [parts] unless parts.is_a?(Array)
|
114
|
+
parts.each do |part|
|
115
|
+
refute message.to_s.include?(part), "Message should not have part '#{part}' in message: \n#{message}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Get email notifications for an account
|
122
|
+
#
|
123
|
+
def email_notifications(account = nil)
|
124
|
+
return EmailNotification.all if account.nil?
|
125
|
+
|
126
|
+
account.is_a?(Account) ? account.notifications.emails : EmailNotification.where(account_id: account)
|
127
|
+
end
|
128
|
+
|
129
|
+
#
|
130
|
+
# Get slack notifications for an account
|
131
|
+
#
|
132
|
+
def slack_notifications(account = nil)
|
133
|
+
return SlackNotification.all if account.nil?
|
134
|
+
|
135
|
+
account.is_a?(Account) ? account.notifications.slacks : SlackNotification.where(account_id: account)
|
136
|
+
end
|
137
|
+
|
138
|
+
#
|
139
|
+
# Get SMS notification for an account
|
140
|
+
#
|
141
|
+
def sms_notifications(account = nil)
|
142
|
+
return SmsNotification.all if account.nil?
|
143
|
+
|
144
|
+
account.is_a?(Account) ? account.notifications.sms : SmsNotification.where(account_id: account)
|
145
|
+
end
|
146
|
+
end
|
data/test/rails_setup.rb
CHANGED
@@ -23,6 +23,8 @@ require 'rails'
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
require 'mail'
|
27
|
+
|
26
28
|
# Require the gems listed in Gemfile, including any gems
|
27
29
|
# you've limited to :test, :development, or :production.
|
28
30
|
Bundler.require(*Rails.groups)
|
@@ -53,5 +55,7 @@ module WebCore
|
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
58
|
+
Delayed::Worker.delay_jobs = false
|
59
|
+
|
56
60
|
# Initialize the Rails application.
|
57
61
|
Rails.application.initialize!
|
data/test/test_helper.rb
CHANGED
@@ -15,7 +15,12 @@ if ENV['CODACY_PROJECT_TOKEN']
|
|
15
15
|
end
|
16
16
|
|
17
17
|
require 'rubygems'
|
18
|
+
require 'aws-sdk-ec2'
|
18
19
|
require 'mongoid'
|
20
|
+
require 'delayed_job_mongoid'
|
21
|
+
require 'liquid'
|
22
|
+
require 'jwt'
|
23
|
+
require 'rest-client'
|
19
24
|
require_relative 'rails_setup'
|
20
25
|
require 'rails/test_help'
|
21
26
|
require 'test/unit'
|
@@ -35,10 +40,7 @@ else
|
|
35
40
|
Minitest::Reporters.use!(Minitest::Reporters::RubyMineReporter.new)
|
36
41
|
end
|
37
42
|
|
38
|
-
|
39
|
-
include StandardModel
|
40
|
-
include CoreSystemConfiguration
|
41
|
-
end
|
43
|
+
require 'test_models_helper'
|
42
44
|
|
43
45
|
module ActiveSupport
|
44
46
|
class TestCase
|
@@ -55,8 +57,10 @@ module ActiveSupport
|
|
55
57
|
end
|
56
58
|
teardown do
|
57
59
|
DatabaseCleaner.clean
|
60
|
+
Mail::TestMailer.deliveries.clear
|
58
61
|
mocha_teardown
|
59
62
|
WebMock.disable!
|
63
|
+
WebMock.reset!
|
60
64
|
end
|
61
65
|
end
|
62
66
|
end
|
@@ -76,8 +80,10 @@ module ActionDispatch
|
|
76
80
|
end
|
77
81
|
teardown do
|
78
82
|
DatabaseCleaner.clean
|
83
|
+
Mail::TestMailer.deliveries.clear
|
79
84
|
mocha_teardown
|
80
85
|
WebMock.disable!
|
86
|
+
WebMock.reset!
|
81
87
|
end
|
82
88
|
end
|
83
89
|
end
|
data/web47core.gemspec
CHANGED
@@ -8,7 +8,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
8
8
|
Gem::Specification.new do |spec|
|
9
9
|
spec.required_ruby_version = '~> 2.4.1'
|
10
10
|
spec.name = 'web47core'
|
11
|
-
spec.version = '0.0.
|
11
|
+
spec.version = '0.0.9'
|
12
12
|
spec.authors = ['Chris Schroeder']
|
13
13
|
spec.email = ['chris@app47.com']
|
14
14
|
spec.summary = 'App47 Web Core Library.'
|
@@ -22,14 +22,17 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ['lib']
|
23
23
|
|
24
24
|
# spec.add_dependency 'json'
|
25
|
-
spec.add_runtime_dependency 'aws-sdk-ec2', '
|
25
|
+
spec.add_runtime_dependency 'aws-sdk-ec2', '> 1.140', '<= 1.160'
|
26
26
|
spec.add_runtime_dependency 'activesupport', '~> 5.0'
|
27
27
|
spec.add_runtime_dependency 'delayed_job_mongoid', '~> 2.3'
|
28
|
+
spec.add_runtime_dependency 'haml'
|
28
29
|
spec.add_runtime_dependency 'jwt'
|
30
|
+
spec.add_runtime_dependency 'liquid'
|
29
31
|
spec.add_runtime_dependency 'mongoid', '> 6', '< 7'
|
30
32
|
spec.add_runtime_dependency 'rails', '< 5.3', '>= 4.2'
|
31
33
|
spec.add_runtime_dependency 'redis', '~> 4.1'
|
32
34
|
spec.add_runtime_dependency 'redis-rails', '> 5', '< 6'
|
35
|
+
spec.add_runtime_dependency 'rest-client', '<= 2.1.0', '>=0'
|
33
36
|
spec.add_development_dependency 'bundler'
|
34
37
|
spec.add_development_dependency 'codacy-coverage', '~> 2.1.0'
|
35
38
|
spec.add_development_dependency 'database_cleaner'
|
metadata
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web47core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schroeder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-ec2
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.140'
|
20
20
|
- - "<="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '1.
|
22
|
+
version: '1.160'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
29
|
+
version: '1.140'
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '1.
|
32
|
+
version: '1.160'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,20 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '2.3'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: haml
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
61
75
|
- !ruby/object:Gem::Dependency
|
62
76
|
name: jwt
|
63
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,6 +86,20 @@ dependencies:
|
|
72
86
|
- - ">="
|
73
87
|
- !ruby/object:Gem::Version
|
74
88
|
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: liquid
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
75
103
|
- !ruby/object:Gem::Dependency
|
76
104
|
name: mongoid
|
77
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +174,26 @@ dependencies:
|
|
146
174
|
- - "<"
|
147
175
|
- !ruby/object:Gem::Version
|
148
176
|
version: '6'
|
177
|
+
- !ruby/object:Gem::Dependency
|
178
|
+
name: rest-client
|
179
|
+
requirement: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
- - "<="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: 2.1.0
|
187
|
+
type: :runtime
|
188
|
+
prerelease: false
|
189
|
+
version_requirements: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
version: '0'
|
194
|
+
- - "<="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: 2.1.0
|
149
197
|
- !ruby/object:Gem::Dependency
|
150
198
|
name: bundler
|
151
199
|
requirement: !ruby/object:Gem::Requirement
|
@@ -399,20 +447,38 @@ files:
|
|
399
447
|
- LICENSE
|
400
448
|
- README.md
|
401
449
|
- Rakefile
|
402
|
-
- lib/app/models/concerns/
|
450
|
+
- lib/app/models/concerns/app47_logger.rb
|
403
451
|
- lib/app/models/concerns/cdn_url.rb
|
452
|
+
- lib/app/models/concerns/core_account.rb
|
404
453
|
- lib/app/models/concerns/core_system_configuration.rb
|
405
|
-
- lib/app/models/concerns/formable.rb
|
406
454
|
- lib/app/models/concerns/standard_model.rb
|
455
|
+
- lib/app/models/email_notification.rb
|
456
|
+
- lib/app/models/email_template.rb
|
457
|
+
- lib/app/models/notification.rb
|
458
|
+
- lib/app/models/notification_template.rb
|
459
|
+
- lib/app/models/slack_notification.rb
|
460
|
+
- lib/app/models/sms_notification.rb
|
461
|
+
- lib/app/models/smtp_configuration.rb
|
462
|
+
- lib/app/models/template.rb
|
463
|
+
- lib/templates/email/notification_failure.liquid
|
464
|
+
- lib/templates/email/notification_failure.subject.liquid
|
465
|
+
- lib/templates/slack/error_message.liquid
|
407
466
|
- lib/web47core.rb
|
467
|
+
- test/factories/account_factories.rb
|
468
|
+
- test/factories/notification_factories.rb
|
408
469
|
- test/fixtures/mongoid.yml
|
409
|
-
- test/models/
|
470
|
+
- test/models/app47_logger_test.rb
|
410
471
|
- test/models/concerns/cdn_url_test.rb
|
411
|
-
- test/models/concerns/
|
472
|
+
- test/models/concerns/standard_model_test.rb
|
412
473
|
- test/models/concerns/system_configuration_test.rb
|
474
|
+
- test/models/email_notification_test.rb
|
475
|
+
- test/models/notification_test.rb
|
476
|
+
- test/models/slack_notification_test.rb
|
477
|
+
- test/notification_test_helper.rb
|
413
478
|
- test/rails_setup.rb
|
414
479
|
- test/shoulda_macros/mongoid.rb
|
415
480
|
- test/test_helper.rb
|
481
|
+
- test/test_models_helper.rb
|
416
482
|
- web47core.gemspec
|
417
483
|
homepage: https://app47.com
|
418
484
|
licenses:
|
@@ -438,11 +504,18 @@ signing_key:
|
|
438
504
|
specification_version: 4
|
439
505
|
summary: App47 Web Core Library.
|
440
506
|
test_files:
|
507
|
+
- test/factories/account_factories.rb
|
508
|
+
- test/factories/notification_factories.rb
|
441
509
|
- test/fixtures/mongoid.yml
|
442
|
-
- test/models/
|
510
|
+
- test/models/app47_logger_test.rb
|
443
511
|
- test/models/concerns/cdn_url_test.rb
|
444
|
-
- test/models/concerns/
|
512
|
+
- test/models/concerns/standard_model_test.rb
|
445
513
|
- test/models/concerns/system_configuration_test.rb
|
514
|
+
- test/models/email_notification_test.rb
|
515
|
+
- test/models/notification_test.rb
|
516
|
+
- test/models/slack_notification_test.rb
|
517
|
+
- test/notification_test_helper.rb
|
446
518
|
- test/rails_setup.rb
|
447
519
|
- test/shoulda_macros/mongoid.rb
|
448
520
|
- test/test_helper.rb
|
521
|
+
- test/test_models_helper.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#
|
4
|
-
# Clear the Rails.cache when this object is saved. This prevents a number of
|
5
|
-
# caching issues over time where we've put it in cache, but the update doesn't appear
|
6
|
-
# until that cache expires.
|
7
|
-
#
|
8
|
-
module AutoClearCache
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
#
|
12
|
-
# Add the call backs to the class being included.
|
13
|
-
#
|
14
|
-
def self.included(base)
|
15
|
-
base.class_eval do
|
16
|
-
# Add the call back to the class
|
17
|
-
after_save :clear_cache
|
18
|
-
before_destroy :clear_cache
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
#
|
23
|
-
# Clear the cache
|
24
|
-
#
|
25
|
-
def clear_cache
|
26
|
-
Rails.cache.delete_matched "*#{id}*"
|
27
|
-
return unless respond_to?(:account) && account.present? && account.is_a?(Account)
|
28
|
-
|
29
|
-
Rails.cache.delete_matched "*#{account.id}*"
|
30
|
-
true # Force a return of true so that we don't break the callback chain.
|
31
|
-
rescue StandardError
|
32
|
-
false
|
33
|
-
end
|
34
|
-
end
|