dup_send_blocker 0.0.1

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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +26 -0
  4. data/app/assets/javascripts/dup_send_blocker/application.js +13 -0
  5. data/app/assets/stylesheets/dup_send_blocker/application.css +15 -0
  6. data/app/controllers/dup_send_blocker/application_controller.rb +5 -0
  7. data/app/helpers/dup_send_blocker/application_helper.rb +4 -0
  8. data/app/models/dup_send_blocker/send_log.rb +25 -0
  9. data/app/views/layouts/dup_send_blocker/application.html.erb +14 -0
  10. data/config/routes.rb +2 -0
  11. data/db/migrate/20201006085900_create_dup_send_blocker_send_logs.rb +25 -0
  12. data/lib/dup_send_blocker.rb +38 -0
  13. data/lib/dup_send_blocker/engine.rb +9 -0
  14. data/lib/dup_send_blocker/version.rb +3 -0
  15. data/lib/tasks/dup_send_blocker_tasks.rake +4 -0
  16. data/spec/dummy_app/README.rdoc +28 -0
  17. data/spec/dummy_app/Rakefile +6 -0
  18. data/spec/dummy_app/app/assets/config/manifest.js +3 -0
  19. data/spec/dummy_app/app/assets/javascripts/application.js +13 -0
  20. data/spec/dummy_app/app/assets/stylesheets/application.css +15 -0
  21. data/spec/dummy_app/app/controllers/application_controller.rb +5 -0
  22. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  23. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  24. data/spec/dummy_app/bin/bundle +3 -0
  25. data/spec/dummy_app/bin/rails +4 -0
  26. data/spec/dummy_app/bin/rake +4 -0
  27. data/spec/dummy_app/bin/setup +29 -0
  28. data/spec/dummy_app/config.ru +4 -0
  29. data/spec/dummy_app/config/application.rb +33 -0
  30. data/spec/dummy_app/config/boot.rb +5 -0
  31. data/spec/dummy_app/config/database.yml +23 -0
  32. data/spec/dummy_app/config/database.yml.bak +25 -0
  33. data/spec/dummy_app/config/environment.rb +5 -0
  34. data/spec/dummy_app/config/environments/development.rb +41 -0
  35. data/spec/dummy_app/config/environments/production.rb +79 -0
  36. data/spec/dummy_app/config/environments/test.rb +47 -0
  37. data/spec/dummy_app/config/initializers/assets.rb +11 -0
  38. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy_app/config/initializers/cookies_serializer.rb +3 -0
  40. data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/spec/dummy_app/config/initializers/inflections.rb +16 -0
  42. data/spec/dummy_app/config/initializers/mime_types.rb +4 -0
  43. data/spec/dummy_app/config/initializers/session_store.rb +3 -0
  44. data/spec/dummy_app/config/initializers/to_time_preserves_timezone.rb +10 -0
  45. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy_app/config/locales/en.yml +23 -0
  47. data/spec/dummy_app/config/routes.rb +4 -0
  48. data/spec/dummy_app/config/secrets.yml +22 -0
  49. data/spec/dummy_app/db/schema.rb +27 -0
  50. data/spec/dummy_app/log/development.log +205 -0
  51. data/spec/dummy_app/log/test.log +2019 -0
  52. data/spec/dummy_app/public/404.html +67 -0
  53. data/spec/dummy_app/public/422.html +67 -0
  54. data/spec/dummy_app/public/500.html +66 -0
  55. data/spec/dummy_app/public/favicon.ico +0 -0
  56. data/spec/models/dup_send_blocker/send_log_spec.rb +69 -0
  57. data/spec/models/dup_send_blocker_spec.rb +114 -0
  58. data/spec/rails_helper.rb +69 -0
  59. data/spec/spec_helper.rb +109 -0
  60. metadata +229 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,69 @@
