commons_yellowme 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +12 -0
  5. data/Gemfile.lock +234 -0
  6. data/bin/test +5 -0
  7. data/commons.gemspec +43 -0
  8. data/lib/commons/version.rb +1 -1
  9. data/spec/commons/authentication/authenticate_by_jwt_spec.rb +37 -0
  10. data/spec/commons/authentication/json_web_token_spec.rb +41 -0
  11. data/spec/commons/concerns/attributes/sex_spec.rb +24 -0
  12. data/spec/commons/concerns/extensions/deleted_spec.rb +42 -0
  13. data/spec/commons/concerns/guard/capitalizable_spec.rb +13 -0
  14. data/spec/commons/concerns/validations/undestroyable_spec.rb +9 -0
  15. data/spec/commons/errors/bad_request_spec.rb +62 -0
  16. data/spec/commons/errors/conflict_spec.rb +62 -0
  17. data/spec/commons/errors/forbidden_spec.rb +62 -0
  18. data/spec/commons/errors/internal_server_error_spec.rb +62 -0
  19. data/spec/commons/errors/invalid_resource_spec.rb +62 -0
  20. data/spec/commons/errors/maintenance_mode_spec.rb +49 -0
  21. data/spec/commons/errors/missing_parameter_spec.rb +49 -0
  22. data/spec/commons/errors/not_unique_spec.rb +62 -0
  23. data/spec/commons/errors/payment_required_spec.rb +62 -0
  24. data/spec/commons/errors/precondition_failed_spec.rb +62 -0
  25. data/spec/commons/errors/resource_not_found_spec.rb +49 -0
  26. data/spec/commons/errors/route_not_found_spec.rb +49 -0
  27. data/spec/commons/errors/unauthorized_spec.rb +62 -0
  28. data/spec/commons/errors/unprocessable_entity_spec.rb +62 -0
  29. data/spec/commons/formatter/e164_phone_spec.rb +155 -0
  30. data/spec/commons/formatter/regex_constants_spec.rb +102 -0
  31. data/spec/commons/formatter/string_utils_spec.rb +19 -0
  32. data/spec/commons/repositories/base_repository_spec.rb +504 -0
  33. data/spec/commons/repositories/catalogs/base_catalog_spec.rb +55 -0
  34. data/spec/commons/serializers/bad_request_spec.rb +46 -0
  35. data/spec/commons/serializers/conflict_spec.rb +46 -0
  36. data/spec/commons/serializers/forbidden_spec.rb +46 -0
  37. data/spec/commons/serializers/internal_server_error_spec.rb +46 -0
  38. data/spec/commons/serializers/invalid_resource_spec.rb +46 -0
  39. data/spec/commons/serializers/maintenance_mode_spec.rb +46 -0
  40. data/spec/commons/serializers/missing_parameter_spec.rb +44 -0
  41. data/spec/commons/serializers/not_unique_spec.rb +46 -0
  42. data/spec/commons/serializers/payment_required_spec.rb +46 -0
  43. data/spec/commons/serializers/precondition_failed_spec.rb +46 -0
  44. data/spec/commons/serializers/route_not_found_spec.rb +46 -0
  45. data/spec/commons/serializers/unauthorized_spec.rb +46 -0
  46. data/spec/commons/serializers/unprocessable_entity_spec.rb +46 -0
  47. data/spec/commons/shared-examples/user_spec.rb +18 -0
  48. data/spec/dummy/.ruby-version +1 -0
  49. data/spec/dummy/Rakefile +6 -0
  50. data/spec/dummy/app/assets/config/manifest.js +2 -0
  51. data/spec/dummy/app/assets/images/.keep +0 -0
  52. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  53. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  54. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  55. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  56. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  57. data/spec/dummy/app/controllers/miscellaneous_controller.rb +13 -0
  58. data/spec/dummy/app/errors/default_handling.rb +35 -0
  59. data/spec/dummy/app/errors/error_notifier.rb +12 -0
  60. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  61. data/spec/dummy/app/javascript/packs/application.js +15 -0
  62. data/spec/dummy/app/jobs/application_job.rb +7 -0
  63. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  64. data/spec/dummy/app/models/application_record.rb +3 -0
  65. data/spec/dummy/app/models/catalogs/application_parameter.rb +6 -0
  66. data/spec/dummy/app/models/concerns/.keep +0 -0
  67. data/spec/dummy/app/models/employee.rb +3 -0
  68. data/spec/dummy/app/models/user.rb +16 -0
  69. data/spec/dummy/app/repositories/catalogs/application_parameter_repository.rb +4 -0
  70. data/spec/dummy/app/repositories/employee_repository.rb +2 -0
  71. data/spec/dummy/app/repositories/user_repository.rb +2 -0
  72. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  73. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  74. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  75. data/spec/dummy/bin/rails +4 -0
  76. data/spec/dummy/bin/rake +4 -0
  77. data/spec/dummy/bin/setup +33 -0
  78. data/spec/dummy/config.ru +5 -0
  79. data/spec/dummy/config/application.rb +29 -0
  80. data/spec/dummy/config/boot.rb +5 -0
  81. data/spec/dummy/config/cable.yml +10 -0
  82. data/spec/dummy/config/database.yml +25 -0
  83. data/spec/dummy/config/environment.rb +5 -0
  84. data/spec/dummy/config/environments/development.rb +62 -0
  85. data/spec/dummy/config/environments/production.rb +112 -0
  86. data/spec/dummy/config/environments/test.rb +48 -0
  87. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  88. data/spec/dummy/config/initializers/assets.rb +12 -0
  89. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  90. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  91. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  92. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  93. data/spec/dummy/config/initializers/inflections.rb +16 -0
  94. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/spec/dummy/config/locales/en.yml +33 -0
  97. data/spec/dummy/config/puma.rb +38 -0
  98. data/spec/dummy/config/routes.rb +9 -0
  99. data/spec/dummy/config/spring.rb +6 -0
  100. data/spec/dummy/config/storage.yml +34 -0
  101. data/spec/dummy/db/migrate/20191212233443_create_user.rb +13 -0
  102. data/spec/dummy/db/migrate/20191213072543_create_application_parameters.rb +8 -0
  103. data/spec/dummy/db/migrate/20200101204534_create_employee.rb +8 -0
  104. data/spec/dummy/db/schema.rb +35 -0
  105. data/spec/dummy/lib/assets/.keep +0 -0
  106. data/spec/dummy/log/.keep +0 -0
  107. data/spec/dummy/public/404.html +67 -0
  108. data/spec/dummy/public/422.html +67 -0
  109. data/spec/dummy/public/500.html +66 -0
  110. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  111. data/spec/dummy/public/apple-touch-icon.png +0 -0
  112. data/spec/dummy/public/favicon.ico +0 -0
  113. data/spec/factories/catalogs/application_parameters.rb +6 -0
  114. data/spec/factories/employees.rb +6 -0
  115. data/spec/factories/users.rb +7 -0
  116. data/spec/rails_helper.rb +68 -0
  117. data/spec/spec_helper.rb +104 -0
  118. data/spec/support/.DS_Store +0 -0
  119. data/spec/support/shared-examples/capitalizable.rb +16 -0
  120. data/spec/support/shared-examples/deletable.rb +39 -0
  121. data/spec/support/shared-examples/dimorphic.rb +28 -0
  122. data/spec/support/shared-examples/stripable.rb +17 -0
  123. data/spec/support/shared-examples/undestroyable.rb +8 -0
  124. metadata +240 -3
