human_attributes 0.6.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +104 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.rubocop.yml +65 -594
  5. data/.ruby-version +1 -1
  6. data/CHANGELOG.md +11 -0
  7. data/Gemfile.lock +219 -147
  8. data/Guardfile +4 -4
  9. data/README.md +127 -26
  10. data/Rakefile +1 -1
  11. data/human_attributes.gemspec +11 -7
  12. data/lib/human_attributes/config.rb +50 -68
  13. data/lib/human_attributes/engine.rb +1 -0
  14. data/lib/human_attributes/errors.rb +6 -0
  15. data/lib/human_attributes/extension.rb +21 -26
  16. data/lib/human_attributes/formatters/base.rb +1 -0
  17. data/lib/human_attributes/formatters/enum.rb +25 -0
  18. data/lib/human_attributes/formatters/enumerize.rb +1 -0
  19. data/lib/human_attributes/formatters_builder.rb +1 -0
  20. data/lib/human_attributes/version.rb +1 -1
  21. data/spec/dummy/Rakefile +1 -1
  22. data/spec/dummy/app/assets/config/manifest.js +3 -0
  23. data/spec/dummy/app/assets/stylesheets/application.css +3 -3
  24. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  25. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  27. data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +3 -1
  28. data/spec/dummy/app/jobs/application_job.rb +7 -0
  29. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  30. data/spec/dummy/app/models/application_record.rb +3 -0
  31. data/spec/dummy/app/models/purchase.rb +20 -11
  32. data/spec/dummy/app/views/layouts/application.html.erb +10 -9
  33. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  34. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  35. data/spec/dummy/bin/rails +3 -3
  36. data/spec/dummy/bin/rake +2 -2
  37. data/spec/dummy/bin/setup +18 -14
  38. data/spec/dummy/config/application.rb +12 -22
  39. data/spec/dummy/config/boot.rb +3 -3
  40. data/spec/dummy/config/cable.yml +10 -0
  41. data/spec/dummy/config/database.yml +4 -18
  42. data/spec/dummy/config/environment.rb +1 -1
  43. data/spec/dummy/config/environments/development.rb +49 -14
  44. data/spec/dummy/config/environments/production.rb +63 -22
  45. data/spec/dummy/config/environments/test.rb +29 -12
  46. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  47. data/spec/dummy/config/initializers/assets.rb +4 -3
  48. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
  49. data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
  50. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  51. data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
  52. data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
  53. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
  54. data/spec/dummy/config/locales/en.yml +26 -1
  55. data/spec/dummy/config/puma.rb +43 -0
  56. data/spec/dummy/config/routes.rb +1 -54
  57. data/spec/dummy/config/storage.yml +34 -0
  58. data/spec/dummy/config.ru +3 -1
  59. data/spec/dummy/db/migrate/20161113032308_create_purchases.rb +1 -1
  60. data/spec/dummy/db/migrate/20211006145358_add_payment_method_to_purchase.rb +5 -0
  61. data/spec/dummy/db/migrate/20211103114451_add_shipping_to_purchase.rb +5 -0
  62. data/spec/dummy/db/migrate/20211103114830_add_store_to_purchase.rb +5 -0
  63. data/spec/dummy/db/schema.rb +17 -17
  64. data/spec/dummy/public/404.html +6 -6
  65. data/spec/dummy/public/422.html +6 -6
  66. data/spec/dummy/public/500.html +6 -6
  67. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  68. data/spec/dummy/public/apple-touch-icon.png +0 -0
  69. data/spec/dummy/spec/factories/purchases.rb +9 -22
  70. data/spec/dummy/spec/lib/active_record_extension_spec.rb +81 -33
  71. metadata +104 -38
  72. data/.hound.yml +0 -4
  73. data/.travis.yml +0 -15
  74. data/spec/dummy/README.rdoc +0 -28
  75. data/spec/dummy/bin/bundle +0 -3
  76. data/spec/dummy/config/initializers/session_store.rb +0 -3
  77. data/spec/dummy/config/secrets.yml +0 -22