1
+ require 'rails_helper'
2
+
3
+ describe DupSendBlocker::SendLog do
4
+ describe "write_labels!" do
5
+ let(:labels3) { [:info_1, "2020-10-07", 123] }
6
+ let(:labels2) { [:info_2, 123] }
7
+
8
+ context "ラベルを指定して保存したとき" do
9
+ subject {
10
+ DupSendBlocker::SendLog.write_labels!(labels3)
11
+ }
12
+ it "保存に成功する" do
13
+ send_log = subject
14
+ expect(send_log.id.present?).to eq true
15
+ end
16
+ end
17
+
18
+ context "保存済のラベルを指定して保存したとき" do
19
+ subject {
20
+ DupSendBlocker::SendLog.write_labels!(labels3)
21
+ DupSendBlocker::SendLog.write_labels!(labels3)
22
+ }
23
+ it "例外発生" do
24
+ expect { subject }.to raise_error(DupSendBlocker::SendLog::DupLabelError)
25
+ end
26
+ end
27
+
28
+ context "保存済のラベルと異なるラベルを指定して保存したとき" do
29
+ let(:labels3_2) { [:info_1, "2020-10-07", 124] }
30
+ subject {
31
+ DupSendBlocker::SendLog.write_labels!(labels3)
32
+ DupSendBlocker::SendLog.write_labels!(labels3_2)
33
+ }
34
+ it "保存に成功する" do
35
+ subject
36
+ expect(DupSendBlocker::SendLog.where({
37
+ label01: labels3[0],
38
+ label02: labels3[1],
39
+ label03: labels3[2],
40
+ }).exists?).to eq true
41
+ expect(DupSendBlocker::SendLog.where({
42
+ label01: labels3_2[0],
43
+ label02: labels3_2[1],
44
+ label03: labels3_2[2],
45
+ }).exists?).to eq true
46
+ end
47
+ end
48
+
49
+ context "空文字を含むラベルを渡したとき" do
50
+ subject {
51
+ DupSendBlocker::SendLog.write_labels!(labels2)
52
+ }
53
+ it "保存に成功する" do
54
+ send_log = subject
55
+ expect(send_log.id.present?).to eq true
56
+ end
57
+ end
58
+
59
+ context "保存済の空文字を含むラベルを渡したとき" do
60
+ subject {
61
+ DupSendBlocker::SendLog.write_labels!(labels2)
62
+ DupSendBlocker::SendLog.write_labels!(labels2)
63
+ }
64
+ it "例外発生" do
65
+ expect { subject }.to raise_error(DupSendBlocker::SendLog::DupLabelError)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,114 @@
1
+ require 'rails_helper'
2
+
3
+ describe DupSendBlocker do
4
+ describe "perform!" do
5
+ let(:labels3) { [:info_1, "2020-10-07", 123] }
6
+ let(:sender) {
7
+ _sender = double("MockSender")
8
+ allow(_sender).to receive(:send).and_return(true)
9
+ allow(_sender).to receive(:send_error).and_raise(StandardError)
10
+ _sender
11
+ }
12
+
13
+ context 'ブロックを渡さずに実行した場合' do
14
+ subject { DupSendBlocker.perform!(labels3) }
15
+ it '例外発生' do
16
+ expect { subject }.to raise_error(ArgumentError)
17
+ end
18
+ end
19
+
20
+ context 'ラベル/ブロックを指定して実行したとき' do
21
+ subject {
22
+ result = nil
23
+ DupSendBlocker.perform!(labels3) do
24
+ result = sender.send
25
+ end
26
+ result
27
+ }
28
+ it '実行できる' do
29
+ expect(subject).to eq true
30
+ end
31
+ end
32
+
33
+ context '実行済と異なるラベルを指定して再実行したとき' do
34
+ subject {
35
+ DupSendBlocker.perform!([:info_1, "2020-10-07", 122]) do
36
+ sender.send
37
+ end
38
+
39
+ result = nil
40
+ DupSendBlocker.perform!(labels3) do
41
+ result = sender.send
42
+ end
43
+ result
44
+ }
45
+ it '実行できる' do
46
+ expect(subject).to eq true
47
+ end
48
+ end
49
+
50
+ context '実行済のラベルを指定して再実行したとき' do
51
+ subject {
52
+ DupSendBlocker.perform!(labels3) { sender.send }
53
+ DupSendBlocker.perform!(labels3) { sender.send }
54
+ }
55
+ it '例外発生' do
56
+ expect { subject }.to raise_error(DupSendBlocker::BlockError)
57
+ end
58
+ end
59
+
60
+ context 'send_error_is :invalidの場合' do
61
+ context '送信処理でエラーしたとき' do
62
+ subject {
63
+ DupSendBlocker.perform!(labels3) { sender.send_error }
64
+ }
65
+ it '例外発生' do
66
+ expect { subject }.to raise_error(StandardError)
67
+ end
68
+
69
+ context '再実行したとき' do
70
+ subject {
71
+ DupSendBlocker.perform!(labels3) { sender.send_error } rescue nil
72
+
73
+ result = nil
74
+ DupSendBlocker.perform!(labels3) do
75
+ result = sender.send
76
+ end
77
+ result
78
+ }
79
+ it '実行できる' do
80
+ expect(subject).to eq true
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ context 'send_error_is :validの場合' do
87
+ context '送信処理でエラーしたとき' do
88
+ subject {
89
+ DupSendBlocker.perform!(labels3, send_error_is: :valid) do
90
+ sender.send_error
91
+ end
92
+ }
93
+ it '例外発生' do
94
+ expect { subject }.to raise_error(StandardError)
95
+ end
96
+
97
+ context '再実行したとき' do
98
+ subject {
99
+ DupSendBlocker.perform!(labels3, send_error_is: :valid) {
100
+ sender.send_error
101
+ } rescue nil
102
+
103
+ DupSendBlocker.perform!(labels3, send_error_is: :valid) do
104
+ sender.send
105
+ end
106
+ }
107
+ it '例外発生' do
108
+ expect { subject }.to raise_error(DupSendBlocker::BlockError)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,69 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+
5
+ # require File.expand_path('../config/environment', __dir__)
6
+ require File.expand_path("../dummy_app/config/environment.rb", __FILE__)
7
+
8
+ # Prevent database truncation if the environment is production
9
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
10
+ require 'rspec/rails'
11
+ require 'pry-rails'
12
+ # Add additional requires below this line. Rails is not loaded until this point!
13
+
14
+ # Requires supporting ruby files with custom matchers and macros, etc, in
15
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
16
+ # run as spec files by default. This means that files in spec/support that end
17
+ # in _spec.rb will both be required and run as specs, causing the specs to be
18
+ # run twice. It is recommended that you do not name files matching this glob to
19
+ # end with _spec.rb. You can configure this pattern with the --pattern
20
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
21
+ #
22
+ # The following line is provided for convenience purposes. It has the downside
23
+ # of increasing the boot-up time by auto-requiring all files in the support
24
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
25
+ # require only the support files necessary.
26
+ #
27
+ # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
28
+
29
+ # Checks for pending migrations and applies them before tests are run.
30
+ # If you are not using ActiveRecord, you can remove these lines.
31
+ begin
32
+ # DEPRECATION WARNING: ActiveRecord::Base.raise_in_transactional_callbacks= is deprecated, has no effect and will be removed without replacement.
33
+ # ActiveRecord::Migration.maintain_test_schema!
34
+ rescue ActiveRecord::PendingMigrationError => e
35
+ puts e.to_s.strip
36
+ exit 1
37
+ end
38
+ RSpec.configure do |config|
39
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
40
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
41
+
42
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
43
+ # examples within a transaction, remove the following line or assign false
44
+ # instead of true.
45
+ config.use_transactional_fixtures = true
46
+
47
+ # You can uncomment this line to turn off ActiveRecord support entirely.
48
+ # config.use_active_record = false
49
+
50
+ # RSpec Rails can automatically mix in different behaviours to your tests
51
+ # based on their file location, for example enabling you to call `get` and
52
+ # `post` in specs under `spec/controllers`.
53
+ #
54
+ # You can disable this behaviour by removing the line below, and instead
55
+ # explicitly tag your specs with their type, e.g.:
56
+ #
57
+ # RSpec.describe UsersController, type: :controller do
58
+ # # ...
59
+ # end
60
+ #
61
+ # The different available types are documented in the features, such as in
62
+ # https://relishapp.com/rspec/rspec-rails/docs
63
+ config.infer_spec_type_from_file_location!
64
+
65
+ # Filter lines from Rails gems in backtraces.
66
+ config.filter_rails_from_backtrace!
67
+ # arbitrary gems may also be filtered via:
68
+ # config.filter_gems_from_backtrace("gem name")
69
+ end