validation_hints 8.1.75 → 8.1.76
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/validation_hints/version.rb +1 -1
- data/validation_hints.gemspec +4 -10
- metadata +1 -14
- data/.document +0 -5
- data/.forgejo/workflows/ci.yml +0 -51
- data/.gitignore +0 -20
- data/.rubocop.yml +0 -12
- data/.ruby-version +0 -1
- data/Gemfile +0 -5
- data/Rakefile +0 -52
- data/stuff/rails-8-checklist.md +0 -19
- data/test/active_model/hints_test.rb +0 -149
- data/test/active_model/i18n_test.rb +0 -105
- data/test/gem_build_test.rb +0 -74
- data/test/test_helper.rb +0 -59
- data/test/validation_hints_test.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 27b23658927a5ceb68d197dab15334519233d02344eadaf6d89342f86ddfee5c
|
|
4
|
+
data.tar.gz: bbd43f6ece8cb99ca2025e62e2b55caf5308630bb582036c2433b1e2d10b5bd2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 583f30188fa6a5e3ed57e6a42167a47531b582d75b671d925c81e3fe464fe701298c0156c5f86882b65a92630f525e285195f4e7894f25c1e96985cd24ccddcb
|
|
7
|
+
data.tar.gz: 9b54def53ac09ccadaa215b390ddd17110abc01b0421c23970888792e330f8d7bd0eb291b8898edda5c404b69525e96c58e8113d2d42c3b5850cc2cb096d252b
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project are documented here.
|
|
4
4
|
|
|
5
|
+
## 8.1.76
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- The gem packages only `lib` and the documents. Tests, `.forgejo/`, `stuff/`, RuboCop and Ruby version files, `Gemfile` and `Rakefile` are left out.
|
|
10
|
+
- Version bump to stay in lockstep with `inline_forms` / `inline_forms_installer` / `inline_forms_schema_edit` 8.1.76.
|
|
11
|
+
|
|
5
12
|
## 8.1.75
|
|
6
13
|
|
|
7
14
|
### Changed
|
data/validation_hints.gemspec
CHANGED
|
@@ -16,16 +16,10 @@ Gem::Specification.new do |s|
|
|
|
16
16
|
s.license = "MIT"
|
|
17
17
|
s.required_ruby_version = ">= 4.0.0"
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
s.files = Dir.chdir(__dir__) do
|
|
24
|
-
Dir.glob("{lib,test}/**/*", File::FNM_DOTMATCH).reject do |f|
|
|
25
|
-
f.end_with?(".gem") || f.start_with?("stuff/")
|
|
26
|
-
end + %w[README.md LICENSE.txt CHANGELOG.md Gemfile Rakefile validation_hints.gemspec]
|
|
27
|
-
end
|
|
28
|
-
s.test_files = Dir.glob("{test,spec}/**/*", base: __dir__)
|
|
19
|
+
# What an installed gem needs; not the tests, CI and RuboCop files or stuff/.
|
|
20
|
+
s.files = Dir.chdir(__dir__) do
|
|
21
|
+
Dir.glob("lib/**/*").select { |f| File.file?(f) } +
|
|
22
|
+
%w[README.md LICENSE.txt CHANGELOG.md validation_hints.gemspec]
|
|
29
23
|
end
|
|
30
24
|
|
|
31
25
|
s.require_paths = [ "lib" ]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: validation_hints
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 8.1.
|
|
4
|
+
version: 8.1.76
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ace Suares
|
|
@@ -147,16 +147,9 @@ executables: []
|
|
|
147
147
|
extensions: []
|
|
148
148
|
extra_rdoc_files: []
|
|
149
149
|
files:
|
|
150
|
-
- ".document"
|
|
151
|
-
- ".forgejo/workflows/ci.yml"
|
|
152
|
-
- ".gitignore"
|
|
153
|
-
- ".rubocop.yml"
|
|
154
|
-
- ".ruby-version"
|
|
155
150
|
- CHANGELOG.md
|
|
156
|
-
- Gemfile
|
|
157
151
|
- LICENSE.txt
|
|
158
152
|
- README.md
|
|
159
|
-
- Rakefile
|
|
160
153
|
- lib/active_model/hints.rb
|
|
161
154
|
- lib/validation_hints.rb
|
|
162
155
|
- lib/validation_hints/gem_build.rb
|
|
@@ -165,12 +158,6 @@ files:
|
|
|
165
158
|
- lib/validation_hints/railtie.rb
|
|
166
159
|
- lib/validation_hints/validations_patch.rb
|
|
167
160
|
- lib/validation_hints/version.rb
|
|
168
|
-
- stuff/rails-8-checklist.md
|
|
169
|
-
- test/active_model/hints_test.rb
|
|
170
|
-
- test/active_model/i18n_test.rb
|
|
171
|
-
- test/gem_build_test.rb
|
|
172
|
-
- test/test_helper.rb
|
|
173
|
-
- test/validation_hints_test.rb
|
|
174
161
|
- validation_hints.gemspec
|
|
175
162
|
homepage: https://github.com/acesuares/validation_hints
|
|
176
163
|
licenses:
|
data/.document
DELETED
data/.forgejo/workflows/ci.yml
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# CI for Forgejo Actions (runner on dev02; same pattern as inline_forms).
|
|
2
|
-
#
|
|
3
|
-
# No Node: the job runs in the official ruby image and uses only shell steps.
|
|
4
|
-
# actions/checkout and actions/cache are JavaScript and need node inside the
|
|
5
|
-
# container, so the checkout is plain git and the gems are installed fresh each
|
|
6
|
-
# run.
|
|
7
|
-
#
|
|
8
|
-
# No GitHub workflows exist — pushing to GitHub triggers nothing.
|
|
9
|
-
name: CI
|
|
10
|
-
|
|
11
|
-
# Push triggers on EVERY branch (inline_forms stuff/prompt/workflow.md:
|
|
12
|
-
# "every commit runs through CI") — feature branches were silently skipping
|
|
13
|
-
# CI when this was `branches: [master]`.
|
|
14
|
-
on:
|
|
15
|
-
push:
|
|
16
|
-
pull_request:
|
|
17
|
-
|
|
18
|
-
jobs:
|
|
19
|
-
test:
|
|
20
|
-
runs-on: docker
|
|
21
|
-
container:
|
|
22
|
-
image: docker.io/library/ruby:4.0.10
|
|
23
|
-
steps:
|
|
24
|
-
- name: Check out
|
|
25
|
-
env:
|
|
26
|
-
TOKEN: ${{ github.token }}
|
|
27
|
-
SERVER: ${{ github.server_url }}
|
|
28
|
-
REPO: ${{ github.repository }}
|
|
29
|
-
SHA: ${{ github.sha }}
|
|
30
|
-
run: |
|
|
31
|
-
auth=$(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)
|
|
32
|
-
git init -q .
|
|
33
|
-
git -c http.extraHeader="Authorization: basic $auth" fetch -q --depth 1 "$SERVER/$REPO.git" "$SHA"
|
|
34
|
-
git checkout -q FETCH_HEAD
|
|
35
|
-
git log --oneline -1
|
|
36
|
-
|
|
37
|
-
- name: Install gems
|
|
38
|
-
run: |
|
|
39
|
-
bundle config set --local path vendor/bundle
|
|
40
|
-
bundle install --jobs 4
|
|
41
|
-
|
|
42
|
-
- name: Tests
|
|
43
|
-
run: bundle exec rake test
|
|
44
|
-
|
|
45
|
-
- name: RuboCop
|
|
46
|
-
run: bundle exec rubocop
|
|
47
|
-
|
|
48
|
-
- name: bundler-audit
|
|
49
|
-
run: |
|
|
50
|
-
gem install bundler-audit --no-document
|
|
51
|
-
bundle-audit check --update
|
data/.gitignore
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
*.rbc
|
|
2
|
-
*.sassc
|
|
3
|
-
.sass-cache
|
|
4
|
-
capybara-*.html
|
|
5
|
-
.rspec
|
|
6
|
-
/.bundle
|
|
7
|
-
/vendor/bundle
|
|
8
|
-
Gemfile.lock
|
|
9
|
-
/log/*
|
|
10
|
-
/tmp/*
|
|
11
|
-
/db/*.sqlite3
|
|
12
|
-
/public/system/*
|
|
13
|
-
/coverage/
|
|
14
|
-
/spec/tmp/*
|
|
15
|
-
**.orig
|
|
16
|
-
rerun.txt
|
|
17
|
-
pickle-email-*.html
|
|
18
|
-
/pkg
|
|
19
|
-
*.gem
|
|
20
|
-
.rvmrc
|
data/.rubocop.yml
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
# RuboCop with the Rails "omakase" preset (same recipe as Papiamentu and
|
|
2
|
-
# inline_forms). The codebase is fully clean — no .rubocop_todo.yml baseline.
|
|
3
|
-
# Run with: bundle exec rubocop
|
|
4
|
-
inherit_gem:
|
|
5
|
-
rubocop-rails-omakase: rubocop.yml
|
|
6
|
-
|
|
7
|
-
AllCops:
|
|
8
|
-
TargetRubyVersion: 3.3
|
|
9
|
-
Exclude:
|
|
10
|
-
- "pkg/**/*"
|
|
11
|
-
- "vendor/**/*"
|
|
12
|
-
- "stuff/**/*"
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ruby-4.0.10
|
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/gem_helper"
|
|
4
|
-
require "rake/testtask"
|
|
5
|
-
require_relative "lib/validation_hints/version"
|
|
6
|
-
|
|
7
|
-
# Do not require "bundler/setup" at load time: `rake release` only builds and
|
|
8
|
-
# pushes the .gem (no tests, no sqlite3). Tests load the bundle explicitly.
|
|
9
|
-
Bundler::GemHelper.install_tasks
|
|
10
|
-
|
|
11
|
-
# Release git-push ALWAYS targets `origin` (GitHub) only.
|
|
12
|
-
#
|
|
13
|
-
# Bundler's stock `release` pushes the commit + tag to the CURRENT BRANCH's
|
|
14
|
-
# tracking remote (`git config branch.<branch>.remote`). If this repo is ever
|
|
15
|
-
# released from a branch that tracks `forgejo` (dev02, CI-only), the release
|
|
16
|
-
# would land there instead of GitHub. `origin` is the only place release
|
|
17
|
-
# commits/tags belong. Override `release` so its git-push step can never follow
|
|
18
|
-
# a non-origin tracking remote. Idempotent on the tag so a re-run after a failed
|
|
19
|
-
# push still lands the tag on origin.
|
|
20
|
-
Rake::Task["release"].clear if Rake::Task.task_defined?("release")
|
|
21
|
-
|
|
22
|
-
desc "Tag the release and push the commit + tag to origin (GitHub) only"
|
|
23
|
-
task "release:push_to_origin" do
|
|
24
|
-
version = ValidationHints::VERSION
|
|
25
|
-
tag = "v#{version}"
|
|
26
|
-
branch = `git rev-parse --abbrev-ref HEAD`.strip
|
|
27
|
-
unless system("git", "rev-parse", "-q", "--verify", "refs/tags/#{tag}",
|
|
28
|
-
out: File::NULL, err: File::NULL)
|
|
29
|
-
sh "git", "tag", tag
|
|
30
|
-
end
|
|
31
|
-
sh "git", "push", "origin", "refs/heads/#{branch}"
|
|
32
|
-
sh "git", "push", "origin", "refs/tags/#{tag}"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
desc "Build, tag, push to origin (GitHub) and push the gem to RubyGems"
|
|
36
|
-
task "release" => [ "build", "release:guard_clean",
|
|
37
|
-
"release:push_to_origin", "release:rubygem_push" ]
|
|
38
|
-
|
|
39
|
-
Rake::TestTask.new(:test) do |t|
|
|
40
|
-
t.libs << "test"
|
|
41
|
-
t.libs << "lib"
|
|
42
|
-
t.pattern = "test/**/*_test.rb"
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
task "test:bundle" do
|
|
46
|
-
sh "bundle check > /dev/null 2>&1 || bundle install"
|
|
47
|
-
require "bundler/setup"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
Rake::Task[:test].enhance([ "test:bundle" ])
|
|
51
|
-
|
|
52
|
-
task default: :test
|
data/stuff/rails-8-checklist.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Rails 8 migration — checklist (archived)
|
|
2
|
-
|
|
3
|
-
**Status:** Migration **complete** on the **8.0.x** line (2026-05-22).
|
|
4
|
-
|
|
5
|
-
**Canonical runbook (maintainers):** `inline_forms/stuff/rails8forReal.md` (local copy; gitignored in inline_forms).
|
|
6
|
-
|
|
7
|
-
**Release summary (published docs):** [`inline_forms/docs/rails-8-release.md`](../../inline_forms/docs/rails-8-release.md)
|
|
8
|
-
|
|
9
|
-
**Zeitwerk / load paths:** [`inline_forms/docs/zeitwerk-and-load-paths.md`](../../inline_forms/docs/zeitwerk-and-load-paths.md)
|
|
10
|
-
|
|
11
|
-
| Gem | Released |
|
|
12
|
-
|-----|----------|
|
|
13
|
-
| **validation_hints** | **8.0.3** — AR `>= 8.0`, `< 8.1` |
|
|
14
|
-
| **inline_forms** | **8.0.3** — Rails `>= 8.0`, `< 8.1` |
|
|
15
|
-
| **inline_forms_installer** | **8.0.3** — lockstep |
|
|
16
|
-
|
|
17
|
-
**Example app gate:** `inline_forms create MyApp -d sqlite --example` → **88 runs, 502 assertions, 0 failures** (Rails 8.0.5).
|
|
18
|
-
|
|
19
|
-
For historical phase checklists, see git history of this file or `rails8forReal.md`.
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
|
|
5
|
-
class ActiveModelHintsTest < Minitest::Test
|
|
6
|
-
def setup
|
|
7
|
-
@person = Person.new
|
|
8
|
-
@profile = Profile.new
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def test_presence_hint
|
|
12
|
-
assert_includes @person.hints[:name], "can't be blank"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def test_full_messages_for_includes_human_attribute_name
|
|
16
|
-
messages = @person.hints.full_messages_for(:name)
|
|
17
|
-
assert_equal [ "Name can't be blank" ], messages
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_has_validations_for
|
|
21
|
-
assert @person.has_validations_for?(:name)
|
|
22
|
-
refute @person.has_validations_for?(:missing)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_has_validations_on_class_and_instance
|
|
26
|
-
assert Person.has_validations?
|
|
27
|
-
assert @person.has_validations?
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_length_within_hint
|
|
31
|
-
hints = @person.hints[:password]
|
|
32
|
-
assert_includes hints, "must be between 1 and 4 characters"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def test_numericality_option_hints
|
|
36
|
-
hints = @person.hints[:age]
|
|
37
|
-
assert_includes hints, "must be a number"
|
|
38
|
-
assert_includes hints, "must be an integer"
|
|
39
|
-
assert_includes hints, "must be greater than 19"
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def test_bare_numericality_emits_must_be_a_number
|
|
43
|
-
model = Class.new(ActiveRecord::Base) do
|
|
44
|
-
self.table_name = "people"
|
|
45
|
-
validates :age, numericality: true
|
|
46
|
-
def self.name
|
|
47
|
-
"BareNumericalityModel"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
assert_equal [ "must be a number" ], model.new.hints[:age]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def test_numericality_range_options_keep_their_messages
|
|
55
|
-
model = Class.new(ActiveRecord::Base) do
|
|
56
|
-
self.table_name = "people"
|
|
57
|
-
validates :age, numericality: { greater_than_or_equal_to: -90, less_than_or_equal_to: 90 }
|
|
58
|
-
def self.name
|
|
59
|
-
"RangeNumericalityModel"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
hints = model.new.hints[:age]
|
|
64
|
-
assert_equal "must be a number", hints.first,
|
|
65
|
-
"expected the base must-be-a-number hint to come first"
|
|
66
|
-
assert_includes hints, "must be greater than or equal to -90"
|
|
67
|
-
assert_includes hints, "must be less than or equal to 90"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def test_inclusion_hint_uses_list
|
|
71
|
-
hints = @person.hints[:status]
|
|
72
|
-
assert_equal 1, hints.size
|
|
73
|
-
assert_match(/must be one of/, hints.first)
|
|
74
|
-
assert_match(/active/, hints.first)
|
|
75
|
-
assert_match(/inactive/, hints.first)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def test_virtual_attribute_with_validators_is_included
|
|
79
|
-
assert_includes @profile.hints.keys, :nickname
|
|
80
|
-
assert_includes @profile.hints[:nickname], "can't be blank"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def test_empty_returns_true_when_no_hint_messages
|
|
84
|
-
person = Class.new do
|
|
85
|
-
include ActiveModel::Model
|
|
86
|
-
include ActiveModel::Validations
|
|
87
|
-
|
|
88
|
-
def self.name
|
|
89
|
-
"EmptyModel"
|
|
90
|
-
end
|
|
91
|
-
end.new
|
|
92
|
-
|
|
93
|
-
assert person.hints.empty?
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def test_add_and_added_with_symbol_message
|
|
97
|
-
person = Person.new
|
|
98
|
-
person.hints.add(:name, :blank)
|
|
99
|
-
assert person.hints.added?(:name, :blank)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def test_validator_keys_for_rails_7_validators
|
|
103
|
-
validators = Person.validators_on(:name).map { |v| v.class.name.demodulize }
|
|
104
|
-
assert_includes validators, "PresenceValidator"
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def test_confirmation_hint
|
|
108
|
-
hints = @person.hints[:password]
|
|
109
|
-
assert_includes hints, "doesn't match confirmation"
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_custom_message_as_symbol
|
|
113
|
-
I18n.backend.store_translations(:en, activerecord: {
|
|
114
|
-
hints: {
|
|
115
|
-
models: {
|
|
116
|
-
person: {
|
|
117
|
-
attributes: {
|
|
118
|
-
email: {
|
|
119
|
-
"presence" => { "required" => "is required" }
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
hints = @person.hints[:email]
|
|
128
|
-
assert_includes hints, "is required"
|
|
129
|
-
messages = @person.hints.full_messages_for(:email)
|
|
130
|
-
assert_includes messages, "Email is required"
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def test_format_validator_hint
|
|
134
|
-
hints = @person.hints[:code]
|
|
135
|
-
assert_includes hints, "must match the required format"
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def test_custom_each_validator_hint
|
|
139
|
-
person = CustomValidatorPerson.new
|
|
140
|
-
hints = person.hints[:email]
|
|
141
|
-
assert_includes hints, "must look like an email address"
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def test_validates_with_class_validator_does_not_crash
|
|
145
|
-
person = CustomValidatorPerson.new
|
|
146
|
-
person.hints[:name]
|
|
147
|
-
assert_empty person.hints[:code], "validates_with class validators are not introspectable for hints"
|
|
148
|
-
end
|
|
149
|
-
end
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
|
|
5
|
-
# `message: :required` is what every belongs_to declares (Rails adds
|
|
6
|
-
# validates_presence_of <assoc>, message: :required).
|
|
7
|
-
class RequiredCodePerson < ActiveRecord::Base
|
|
8
|
-
self.table_name = "people"
|
|
9
|
-
|
|
10
|
-
validates :code, presence: { message: :required }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class ActiveModelHintsI18nTest < Minitest::Test
|
|
14
|
-
def setup
|
|
15
|
-
@person = Person.new
|
|
16
|
-
@backend = I18n.backend
|
|
17
|
-
@kv = I18n::Backend::KeyValue.new({})
|
|
18
|
-
I18n.backend = I18n::Backend::Chain.new(@kv, @backend)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def teardown
|
|
22
|
-
I18n.backend = @backend
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_activerecord_hints_messages_override
|
|
26
|
-
@kv.store_translations(:en, activerecord: { hints: { messages: { presence: "is required" } } })
|
|
27
|
-
|
|
28
|
-
assert_includes @person.hints[:name], "is required"
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def test_activerecord_hints_model_attribute_override
|
|
32
|
-
@kv.store_translations(
|
|
33
|
-
:en,
|
|
34
|
-
activerecord: {
|
|
35
|
-
hints: {
|
|
36
|
-
models: {
|
|
37
|
-
person: {
|
|
38
|
-
attributes: {
|
|
39
|
-
name: { presence: "needs a name" }
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
|
|
47
|
-
assert_equal [ "needs a name" ], @person.hints[:name]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def test_hints_attributes_override
|
|
51
|
-
@kv.store_translations(:en, hints: { attributes: { name: { presence: "name hint" } } })
|
|
52
|
-
|
|
53
|
-
assert_equal [ "name hint" ], @person.hints[:name]
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def test_top_level_hints_messages_override
|
|
57
|
-
@kv.store_translations(:en, hints: { messages: { presence: "fill this in" } })
|
|
58
|
-
|
|
59
|
-
assert_includes @person.hints[:name], "fill this in"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# The en file had only a plain `presence` string, so "presence.required"
|
|
63
|
-
# (every belongs_to hint) rendered "Translation missing" even in en.
|
|
64
|
-
def test_required_message_resolves_in_en
|
|
65
|
-
assert_equal [ "must be chosen" ], RequiredCodePerson.new.hints[:code]
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_required_message_prefers_a_presence_required_key
|
|
69
|
-
@kv.store_translations(:en, hints: { messages: { presence: { required: "pick one" } } })
|
|
70
|
-
|
|
71
|
-
assert_equal [ "pick one" ], RequiredCodePerson.new.hints[:code]
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def test_nl_ships_with_the_gem
|
|
75
|
-
I18n.with_locale(:nl) do
|
|
76
|
-
assert_includes @person.hints[:name], "moet ingevuld zijn"
|
|
77
|
-
assert_equal [ "moet gekozen zijn" ], RequiredCodePerson.new.hints[:code]
|
|
78
|
-
assert_equal [ "Name moet ingevuld zijn" ], @person.hints.full_messages_for(:name)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_every_shipped_locale_has_the_keys_of_en
|
|
83
|
-
flatten = lambda do |hash, prefix = nil|
|
|
84
|
-
hash.flat_map { |key, value| value.is_a?(Hash) ? flatten.call(value, [ prefix, key ].compact.join(".")) : [ [ prefix, key ].compact.join(".") ] }
|
|
85
|
-
end
|
|
86
|
-
en_keys = flatten.call(YAML.load_file(ValidationHints::LOCALE_PATH)["en"]).sort
|
|
87
|
-
assert_operator ValidationHints::LOCALE_PATHS.size, :>=, 2
|
|
88
|
-
ValidationHints::LOCALE_PATHS.each do |path|
|
|
89
|
-
locale, translations = YAML.load_file(path).first
|
|
90
|
-
assert_equal en_keys, flatten.call(translations).sort, "#{locale} (#{File.basename(path)})"
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def test_full_message_uses_activerecord_human_attribute_name
|
|
95
|
-
@kv.store_translations(:en, activerecord: { attributes: { person: { name: "Your name" } } })
|
|
96
|
-
|
|
97
|
-
assert_equal [ "Your name can't be blank" ], @person.hints.full_messages_for(:name)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def test_full_message_format_override
|
|
101
|
-
@kv.store_translations(:en, activerecord: { hints: { format: "%{attribute}: %{message}" } })
|
|
102
|
-
|
|
103
|
-
assert_equal [ "Name: can't be blank" ], @person.hints.full_messages_for(:name)
|
|
104
|
-
end
|
|
105
|
-
end
|
data/test/gem_build_test.rb
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "minitest/autorun"
|
|
4
|
-
require "tmpdir"
|
|
5
|
-
require "zlib"
|
|
6
|
-
require_relative "../lib/validation_hints/gem_build"
|
|
7
|
-
|
|
8
|
-
# 8.1.53 shipped every file as 0660 (the checkout's group-only modes), so an
|
|
9
|
-
# installed gem was unreadable for anyone outside the installing user and
|
|
10
|
-
# group. Gem builds now package 0644 / 0755 whatever the on-disk modes.
|
|
11
|
-
class GemBuildTest < Minitest::Test
|
|
12
|
-
REPO_ROOT = File.expand_path("..", __dir__)
|
|
13
|
-
|
|
14
|
-
def packaged_modes(gem_path)
|
|
15
|
-
modes = {}
|
|
16
|
-
File.open(gem_path, "rb") do |io|
|
|
17
|
-
Gem::Package::TarReader.new(io).each do |entry|
|
|
18
|
-
next unless entry.full_name == "data.tar.gz"
|
|
19
|
-
|
|
20
|
-
Gem::Package::TarReader.new(Zlib::GzipReader.new(entry)).each do |file|
|
|
21
|
-
modes[file.full_name] = file.header.mode & 0o777
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
modes
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def build(spec, dir, gem_dir)
|
|
29
|
-
gem_path = File.join(gem_dir, "#{spec.full_name}.gem")
|
|
30
|
-
Dir.chdir(dir) do
|
|
31
|
-
package = Gem::Package.new(gem_path)
|
|
32
|
-
package.spec = spec
|
|
33
|
-
Gem::DefaultUserInteraction.use_ui(Gem::SilentUI.new) { package.build(true) }
|
|
34
|
-
end
|
|
35
|
-
gem_path
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_group_only_files_are_packaged_world_readable
|
|
39
|
-
Dir.mktmpdir do |src|
|
|
40
|
-
Dir.mktmpdir do |out|
|
|
41
|
-
File.write(File.join(src, "plain.rb"), "# plain\n")
|
|
42
|
-
File.write(File.join(src, "tool"), "#!/bin/sh\n")
|
|
43
|
-
File.chmod(0o660, File.join(src, "plain.rb"))
|
|
44
|
-
File.chmod(0o700, File.join(src, "tool"))
|
|
45
|
-
|
|
46
|
-
spec = Gem::Specification.new do |s|
|
|
47
|
-
s.name = "modes_probe"
|
|
48
|
-
s.version = "0.0.1"
|
|
49
|
-
s.summary = "probe"
|
|
50
|
-
s.authors = [ "probe" ]
|
|
51
|
-
s.files = %w[plain.rb tool]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
modes = packaged_modes(build(spec, src, out))
|
|
55
|
-
|
|
56
|
-
assert_equal({ "plain.rb" => 0o644, "tool" => 0o755 }, modes)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def test_the_gemspec_packages_world_readable_files
|
|
62
|
-
path = File.join(REPO_ROOT, "validation_hints.gemspec")
|
|
63
|
-
spec = Gem::Specification.load(path)
|
|
64
|
-
refute_nil spec
|
|
65
|
-
|
|
66
|
-
Dir.mktmpdir do |out|
|
|
67
|
-
modes = packaged_modes(build(spec, REPO_ROOT, out))
|
|
68
|
-
|
|
69
|
-
refute_empty modes
|
|
70
|
-
unreadable = modes.reject { |_, mode| (mode & 0o444) == 0o444 }
|
|
71
|
-
assert_empty unreadable, "not world-readable in the .gem"
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
data/test/test_helper.rb
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "minitest/autorun"
|
|
5
|
-
require "active_record"
|
|
6
|
-
require "active_model"
|
|
7
|
-
|
|
8
|
-
require "validation_hints"
|
|
9
|
-
|
|
10
|
-
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
|
|
11
|
-
|
|
12
|
-
ActiveRecord::Schema.define do
|
|
13
|
-
create_table :people, force: true do |t|
|
|
14
|
-
t.string :name
|
|
15
|
-
t.string :password
|
|
16
|
-
t.string :password_confirmation
|
|
17
|
-
t.integer :age
|
|
18
|
-
t.string :status
|
|
19
|
-
t.string :email
|
|
20
|
-
t.string :code
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
class Person < ActiveRecord::Base
|
|
25
|
-
validates :name, presence: true
|
|
26
|
-
validates :password, length: { within: 1...5 }
|
|
27
|
-
validates :age, numericality: { only_integer: true, greater_than: 19 }
|
|
28
|
-
validates :status, inclusion: { in: %w[active inactive] }
|
|
29
|
-
validates :password, confirmation: true
|
|
30
|
-
validates :email, presence: { message: :required }
|
|
31
|
-
validates :code, format: { with: /\A\d+\z/ }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
class EmailFormatValidator < ActiveModel::EachValidator
|
|
35
|
-
def validate_each(record, attribute, value)
|
|
36
|
-
record.errors.add(attribute, :invalid) unless value.to_s.include?("@")
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
class CodePresenceValidator < ActiveModel::Validator
|
|
41
|
-
def validate(record)
|
|
42
|
-
record.errors.add(:code, :blank) if record.code.blank?
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class CustomValidatorPerson < ActiveRecord::Base
|
|
47
|
-
self.table_name = "people"
|
|
48
|
-
|
|
49
|
-
validates :email, email_format: true
|
|
50
|
-
validates_with CodePresenceValidator
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
class Profile < ActiveRecord::Base
|
|
54
|
-
self.table_name = "people"
|
|
55
|
-
|
|
56
|
-
attr_accessor :nickname
|
|
57
|
-
|
|
58
|
-
validates :nickname, presence: true
|
|
59
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
|
|
5
|
-
class ValidationHintsTest < Minitest::Test
|
|
6
|
-
# Lockstep releases bump VERSION without touching this gem's code, so pin the
|
|
7
|
-
# 8.1 line rather than an exact patch (which broke on the 8.1.21 bump).
|
|
8
|
-
def test_version
|
|
9
|
-
assert_match(/\A8\.1\.\d+\z/, ValidationHints::VERSION)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_locale_path_exists
|
|
13
|
-
assert File.file?(ValidationHints::LOCALE_PATH)
|
|
14
|
-
end
|
|
15
|
-
end
|