@@ -0,0 +1,11 @@
1
+ # Define an application-wide HTTP permissions policy. For further
2
+ # information see https://developers.google.com/web/updates/2018/06/feature-policy
3
+ #
4
+ # Rails.application.config.permissions_policy do |f|
5
+ # f.camera :none
6
+ # f.gyroscope :none
7
+ # f.microphone :none
8
+ # f.usb :none
9
+ # f.fullscreen :self
10
+ # f.payment :self, "https://secure.example.com"
11
+ # end
@@ -5,10 +5,10 @@
5
5
 
6
6
  # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
7
  ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
8
+ wrap_parameters format: [:json]
9
9
  end
10
10
 
11
11
  # To enable root element in JSON for ActiveRecord objects.
12
12
  # ActiveSupport.on_load(:active_record) do
13
- # self.include_root_in_json = true
13
+ # self.include_root_in_json = true
14
14
  # end
@@ -16,10 +16,35 @@
16
16
  #
17
17
  # This would use the information in config/locales/es.yml.
18
18
  #
19
+ # The following keys must be escaped otherwise they will not be retrieved by
20
+ # the default I18n backend:
21
+ #
22
+ # true, false, on, off, yes, no
23
+ #
24
+ # Instead, surround them with single quotes.
25
+ #
26
+ # en:
27
+ # 'true': 'foo'
28
+ #
19
29
  # To learn more, please read the Rails Internationalization guide
20
- # available at http://guides.rubyonrails.org/i18n.html.
30
+ # available at https://guides.rubyonrails.org/i18n.html.
21
31
 
22
32
  en:
23
33
  boolean:
24
34
  positive: "Yes"
25
35
  negative: "No"
36
+ enum:
37
+ defaults:
38
+ shippings:
39
+ standard: "Standard"
40
+ express: "Express"
41
+ activerecord:
42
+ attributes:
43
+ purchase:
44
+ payment_methods:
45
+ credit: "Credit Card"
46
+ debit: "Debit Card"
47
+ cash: "Cash"
48
+ bitcoin: "Bitcoin"
49
+
50
+
@@ -0,0 +1,43 @@
1
+ # Puma can serve each request in a thread from an internal thread pool.
2
+ # The `threads` method setting takes two numbers: a minimum and maximum.
3
+ # Any libraries that use thread pools should be configured to match
4
+ # the maximum value specified for Puma. Default is set to 5 threads for minimum
5
+ # and maximum; this matches the default thread size of Active Record.
6
+ #
7
+ max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
8
+ min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
9
+ threads min_threads_count, max_threads_count
10
+
11
+ # Specifies the `worker_timeout` threshold that Puma will use to wait before
12
+ # terminating a worker in development environments.
13
+ #
14
+ worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15
+
16
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17
+ #
18
+ port ENV.fetch("PORT") { 3000 }
19
+
20
+ # Specifies the `environment` that Puma will run in.
21
+ #
22
+ environment ENV.fetch("RAILS_ENV") { "development" }
23
+
24
+ # Specifies the `pidfile` that Puma will use.
25
+ pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26
+
27
+ # Specifies the number of `workers` to boot in clustered mode.
28
+ # Workers are forked web server processes. If using threads and workers together
29
+ # the concurrency of the application would be max `threads` * `workers`.
30
+ # Workers do not work on JRuby or Windows (both of which do not support
31
+ # processes).
32
+ #
33
+ # workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34
+
35
+ # Use the `preload_app!` method when specifying a `workers` number.
36
+ # This directive tells Puma to first boot the application and load code
37
+ # before forking the application. This takes advantage of Copy On Write
38
+ # process behavior so workers use less memory.
39
+ #
40
+ # preload_app!
41
+
42
+ # Allow puma to be restarted by `rails restart` command.
43
+ plugin :tmp_restart
@@ -1,56 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- # The priority is based upon order of creation: first created -> highest priority.
3
- # See how all your routes lay out with "rake routes".
4
-
5
- # You can have the root of your site routed with "root"
6
- # root 'welcome#index'
7
-
8
- # Example of regular route:
9
- # get 'products/:id' => 'catalog#view'
10
-
11
- # Example of named route that can be invoked with purchase_url(id: product.id)
12
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
-
14
- # Example resource route (maps HTTP verbs to controller actions automatically):
15
- # resources :products
16
-
17
- # Example resource route with options:
18
- # resources :products do
19
- # member do
20
- # get 'short'
21
- # post 'toggle'
22
- # end
23
- #
24
- # collection do
25
- # get 'sold'
26
- # end
27
- # end
28
-
29
- # Example resource route with sub-resources:
30
- # resources :products do
31
- # resources :comments, :sales
32
- # resource :seller
33
- # end
34
-
35
- # Example resource route with more complex sub-resources:
36
- # resources :products do
37
- # resources :comments
38
- # resources :sales do
39
- # get 'recent', on: :collection
40
- # end
41
- # end
42
-
43
- # Example resource route with concerns:
44
- # concern :toggleable do
45
- # post 'toggle'
46
- # end
47
- # resources :posts, concerns: :toggleable
48
- # resources :photos, concerns: :toggleable
49
-
50
- # Example resource route within a namespace:
51
- # namespace :admin do
52
- # # Directs /admin/products/* to Admin::ProductsController
53
- # # (app/controllers/admin/products_controller.rb)
54
- # resources :products
55
- # end
2
+ mount HumanAttributes::Engine => "/human_attributes"
56
3
  end
