human_attributes 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +104 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.rubocop.yml +65 -594
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +216 -144
- data/Guardfile +4 -4
- data/README.md +37 -17
- data/Rakefile +1 -1
- data/human_attributes.gemspec +11 -7
- data/lib/human_attributes/extension.rb +5 -3
- data/lib/human_attributes/formatters/base.rb +1 -0
- data/lib/human_attributes/formatters/enumerize.rb +1 -0
- data/lib/human_attributes/formatters_builder.rb +1 -0
- data/lib/human_attributes/version.rb +1 -1
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +3 -3
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +3 -1
- data/spec/dummy/app/jobs/application_job.rb +7 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/purchase.rb +1 -1
- data/spec/dummy/app/views/layouts/application.html.erb +10 -9
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/rails +3 -3
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +18 -14
- data/spec/dummy/config.ru +3 -1
- data/spec/dummy/config/application.rb +12 -22
- data/spec/dummy/config/boot.rb +3 -3
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +4 -18
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +49 -14
- data/spec/dummy/config/environments/production.rb +63 -22
- data/spec/dummy/config/environments/test.rb +29 -12
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +4 -3
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -2
- data/spec/dummy/config/locales/en.yml +11 -1
- data/spec/dummy/config/puma.rb +43 -0
- data/spec/dummy/config/routes.rb +1 -54
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/db/migrate/20161113032308_create_purchases.rb +1 -1
- data/spec/dummy/db/schema.rb +14 -15
- data/spec/dummy/public/404.html +6 -6
- data/spec/dummy/public/422.html +6 -6
- data/spec/dummy/public/500.html +6 -6
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/spec/factories/purchases.rb +6 -22
- data/spec/dummy/spec/lib/active_record_extension_spec.rb +34 -32
- metadata +97 -36
- data/spec/dummy/README.rdoc +0 -28
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
@@ -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
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,56 +1,3 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
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/db/schema.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
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
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# from scratch.
|
10
|
-
#
|
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:
|
13
|
+
ActiveRecord::Schema.define(version: 2016_11_13_032308) do
|
15
14
|
|
16
15
|
create_table "purchases", force: :cascade do |t|
|
17
|
-
t.boolean
|
18
|
-
t.decimal
|
19
|
-
t.integer
|
20
|
-
t.string
|
16
|
+
t.boolean "paid"
|
17
|
+
t.decimal "commission"
|
18
|
+
t.integer "quantity"
|
19
|
+
t.string "state"
|
21
20
|
t.datetime "expired_at"
|
22
|
-
t.decimal
|
23
|
-
t.text
|
24
|
-
t.datetime "created_at",
|
25
|
-
t.datetime "updated_at",
|
21
|
+
t.decimal "amount"
|
22
|
+
t.text "description"
|
23
|
+
t.datetime "created_at", null: false
|
24
|
+
t.datetime "updated_at", null: false
|
26
25
|
end
|
27
26
|
|
28
27
|
end
|
data/spec/dummy/public/404.html
CHANGED
@@ -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
|
-
|
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>
|
data/spec/dummy/public/422.html
CHANGED
@@ -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
|
-
|
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>
|
data/spec/dummy/public/500.html
CHANGED
@@ -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
|
-
|
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
|
File without changes
|
@@ -1,26 +1,10 @@
|
|
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" }
|
25
9
|
end
|
26
10
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require "rails_helper"
|
2
2
|
require "enumerize"
|
3
3
|
|
4
|
+
# rubocop:disable Lint/ConstantDefinitionInBlock
|
4
5
|
RSpec.describe "ActiveRecordExtension" do
|
5
6
|
after do
|
6
|
-
class Purchase <
|
7
|
+
class Purchase < ApplicationRecord
|
7
8
|
humanizers.each do |method|
|
8
9
|
remove_method method
|
9
10
|
end
|
@@ -15,7 +16,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
15
16
|
|
16
17
|
it "raises error passing invalid options" do
|
17
18
|
expect do
|
18
|
-
class Purchase <
|
19
|
+
class Purchase < ApplicationRecord
|
19
20
|
humanize :amount, "invalid"
|
20
21
|
end
|
21
22
|
end.to raise_error(HumanAttributes::Error::InvalidHumanizeConfig)
|
@@ -23,7 +24,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
23
24
|
|
24
25
|
it "raises error passing multiple types" do
|
25
26
|
expect do
|
26
|
-
class Purchase <
|
27
|
+
class Purchase < ApplicationRecord
|
27
28
|
humanize :amount, invalid: true
|
28
29
|
end
|
29
30
|
end.to raise_error(HumanAttributes::Error::InvalidType)
|
@@ -31,7 +32,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
31
32
|
|
32
33
|
it "raises error passing no type" do
|
33
34
|
expect do
|
34
|
-
class Purchase <
|
35
|
+
class Purchase < ApplicationRecord
|
35
36
|
humanize :amount, {}
|
36
37
|
end
|
37
38
|
end.to raise_error(HumanAttributes::Error::RequiredAttributeType)
|
@@ -39,7 +40,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
39
40
|
|
40
41
|
it "raises error trying to pass invalid options" do
|
41
42
|
expect do
|
42
|
-
class Purchase <
|
43
|
+
class Purchase < ApplicationRecord
|
43
44
|
humanize :amount, currency: "invalid"
|
44
45
|
end
|
45
46
|
end.to raise_error(HumanAttributes::Error::InvalidAttributeOptions)
|
@@ -47,7 +48,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
47
48
|
|
48
49
|
context "with default value" do
|
49
50
|
before do
|
50
|
-
class Purchase <
|
51
|
+
class Purchase < ApplicationRecord
|
51
52
|
humanize :amount, currency: { default: 666 }
|
52
53
|
end
|
53
54
|
|
@@ -59,7 +60,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
59
60
|
|
60
61
|
context "with default value" do
|
61
62
|
before do
|
62
|
-
class Purchase <
|
63
|
+
class Purchase < ApplicationRecord
|
63
64
|
humanize :amount, percentage: { suffix: true }, currency: { suffix: true }
|
64
65
|
end
|
65
66
|
|
@@ -75,7 +76,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
75
76
|
|
76
77
|
context "with default suffix" do
|
77
78
|
before do
|
78
|
-
class Purchase <
|
79
|
+
class Purchase < ApplicationRecord
|
79
80
|
humanize :amount, currency: { suffix: true }
|
80
81
|
end
|
81
82
|
end
|
@@ -85,7 +86,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
85
86
|
|
86
87
|
context "with custom suffix" do
|
87
88
|
before do
|
88
|
-
class Purchase <
|
89
|
+
class Purchase < ApplicationRecord
|
89
90
|
humanize :amount, currency: { suffix: "to_cur" }
|
90
91
|
end
|
91
92
|
end
|
@@ -102,7 +103,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
102
103
|
|
103
104
|
context "with no options" do
|
104
105
|
before do
|
105
|
-
class Purchase <
|
106
|
+
class Purchase < ApplicationRecord
|
106
107
|
humanize :amount, currency: true
|
107
108
|
end
|
108
109
|
end
|
@@ -112,7 +113,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
112
113
|
|
113
114
|
context "with valid options" do
|
114
115
|
before do
|
115
|
-
class Purchase <
|
116
|
+
class Purchase < ApplicationRecord
|
116
117
|
humanize :amount, currency: { unit: "R$", separator: ",", delimiter: " " }
|
117
118
|
end
|
118
119
|
end
|
@@ -122,7 +123,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
122
123
|
|
123
124
|
context "with multiple attributes" do
|
124
125
|
before do
|
125
|
-
class Purchase <
|
126
|
+
class Purchase < ApplicationRecord
|
126
127
|
humanize :amount, :commission, currency: true
|
127
128
|
end
|
128
129
|
end
|
@@ -133,7 +134,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
133
134
|
|
134
135
|
context "with calculated attributes (instance methods)" do
|
135
136
|
before do
|
136
|
-
class Purchase <
|
137
|
+
class Purchase < ApplicationRecord
|
137
138
|
humanize :commission_amount, currency: true
|
138
139
|
|
139
140
|
def commission_amount
|
@@ -151,7 +152,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
151
152
|
|
152
153
|
context "with number type" do
|
153
154
|
before do
|
154
|
-
class Purchase <
|
155
|
+
class Purchase < ApplicationRecord
|
155
156
|
humanize :quantity, number: true
|
156
157
|
end
|
157
158
|
end
|
@@ -161,7 +162,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
161
162
|
|
162
163
|
context "with size type" do
|
163
164
|
before do
|
164
|
-
class Purchase <
|
165
|
+
class Purchase < ApplicationRecord
|
165
166
|
humanize :quantity, size: true
|
166
167
|
end
|
167
168
|
end
|
@@ -171,7 +172,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
171
172
|
|
172
173
|
context "with percentage type" do
|
173
174
|
before do
|
174
|
-
class Purchase <
|
175
|
+
class Purchase < ApplicationRecord
|
175
176
|
humanize :quantity, percentage: true
|
176
177
|
end
|
177
178
|
end
|
@@ -183,7 +184,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
183
184
|
|
184
185
|
context "with phone type" do
|
185
186
|
before do
|
186
|
-
class Purchase <
|
187
|
+
class Purchase < ApplicationRecord
|
187
188
|
humanize :quantity, phone: true
|
188
189
|
end
|
189
190
|
end
|
@@ -193,7 +194,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
193
194
|
|
194
195
|
context "with delimiter type" do
|
195
196
|
before do
|
196
|
-
class Purchase <
|
197
|
+
class Purchase < ApplicationRecord
|
197
198
|
humanize :quantity, delimiter: true
|
198
199
|
end
|
199
200
|
end
|
@@ -203,7 +204,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
203
204
|
|
204
205
|
context "with precision type" do
|
205
206
|
before do
|
206
|
-
class Purchase <
|
207
|
+
class Purchase < ApplicationRecord
|
207
208
|
humanize :quantity, precision: true
|
208
209
|
end
|
209
210
|
end
|
@@ -217,7 +218,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
217
218
|
|
218
219
|
context "passing true value" do
|
219
220
|
before do
|
220
|
-
class Purchase <
|
221
|
+
class Purchase < ApplicationRecord
|
221
222
|
humanize :paid, boolean: true
|
222
223
|
end
|
223
224
|
end
|
@@ -229,7 +230,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
229
230
|
before do
|
230
231
|
purchase.paid = false
|
231
232
|
|
232
|
-
class Purchase <
|
233
|
+
class Purchase < ApplicationRecord
|
233
234
|
humanize :paid, boolean: true
|
234
235
|
end
|
235
236
|
end
|
@@ -241,7 +242,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
241
242
|
context "with custom formatter" do
|
242
243
|
it "raises error with missing formatter option" do
|
243
244
|
expect do
|
244
|
-
class Purchase <
|
245
|
+
class Purchase < ApplicationRecord
|
245
246
|
humanize :id, custom: true
|
246
247
|
end
|
247
248
|
end.to raise_error(HumanAttributes::Error::MissingFormatterOption)
|
@@ -252,7 +253,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
252
253
|
purchase.id = 1
|
253
254
|
purchase.paid = true
|
254
255
|
|
255
|
-
class Purchase <
|
256
|
+
class Purchase < ApplicationRecord
|
256
257
|
humanize :id, custom: { formatter: ->(purchase, value) { "#{value}:#{purchase.paid}" } }
|
257
258
|
end
|
258
259
|
end
|
@@ -264,7 +265,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
264
265
|
context "with Enumerize attribute" do
|
265
266
|
context "passing valid value" do
|
266
267
|
before do
|
267
|
-
class Purchase <
|
268
|
+
class Purchase < ApplicationRecord
|
268
269
|
extend Enumerize
|
269
270
|
enumerize :state, in: %i{canceled finished}
|
270
271
|
humanize :state, enumerize: true
|
@@ -278,7 +279,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
278
279
|
|
279
280
|
context "passing no enum value" do
|
280
281
|
before do
|
281
|
-
class Purchase <
|
282
|
+
class Purchase < ApplicationRecord
|
282
283
|
extend Enumerize
|
283
284
|
humanize :quantity, enumerize: true
|
284
285
|
end
|
@@ -298,7 +299,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
298
299
|
|
299
300
|
context "passing custom format" do
|
300
301
|
before do
|
301
|
-
class Purchase <
|
302
|
+
class Purchase < ApplicationRecord
|
302
303
|
humanize :expired_at, date: { format: "%Y" }
|
303
304
|
humanize :created_at, datetime: { format: "%Y" }
|
304
305
|
end
|
@@ -310,7 +311,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
310
311
|
|
311
312
|
context "without options" do
|
312
313
|
before do
|
313
|
-
class Purchase <
|
314
|
+
class Purchase < ApplicationRecord
|
314
315
|
humanize :expired_at, date: true
|
315
316
|
humanize :created_at, datetime: true
|
316
317
|
end
|
@@ -322,7 +323,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
322
323
|
|
323
324
|
context "with short format" do
|
324
325
|
before do
|
325
|
-
class Purchase <
|
326
|
+
class Purchase < ApplicationRecord
|
326
327
|
humanize :expired_at, date: { format: :short }
|
327
328
|
humanize :created_at, datetime: { format: :short }
|
328
329
|
end
|
@@ -334,7 +335,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
334
335
|
|
335
336
|
context "with long format" do
|
336
337
|
before do
|
337
|
-
class Purchase <
|
338
|
+
class Purchase < ApplicationRecord
|
338
339
|
humanize :expired_at, date: { format: :long }
|
339
340
|
humanize :created_at, datetime: { format: :long }
|
340
341
|
end
|
@@ -351,7 +352,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
351
352
|
|
352
353
|
context "without options" do
|
353
354
|
before do
|
354
|
-
class Purchase <
|
355
|
+
class Purchase < ApplicationRecord
|
355
356
|
humanize_attributes
|
356
357
|
end
|
357
358
|
end
|
@@ -371,7 +372,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
371
372
|
|
372
373
|
context "with only option" do
|
373
374
|
before do
|
374
|
-
class Purchase <
|
375
|
+
class Purchase < ApplicationRecord
|
375
376
|
humanize_attributes only: [:id, :paid, :amount]
|
376
377
|
end
|
377
378
|
end
|
@@ -391,7 +392,7 @@ RSpec.describe "ActiveRecordExtension" do
|
|
391
392
|
|
392
393
|
context "with except option" do
|
393
394
|
before do
|
394
|
-
class Purchase <
|
395
|
+
class Purchase < ApplicationRecord
|
395
396
|
humanize_attributes except: [:id, :paid, :amount]
|
396
397
|
end
|
397
398
|
end
|
@@ -410,3 +411,4 @@ RSpec.describe "ActiveRecordExtension" do
|
|
410
411
|
end
|
411
412
|
end
|
412
413
|
end
|
414
|
+
# rubocop:enable Lint/ConstantDefinitionInBlock
|