@@ -0,0 +1,46 @@
1
+ RSpec.describe Commons::Errors::PreconditionFailed, type: :serializer do
2
+ let(:title) { Faker::Name.name }
3
+ let(:message) { Faker::Name.name }
4
+ let(:detail) { Faker::Name.name }
5
+ let(:meta) { { data: Faker::Name.name } }
6
+ let(:error) { described_class.new }
7
+ subject do
8
+ serializer = Commons::Errors::ErrorSerializer.new(error)
9
+ serializer.serializable_hash
10
+ end
11
+
12
+ describe 'serialize the model' do
13
+ context 'should validate required attributes' do
14
+ it do
15
+ serialized = subject
16
+ expect(serialized.keys).to include :status
17
+ expect(serialized.keys).to include :code
18
+ expect(serialized.keys).to include :title
19
+ expect(serialized.keys).to include :detail
20
+ end
21
+ end
22
+
23
+ context 'should work with default values' do
24
+ it do
25
+ serialized = subject
26
+ expect(serialized[:status]).to eq error.status
27
+ expect(serialized[:code]).to eq error.code
28
+ expect(serialized[:title]).to eq error.title
29
+ expect(serialized[:detail]).to eq error.detail
30
+ expect(serialized[:meta]).to eq error.meta
31
+ end
32
+ end
33
+
34
+ context 'should work with custom values' do
35
+ let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
36
+ it do
37
+ serialized = subject
38
+ expect(serialized[:status]).to eq error.status
39
+ expect(serialized[:title]).to eq title
40
+ expect(serialized[:detail]).to eq detail
41
+ expect(serialized[:meta][:message]).to eq message
42
+ expect(serialized[:meta][:data]).to eq meta[:data]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ RSpec.describe Commons::Errors::RouteNotFound, type: :serializer do
2
+ let(:title) { Faker::Name.name }
3
+ let(:message) { Faker::Name.name }
4
+ let(:detail) { Faker::Name.name }
5
+ let(:meta) { { data: Faker::Name.name } }
6
+ let(:error) { described_class.new }
7
+ subject do
8
+ serializer = Commons::Errors::ErrorSerializer.new(error)
9
+ serializer.serializable_hash
10
+ end
11
+
12
+ describe 'serialize the model' do
13
+ context 'should validate required attributes' do
14
+ it do
15
+ serialized = subject
16
+ expect(serialized.keys).to include :status
17
+ expect(serialized.keys).to include :code
18
+ expect(serialized.keys).to include :title
19
+ expect(serialized.keys).to include :detail
20
+ end
21
+ end
22
+
23
+ context 'should work with default values' do
24
+ it do
25
+ serialized = subject
26
+ expect(serialized[:status]).to eq error.status
27
+ expect(serialized[:code]).to eq error.code
28
+ expect(serialized[:title]).to eq error.title
29
+ expect(serialized[:detail]).to eq error.detail
30
+ expect(serialized[:meta]).to eq error.meta
31
+ end
32
+ end
33
+
34
+ context 'should work with custom values' do
35
+ let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
36
+ it do
37
+ serialized = subject
38
+ expect(serialized[:status]).to eq error.status
39
+ expect(serialized[:title]).to eq title
40
+ expect(serialized[:detail]).to eq detail
41
+ expect(serialized[:meta][:message]).to eq message
42
+ expect(serialized[:meta][:data]).to eq meta[:data]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ RSpec.describe Commons::Errors::Unauthorized, type: :serializer do
2
+ let(:title) { Faker::Name.name }
3
+ let(:message) { Faker::Name.name }
4
+ let(:detail) { Faker::Name.name }
5
+ let(:meta) { { data: Faker::Name.name } }
6
+ let(:error) { described_class.new }
7
+ subject do
8
+ serializer = Commons::Errors::ErrorSerializer.new(error)
9
+ serializer.serializable_hash
10
+ end
11
+
12
+ describe 'serialize the model' do
13
+ context 'should validate required attributes' do
14
+ it do
15
+ serialized = subject
16
+ expect(serialized.keys).to include :status
17
+ expect(serialized.keys).to include :code
18
+ expect(serialized.keys).to include :title
19
+ expect(serialized.keys).to include :detail
20
+ end
21
+ end
22
+
23
+ context 'should work with default values' do
24
+ it do
25
+ serialized = subject
26
+ expect(serialized[:status]).to eq error.status
27
+ expect(serialized[:code]).to eq error.code
28
+ expect(serialized[:title]).to eq error.title
29
+ expect(serialized[:detail]).to eq error.detail
30
+ expect(serialized[:meta]).to eq error.meta
31
+ end
32
+ end
33
+
34
+ context 'should work with custom values' do
35
+ let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
36
+ it do
37
+ serialized = subject
38
+ expect(serialized[:status]).to eq error.status
39
+ expect(serialized[:title]).to eq title
40
+ expect(serialized[:detail]).to eq detail
41
+ expect(serialized[:meta][:message]).to eq message
42
+ expect(serialized[:meta][:data]).to eq meta[:data]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ RSpec.describe Commons::Errors::UnprocessableEntity, type: :serializer do
2
+ let(:title) { Faker::Name.name }
3
+ let(:message) { Faker::Name.name }
4
+ let(:detail) { Faker::Name.name }
5
+ let(:meta) { { data: Faker::Name.name } }
6
+ let(:error) { described_class.new }
7
+ subject do
8
+ serializer = Commons::Errors::ErrorSerializer.new(error)
9
+ serializer.serializable_hash
10
+ end
11
+
12
+ describe 'serialize the model' do
13
+ context 'should validate required attributes' do
14
+ it do
15
+ serialized = subject
16
+ expect(serialized.keys).to include :status
17
+ expect(serialized.keys).to include :code
18
+ expect(serialized.keys).to include :title
19
+ expect(serialized.keys).to include :detail
20
+ end
21
+ end
22
+
23
+ context 'should work with default values' do
24
+ it do
25
+ serialized = subject
26
+ expect(serialized[:status]).to eq error.status
27
+ expect(serialized[:code]).to eq error.code
28
+ expect(serialized[:title]).to eq error.title
29
+ expect(serialized[:detail]).to eq error.detail
30
+ expect(serialized[:meta]).to eq error.meta
31
+ end
32
+ end
33
+
34
+ context 'should work with custom values' do
35
+ let(:error) { described_class.new(message, title: title, detail: detail, meta: meta) }
36
+ it do
37
+ serialized = subject
38
+ expect(serialized[:status]).to eq error.status
39
+ expect(serialized[:title]).to eq title
40
+ expect(serialized[:detail]).to eq detail
41
+ expect(serialized[:meta][:message]).to eq message
42
+ expect(serialized[:meta][:data]).to eq meta[:data]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ require 'support/shared-examples/dimorphic'
2
+ require 'support/shared-examples/deletable'
3
+ require 'support/shared-examples/undestroyable'
4
+ require 'support/shared-examples/capitalizable'
5
+ require 'support/shared-examples/stripable'
6
+
7
+ RSpec.describe User, type: :model do
8
+ let(:user) { create(:user) }
9
+ subject { user }
10
+
11
+ context 'shared-example' do
12
+ it_behaves_like "undestroyable"
13
+ it_behaves_like "deletable"
14
+ it_behaves_like "dimorphic"
15
+ it_behaves_like "capitalizable", ['name']
16
+ it_behaves_like "stripable", ['name', 'last_name']
17
+ end
18
+ end
@@ -0,0 +1 @@
1
+ ruby-2.5.1
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative 'config/application'
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,2 @@
1
+ //= link_tree ../images
2
+ //= link_directory ../stylesheets .css
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Channel < ActionCable::Channel::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module ApplicationCable
2
+ class Connection < ActionCable::Connection::Base
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,13 @@
1
+ class MiscellaneousController < ApplicationController
2
+ include Commons::Authentication::AuthenticateByJWT
3
+ # always include your handlers first in order to preserve last priority
4
+ # https://stackoverflow.com/a/9121054/3287738
5
+ include DefaultHandling
6
+ include Commons::Errors::DefaultHandling
7
+
8
+ before_action :authorize_jwt!
9
+
10
+ def application_parameters
11
+ render json: [{}]
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ # :nocov:
2
+ module DefaultHandling
3
+ def self.included(cls)
4
+ cls.class_eval do
5
+ include ErrorNotifier
6
+
7
+ # must go first in order to preserve last priority
8
+ # https://stackoverflow.com/a/9121054/3287738
9
+ rescue_from StandardError do |e|
10
+ report_error(e)
11
+ respond Commons::Errors::InternalServerError.new
12
+ end
13
+
14
+ rescue_from Commons::Errors::ErrorBase do |e|
15
+ if e.instance_of?(Commons::Errors::InternalServerError) ||
16
+ e.is_a?(Commons::Errors::InternalServerError) ||
17
+ Rails.env.development?
18
+ report_error(e)
19
+ end
20
+ respond e
21
+ end
22
+ end
23
+ end
24
+
25
+ def respond(error)
26
+ render json: [error],
27
+ status: error.status,
28
+ each_serializer: Commons::Errors::ErrorSerializer
29
+ end
30
+
31
+ def report_error(param)
32
+ print_trace(param)
33
+ end
34
+ end
35
+ # :nocov:
@@ -0,0 +1,12 @@
1
+ module ErrorNotifier
2
+ private
3
+
4
+ # :nocov:
5
+ def print_trace(e)
6
+ return if Rails.env.test? || e.nil?
7
+
8
+ puts e.message unless e.message.nil?
9
+ puts e.backtrace unless e.backtrace.nil?
10
+ end
11
+ # :nocov:
12
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,7 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ # Automatically retry jobs that encountered a deadlock
3
+ # retry_on ActiveRecord::Deadlocked
4
+
5
+ # Most jobs are safe to ignore if the underlying records are no longer available
6
+ # discard_on ActiveJob::DeserializationError
7
+ end
@@ -0,0 +1,4 @@
1
+ class ApplicationMailer < ActionMailer::Base
2
+ default from: 'from@example.com'
3
+ layout 'mailer'
4
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationRecord < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ end
@@ -0,0 +1,6 @@
1
+ module Catalogs
2
+ class ApplicationParameter < ApplicationRecord
3
+ validates :name, :value, presence: true
4
+ validates :name, uniqueness: true
5
+ end
6
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ class Employee < ApplicationRecord
2
+ include Commons::Concerns::Extensions::Deleted
3
+ end
@@ -0,0 +1,16 @@
1
+ class User < ApplicationRecord
2
+ include Commons::Concerns::Attributes::Sex
3
+ include Commons::Concerns::Extensions::Deleted
4
+ include Commons::Concerns::Guard::Capitalizable
5
+ include Commons::Concerns::Validations::Undestroyable
6
+
7
+ capitalize only: [:name]
8
+
9
+ strip_attributes only: [:name, :last_name],
10
+ allow_empty: true,
11
+ collapse_spaces: true
12
+
13
+ validates :name,
14
+ :last_name,
15
+ presence: true
16
+ end
@@ -0,0 +1,4 @@
1
+ module Catalogs
2
+ class ApplicationParameterRepository < Commons::Repositories::Catalogs::BaseCatalog
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ class EmployeeRepository < Commons::Repositories::BaseRepository
2
+ end
@@ -0,0 +1,2 @@
1
+ class UserRepository < Commons::Repositories::BaseRepository
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all' %>
9
+ </head>
10
+
11
+ <body>
12
+ <%= yield %>
13
+ </body>
14
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>