@@ -0,0 +1,34 @@
1
+ test:
2
+ service: Disk
3
+ root: <%= Rails.root.join("tmp/storage") %>
4
+
5
+ local:
6
+ service: Disk
7
+ root: <%= Rails.root.join("storage") %>
8
+
9
+ # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
10
+ # amazon:
11
+ # service: S3
12
+ # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
13
+ # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
14
+ # region: us-east-1
15
+ # bucket: your_own_bucket
16
+
17
+ # Remember not to checkin your GCS keyfile to a repository
18
+ # google:
19
+ # service: GCS
20
+ # project: your_project
21
+ # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
22
+ # bucket: your_own_bucket
23
+
24
+ # Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
25
+ # microsoft:
26
+ # service: AzureStorage
27
+ # storage_account_name: your_account_name
28
+ # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
29
+ # container: your_container_name
30
+
31
+ # mirror:
32
+ # service: Mirror
33
+ # primary: local
34
+ # mirrors: [ amazon, google, microsoft ]
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,6 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require_relative "config/environment"
4
+
4
5
  run Rails.application
6
+ Rails.application.load_server
@@ -1,4 +1,4 @@
1
- class CreatePurchases < ActiveRecord::Migration
1
+ class CreatePurchases < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :purchases do |t|
4
4
  t.boolean :paid
@@ -0,0 +1,5 @@
1
+ class AddPaymentMethodToPurchase < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :purchases, :payment_method, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddShippingToPurchase < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :purchases, :shipping, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddStoreToPurchase < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_column :purchases, :store, :integer
4
+ end
5
+ end
@@ -1,28 +1,28 @@
1
- # encoding: UTF-8
2
1
  # This file is auto-generated from the current state of the database. Instead
3
2
  # of editing this file, please use the migrations feature of Active Record to
4
3
  # incrementally modify your database, and then regenerate this schema definition.
5
4
  #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
11
10
  #
12
11
  # It's strongly recommended that you check this file into your version control system.
13
12
 
14
- ActiveRecord::Schema.define(version: 20161113032308) do
15
-
13
+ ActiveRecord::Schema.define(version: 2021_11_03_114830) do
16
14
  create_table "purchases", force: :cascade do |t|
