web47core 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{lib/app → app}/assets/stylesheets/status.sass +0 -0
- data/{lib/app → app}/controllers/status_controller.rb +0 -0
- data/{lib/app → app}/views/status/index.html.haml +0 -0
- metadata +6 -79
- data/.circleci/config.yml +0 -58
- data/.gitignore +0 -70
- data/.rubocop.yml +0 -33
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -318
- data/Rakefile +0 -7
- data/bin/cron_server +0 -4
- data/test/controllers/status_controller_test.rb +0 -158
- data/test/factories/account_factories.rb +0 -9
- data/test/factories/notification_factories.rb +0 -14
- data/test/fixtures/mongoid.yml +0 -8
- data/test/fixtures/redis/host.yml +0 -5
- data/test/fixtures/redis/options.yml +0 -8
- data/test/fixtures/redis/sentinel.yml +0 -8
- data/test/fixtures/redis/url.yml +0 -2
- data/test/jobs/cron/server_test.rb +0 -160
- data/test/jobs/cron/switchboard_sync_configuration_test.rb +0 -64
- data/test/jobs/cron/trim_cron_servers_test.rb +0 -28
- data/test/jobs/cron/trim_failed_delayed_jobs_test.rb +0 -71
- data/test/models/concerns/app47_logger_test.rb +0 -88
- data/test/models/concerns/cdn_url_test.rb +0 -54
- data/test/models/concerns/email_able_test.rb +0 -145
- data/test/models/concerns/search_able_test.rb +0 -80
- data/test/models/concerns/standard_model_test.rb +0 -154
- data/test/models/concerns/system_configuration_test.rb +0 -212
- data/test/models/concerns/time_zone_able_test.rb +0 -77
- data/test/models/email_notification_test.rb +0 -297
- data/test/models/job_cron_tab_test.rb +0 -25
- data/test/models/notification_test.rb +0 -127
- data/test/models/redis_configuration_test.rb +0 -86
- data/test/models/slack_notification_test.rb +0 -91
- data/test/models/sms_notification_test.rb +0 -69
- data/test/models/smtp_configuration_test.rb +0 -66
- data/test/models/web47core_test.rb +0 -18
- data/test/notification_test_helper.rb +0 -146
- data/test/rails_setup.rb +0 -61
- data/test/shoulda_macros/mongoid.rb +0 -70
- data/test/test_helper.rb +0 -93
- data/test/test_models_helper.rb +0 -14
- data/web47core.gemspec +0 -58
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Cron
|
4
|
-
class TrimCronServersTest < ActiveSupport::TestCase
|
5
|
-
context 'Execute job not deleting servers' do
|
6
|
-
should 'not throw exceptions if no servers ' do
|
7
|
-
assert_nothing_raised { Cron::TrimCronServers.perform_now }
|
8
|
-
end
|
9
|
-
should 'not delete any servers due to last updated' do
|
10
|
-
10.times.each { |n| Cron::Server.create!(host_name: "ip-#{n}", pid: n.to_s).set(last_check_in_at: Time.now.utc) }
|
11
|
-
assert_equal 10, Cron::Server.all.count
|
12
|
-
assert_no_difference 'Cron::Server.all.count' do
|
13
|
-
assert_nothing_raised { Cron::TrimCronServers.perform_now }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
context 'Execute jobs deleting servers' do
|
18
|
-
should 'delete five server logs' do
|
19
|
-
5.times.each { |n| Cron::Server.create!(host_name: "ip-#{n}", pid: n.to_s).set(last_check_in_at: Time.now.utc) }
|
20
|
-
5.times.each { |n| Cron::Server.create!(host_name: "ip-#{n}", pid: (100+n).to_s).set(last_check_in_at: 1.hour.ago.utc) }
|
21
|
-
assert_equal 10, Cron::Server.all.count
|
22
|
-
assert_difference 'Cron::Server.all.count', -5 do
|
23
|
-
assert_nothing_raised { Cron::TrimCronServers.perform_now }
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'notification_test_helper'
|
3
|
-
module Cron
|
4
|
-
class TrimFailedDelayedJobsTest < ActiveSupport::TestCase
|
5
|
-
include NotificationTestHelper
|
6
|
-
context 'Execute with no jobs' do
|
7
|
-
should 'run with no issue' do
|
8
|
-
assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
context 'handle failed job' do
|
12
|
-
setup do
|
13
|
-
SystemConfiguration.configuration.update slack_api_url: 'https://slack.test.com'
|
14
|
-
stub_request(:post, "https://slack.test.com/").to_return(status: 200, body: "", headers: {})
|
15
|
-
Delayed::Worker.delay_jobs = true
|
16
|
-
# Create the job that should be deleted
|
17
|
-
o = TestBGJob.create!
|
18
|
-
o.update_name
|
19
|
-
o.destroy!
|
20
|
-
Delayed::Backend::Mongoid::Job.first.set failed_at: Time.now.utc
|
21
|
-
end
|
22
|
-
teardown do
|
23
|
-
Delayed::Worker.delay_jobs = false
|
24
|
-
end
|
25
|
-
should 'remove one job' do
|
26
|
-
assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
|
27
|
-
assert_empty Delayed::Backend::Mongoid::Job.all
|
28
|
-
assert_slacks_count nil, 1
|
29
|
-
assert_slacks_includes ['*Delayed Jobs Failed* due to missing document, ~removing from queue!~',
|
30
|
-
'*Object:* ```',
|
31
|
-
'*Method:* `',
|
32
|
-
'*Arguments:* ``']
|
33
|
-
end
|
34
|
-
should 'remove two jobs' do
|
35
|
-
o = TestBGJob.create!
|
36
|
-
o.update_name
|
37
|
-
o.destroy!
|
38
|
-
Delayed::Backend::Mongoid::Job.each { |d| d.set failed_at: Time.now.utc }
|
39
|
-
assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
|
40
|
-
assert_empty Delayed::Backend::Mongoid::Job.all
|
41
|
-
assert_slacks_count nil, 2
|
42
|
-
end
|
43
|
-
should 'only remove one' do
|
44
|
-
o = TestBGJob.create!
|
45
|
-
o.update_name
|
46
|
-
o.destroy!
|
47
|
-
assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
|
48
|
-
assert_equal 1, Delayed::Backend::Mongoid::Job.all.count
|
49
|
-
assert_slacks_count nil, 1
|
50
|
-
end
|
51
|
-
should 'only remove one failed missing doc job' do
|
52
|
-
o = TestBGJob.create!
|
53
|
-
o.update_name
|
54
|
-
assert_nothing_raised { Cron::TrimFailedDelayedJobs.perform_now }
|
55
|
-
assert_equal 1, Delayed::Backend::Mongoid::Job.all.count
|
56
|
-
assert_slacks_count nil, 1
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class TestBGJob
|
63
|
-
include StandardModel
|
64
|
-
field :name, type: String
|
65
|
-
|
66
|
-
def update_name
|
67
|
-
set name: 'bg'
|
68
|
-
end
|
69
|
-
|
70
|
-
handle_asynchronously :update_name
|
71
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class App47LoggerTestCase < ActiveSupport::TestCase
|
4
|
-
include App47Logger
|
5
|
-
context 'as singleton' do
|
6
|
-
should 'log a debug message' do
|
7
|
-
App47Logger.expects(:log_message).once
|
8
|
-
App47Logger.log_debug('Foo')
|
9
|
-
end
|
10
|
-
should 'log a warn message with out exception' do
|
11
|
-
App47Logger.expects(:log_message).once
|
12
|
-
App47Logger.log_warn('Foo')
|
13
|
-
end
|
14
|
-
should 'log a warn message with exception' do
|
15
|
-
App47Logger.expects(:log_message).twice
|
16
|
-
App47Logger.log_warn('Foo', Exception.new)
|
17
|
-
end
|
18
|
-
should 'log a error message with out exception' do
|
19
|
-
App47Logger.expects(:log_message).once
|
20
|
-
App47Logger.log_error('Foo')
|
21
|
-
end
|
22
|
-
should 'log a error message with exception' do
|
23
|
-
App47Logger.expects(:log_message).twice
|
24
|
-
App47Logger.log_error('Foo', Exception.new)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'as class method' do
|
29
|
-
should 'log a debug message' do
|
30
|
-
App47Logger.expects(:log_message).once
|
31
|
-
log_debug('Foo')
|
32
|
-
end
|
33
|
-
should 'log a message' do
|
34
|
-
App47Logger.expects(:log_message).once
|
35
|
-
log_message(:debug, 'Foo')
|
36
|
-
end
|
37
|
-
should 'log a warn message with out exception' do
|
38
|
-
App47Logger.expects(:log_message).once
|
39
|
-
log_warn('Foo')
|
40
|
-
end
|
41
|
-
should 'log a warn message with exception' do
|
42
|
-
App47Logger.expects(:log_message).twice
|
43
|
-
log_warn('Foo', Exception.new)
|
44
|
-
end
|
45
|
-
should 'log a error message with out exception' do
|
46
|
-
App47Logger.expects(:log_message).once
|
47
|
-
SlackNotification.expects(:say)
|
48
|
-
log_error('Foo')
|
49
|
-
end
|
50
|
-
should 'log a error message with exception' do
|
51
|
-
App47Logger.expects(:log_message).twice
|
52
|
-
SlackNotification.expects(:say)
|
53
|
-
log_error('Foo', Exception.new)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'log message' do
|
58
|
-
should 'Log debug' do
|
59
|
-
App47Logger.expects(:puts).once
|
60
|
-
App47Logger.log_debug('Foo')
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
context 'as a controller' do
|
65
|
-
should 'log a controller' do
|
66
|
-
App47Logger.expects(:log_message).once
|
67
|
-
log_controller_error(nil)
|
68
|
-
end
|
69
|
-
should 'log a controller with exception' do
|
70
|
-
App47Logger.expects(:log_message).twice
|
71
|
-
log_controller_error(Exception.new('Message'))
|
72
|
-
end
|
73
|
-
end
|
74
|
-
#
|
75
|
-
# Support the testing of log_controller_error
|
76
|
-
#
|
77
|
-
def controller_name
|
78
|
-
'tester'
|
79
|
-
end
|
80
|
-
|
81
|
-
def action_name
|
82
|
-
'tester'
|
83
|
-
end
|
84
|
-
|
85
|
-
def params
|
86
|
-
{}
|
87
|
-
end
|
88
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class CdnUrlTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
setup do
|
6
|
-
@original_url = 'https://s3.amazon.com/test_bucket/test_cdn_url_models/id/original.png'
|
7
|
-
@model = TestCdnUrlModel.new
|
8
|
-
@model.file_url = @original_url
|
9
|
-
assert @model.save
|
10
|
-
end
|
11
|
-
|
12
|
-
context 'CDN not setup' do
|
13
|
-
|
14
|
-
should 'not respond to errant entry' do
|
15
|
-
assert_raises(NoMethodError) { @model.cdn_bad_url }
|
16
|
-
end
|
17
|
-
|
18
|
-
should 'return the original url' do
|
19
|
-
assert_equal @original_url, @model.file_url
|
20
|
-
assert_equal @original_url, @model.cdn_file_url
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context 'CDN setup' do
|
25
|
-
setup do
|
26
|
-
@cdn_url = 'https://9asdfasd9asd.amazon.com'
|
27
|
-
config = SystemConfiguration.configuration
|
28
|
-
assert config.update cdn_url: @cdn_url
|
29
|
-
end
|
30
|
-
should 'return CDN url' do
|
31
|
-
assert_equal @original_url, @model.file_url
|
32
|
-
assert_not_equal @original_url, @model.cdn_file_url
|
33
|
-
assert_equal "#{@cdn_url}/test_cdn_url_models/id/original.png", @model.cdn_file_url
|
34
|
-
end
|
35
|
-
should 'return CDN url with size' do
|
36
|
-
assert_equal "#{@original_url}?size=medium", @model.image_url('medium')
|
37
|
-
assert_equal "#{@cdn_url}/test_cdn_url_models/id/original.png?size=medium", @model.cdn_image_url('medium')
|
38
|
-
end
|
39
|
-
should 'return url' do
|
40
|
-
assert @model.update file_url: 'https://s3.amazon.com/test_bucket/another_model/id/original.png'
|
41
|
-
assert_equal 'https://s3.amazon.com/test_bucket/another_model/id/original.png', @model.cdn_file_url
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class TestCdnUrlModel
|
47
|
-
include Mongoid::Document
|
48
|
-
include CdnUrl
|
49
|
-
field :file_url, type: String
|
50
|
-
|
51
|
-
def image_url(size)
|
52
|
-
"#{file_url}?size=#{size}"
|
53
|
-
end
|
54
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Temp class for testing
|
5
|
-
#
|
6
|
-
class EmailModel
|
7
|
-
include Mongoid::Document
|
8
|
-
include Mongoid::Timestamps
|
9
|
-
include EmailAble
|
10
|
-
field :once, type: String
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
# Test the email model
|
15
|
-
#
|
16
|
-
class EmailModelTest < ActiveSupport::TestCase
|
17
|
-
should_have_field :email, type: String, klass: EmailModel
|
18
|
-
should_have_field :email_bounced_at, type: Time, klass: EmailModel
|
19
|
-
should_have_field :email_bounce_reason, type: String, klass: EmailModel
|
20
|
-
should_have_field :unconfirmed_email, type: String, klass: EmailModel
|
21
|
-
should_have_field :email_enabled, type: Mongoid::Boolean, default: true, klass: EmailModel
|
22
|
-
|
23
|
-
context 'valid email' do
|
24
|
-
should 'not be valid' do
|
25
|
-
email = EmailModel.new
|
26
|
-
email.email = 'nothing'
|
27
|
-
refute email.valid?
|
28
|
-
end
|
29
|
-
should 'be valid' do
|
30
|
-
email = EmailModel.new
|
31
|
-
email.email = 'joe@abc.com'
|
32
|
-
assert email.valid?
|
33
|
-
assert email.valid_email?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'valid_email?' do
|
38
|
-
setup do
|
39
|
-
@model = EmailModel.new
|
40
|
-
@email = 'known@abc.com'
|
41
|
-
@model.email = @email
|
42
|
-
assert @model.save
|
43
|
-
end
|
44
|
-
should 'be valid by default' do
|
45
|
-
assert @model.valid_email?
|
46
|
-
end
|
47
|
-
should 'not be valid with email_bounce_date' do
|
48
|
-
@model.email_bounced_at = Time.now.utc
|
49
|
-
refute @model.valid_email?
|
50
|
-
end
|
51
|
-
should 'not be valid with enabled turned off' do
|
52
|
-
@model.email_enabled = false
|
53
|
-
refute @model.valid_email?
|
54
|
-
end
|
55
|
-
should 'not be valid with enabled turned off and email_bounce_date' do
|
56
|
-
@model.email_bounced_at = Time.now.utc
|
57
|
-
@model.email_enabled = false
|
58
|
-
refute @model.valid_email?
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context 'reset bounce status with mailgun' do
|
63
|
-
setup do
|
64
|
-
@model = EmailModel.new
|
65
|
-
@email = 'known@abc.com'
|
66
|
-
@model.email = @email
|
67
|
-
@model.email_bounced_at = Time.now.utc
|
68
|
-
@model.email_bounce_reason = 'Testing'
|
69
|
-
assert @model.save
|
70
|
-
end
|
71
|
-
should 'not be called if not configured' do
|
72
|
-
config = SystemConfiguration.configuration
|
73
|
-
config.unset :mailgun_api_key
|
74
|
-
assert config.save
|
75
|
-
RestClient.expects(:delete).never
|
76
|
-
@model.reset_bounce_status
|
77
|
-
assert @model.valid_email?, @model.inspect
|
78
|
-
end
|
79
|
-
should 'reset bounce status' do
|
80
|
-
refute @model.valid_email?
|
81
|
-
config = SystemConfiguration.configuration
|
82
|
-
config.smtp_name = 'app47'
|
83
|
-
config.smtp_address = 'mail.app47.com'
|
84
|
-
config.smtp_domain = 'app47.com'
|
85
|
-
config.mailgun_api_key = 'key'
|
86
|
-
assert config.save
|
87
|
-
RestClient.expects(:delete).once.returns(MockHttpResponse.new)
|
88
|
-
@model.reset_bounce_status
|
89
|
-
assert_not_nil @model.reload
|
90
|
-
assert @model.valid_email?
|
91
|
-
end
|
92
|
-
should 'handle error code from rest client' do
|
93
|
-
App47Logger.expects(:log_error).once
|
94
|
-
refute @model.valid_email?
|
95
|
-
config = SystemConfiguration.configuration
|
96
|
-
config.smtp_name = 'app47'
|
97
|
-
config.smtp_address = 'mail.app47.com'
|
98
|
-
config.smtp_domain = 'app47.com'
|
99
|
-
config.mailgun_api_key = 'key'
|
100
|
-
assert config.save
|
101
|
-
RestClient.expects(:delete).once.raises(RestClient::Exception.new(MockHttpResponse.new(404)))
|
102
|
-
@model.reset_bounce_status
|
103
|
-
assert_not_nil @model.reload
|
104
|
-
assert @model.valid_email?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context 'gravatar_url' do
|
109
|
-
setup do
|
110
|
-
@model = EmailModel.new
|
111
|
-
@email = 'known@abc.com'
|
112
|
-
@model.email = @email
|
113
|
-
assert @model.save
|
114
|
-
end
|
115
|
-
should 'go to gravatar site' do
|
116
|
-
url = @model.gravatar_url
|
117
|
-
assert url.start_with? 'https://www.gravatar.com/avatar/', url
|
118
|
-
end
|
119
|
-
should 'correct defaults' do
|
120
|
-
url = @model.gravatar_url
|
121
|
-
assert url.include?('s=32'), url
|
122
|
-
assert url.include?('d=mm'), url
|
123
|
-
end
|
124
|
-
should 'override size' do
|
125
|
-
url = @model.gravatar_url(1024)
|
126
|
-
refute url.include?('s=32'), url
|
127
|
-
assert url.include?('s=1024'), url
|
128
|
-
end
|
129
|
-
should 'override default' do
|
130
|
-
url = @model.gravatar_url(1024, 'retro')
|
131
|
-
refute url.include?('d=mm'), url
|
132
|
-
assert url.include?('d=retro'), url
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
#
|
137
|
-
# Mock class for testing
|
138
|
-
#
|
139
|
-
class MockHttpResponse
|
140
|
-
attr_accessor :code
|
141
|
-
|
142
|
-
def initialize(code = 200)
|
143
|
-
@code = code
|
144
|
-
end
|
145
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SearchableTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
context 'Update search text on save' do
|
6
|
-
|
7
|
-
should 'update name' do
|
8
|
-
model = NameSearchable.new
|
9
|
-
assert model.save
|
10
|
-
assert_equal 'name', model.search_text
|
11
|
-
end
|
12
|
-
|
13
|
-
should 'update text' do
|
14
|
-
model = NameEmailSearchable.new
|
15
|
-
assert model.save
|
16
|
-
assert_equal 'name email@abc.com', model.search_text
|
17
|
-
end
|
18
|
-
should 'update text handle nil values' do
|
19
|
-
model = NameEmailCodeSearchable.new
|
20
|
-
assert model.save
|
21
|
-
assert_equal 'name email@abc.com', model.search_text
|
22
|
-
end
|
23
|
-
should 'update text with code' do
|
24
|
-
model = NameEmailCodeSearchable.new
|
25
|
-
model.code = 'FOOBar'
|
26
|
-
assert model.save
|
27
|
-
assert_equal 'name email@abc.com foobar', model.search_text
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'search for items' do
|
32
|
-
should 'update text' do
|
33
|
-
NameEmailSearchable.create
|
34
|
-
NameEmailSearchable.create
|
35
|
-
NameEmailSearchable.create
|
36
|
-
model = NameEmailSearchable.new
|
37
|
-
model.name = 'defJKL'
|
38
|
-
assert model.save
|
39
|
-
assert_not_nil model
|
40
|
-
assert_equal 'defjkl email@abc.com', model.search_text
|
41
|
-
assert_equal 1, NameEmailSearchable.matching_search_text('defjkl').count
|
42
|
-
end
|
43
|
-
should 'return sort order' do
|
44
|
-
assert_equal [['name', 1], ['email', 1]], NameEmailSearchable.sort_order
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class NameSearchable
|
50
|
-
include Mongoid::Document
|
51
|
-
include SearchAble
|
52
|
-
field :name, type: String, default: 'Name'
|
53
|
-
field :email, type: String, default: 'email@abc.com'
|
54
|
-
end
|
55
|
-
|
56
|
-
class NameEmailSearchable
|
57
|
-
include Mongoid::Document
|
58
|
-
include SearchAble
|
59
|
-
field :name, type: String, default: 'Name'
|
60
|
-
field :email, type: String, default: 'email@abc.com'
|
61
|
-
|
62
|
-
def search_fields
|
63
|
-
%w[name email]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class NameEmailCodeSearchable
|
68
|
-
include Mongoid::Document
|
69
|
-
include SearchAble
|
70
|
-
field :name, type: String, default: 'Name'
|
71
|
-
field :email, type: String, default: 'email@abc.com'
|
72
|
-
field :code, type: String
|
73
|
-
|
74
|
-
private
|
75
|
-
|
76
|
-
def search_fields
|
77
|
-
%w(name email code)
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|