17
- t.boolean "paid"
18
- t.decimal "commission"
19
- t.integer "quantity"
20
- t.string "state"
15
+ t.boolean "paid"
16
+ t.decimal "commission"
17
+ t.integer "quantity"
18
+ t.string "state"
21
19
  t.datetime "expired_at"
22
- t.decimal "amount"
23
- t.text "description"
24
- t.datetime "created_at", null: false
25
- t.datetime "updated_at", null: false
20
+ t.decimal "amount"
21
+ t.text "description"
22
+ t.datetime "created_at", null: false
23
+ t.datetime "updated_at", null: false
24
+ t.integer "payment_method"
25
+ t.integer "shipping"
26
+ t.integer "store"
26
27
  end
27
-
28
28
  end
@@ -4,7 +4,7 @@
4
4
  <title>The page you were looking for doesn't exist (404)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/404.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -4,7 +4,7 @@
4
4
  <title>The change you wanted was rejected (422)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/422.html -->
59
59
  <div class="dialog">
60
60
  <div>
@@ -4,7 +4,7 @@
4
4
  <title>We're sorry, but something went wrong (500)</title>
5
5
  <meta name="viewport" content="width=device-width,initial-scale=1">
6
6
  <style>
7
- body {
7
+ .rails-default-error-page {
8
8
  background-color: #EFEFEF;
9
9
  color: #2E2F30;
10
10
  text-align: center;
@@ -12,13 +12,13 @@
12
12
  margin: 0;
13
13
  }
14
14
 
15
- div.dialog {
15
+ .rails-default-error-page div.dialog {
16
16
  width: 95%;
17
17
  max-width: 33em;
18
18
  margin: 4em auto 0;
19
19
  }
20
20
 
21
- div.dialog > div {
21
+ .rails-default-error-page div.dialog > div {
22
22
  border: 1px solid #CCC;
23
23
  border-right-color: #999;
24
24
  border-left-color: #999;
@@ -31,13 +31,13 @@
31
31
  box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
32
  }
33
33
 
34
- h1 {
34
+ .rails-default-error-page h1 {
35
35
  font-size: 100%;
36
36
  color: #730E15;
37
37
  line-height: 1.5em;
38
38
  }
39
39
 
40
- div.dialog > p {
40
+ .rails-default-error-page div.dialog > p {
41
41
  margin: 0 0 1em;
42
42
  padding: 1em;
43
43
  background-color: #F7F7F7;
@@ -54,7 +54,7 @@
54
54
  </style>
55
55
  </head>
56
56
 
57
- <body>
57
+ <body class="rails-default-error-page">
58
58
  <!-- This file lives in public/500.html -->
59
59
  <div class="dialog">
60
60
  <div>
File without changes
@@ -1,26 +1,13 @@
1
- # == Schema Information
2
- #
3
- # Table name: purchases
4
- #
5
- # id :integer not null, primary key
6
- # paid :boolean
7
- # commission :decimal(, )
8
- # quantity :integer
9
- # state :string
10
- # expired_at :datetime
11
- # amount :decimal(, )
12
- # description :text
13
- # created_at :datetime not null
14
- # updated_at :datetime not null
15
- #
16
-
17
1
  FactoryBot.define do
18
2
  factory :purchase do
19
- paid true
20
- commission 1000.99
21
- quantity 1
22
- expired_at "1984-04-06 09:00"
23
- amount 2_000_000.95
24
- description "Just a text"
3
+ paid { true }
4
+ commission { 1000.99 }
5
+ quantity { 1 }
6
+ expired_at { "1984-04-06 09:00" }
7
+ amount { 2_000_000.95 }
8
+ description { "Just a text" }
9
+ payment_method { 'debit' }
10
+ shipping { 'express' }
11
+ store { 'online' }
25
12
  end
26
13
  end