Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

Read strict page values through one rule so every strict list words a refusal alike

Guido Boykee1b3b680e7f4
diff --git a/.github/workflows/guards.yml b/.github/workflows/guards.yml
index 2cdc993..b8a420e 100644
--- a/.github/workflows/guards.yml
+++ b/.github/workflows/guards.yml
@@ -360,6 +360,7 @@ jobs:
spec/services/actors/correct_meeting_term_spec.rb
spec/requests/organisations/meeting_term_corrections_spec.rb
spec/services/glossary/lookup_spec.rb
+ spec/services/list_paging_spec.rb
spec/requests/organisations/people_spec.rb
spec/requests/organisations/shown_email_spec.rb
spec/requests/user_preferences_email_visibility_spec.rb
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9308757..6418674 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,6 +39,11 @@ starts (`db:prepare lalabase:data_backfills`). Without Docker, run
becomes a link. SVG is not shown yet. Limits: 5 MB per image, 200 images per set.
- The assistant's time report over a whole organisation reads the rights once and sums in
one query, instead of three queries and a sum for every project.
+- The REST API refuses a `page` or `per_page` it cannot read with the same wording on every
+ list that refuses one (people, knowledge, meetings and the glossary), in the language of
+ the token's owner and naming the refused value. Before, people, knowledge and meetings
+ answered in English only, in two different wordings. Status codes and error codes stay as
+ they were.
### Fixed
diff --git a/CLAUDE.md b/CLAUDE.md
index 3cba9e4..3560559 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -834,6 +834,13 @@ feature by feature):
* ⚠️ **A `rescue_from` handler runs outside the token owner's language**: the action's
`around_action :with_token_owner_locale` has ended by then. A text built at the raise is right;
one built in the handler needs `with_token_owner_locale { ... }` (`TermsController#glossary_forbidden`).
+* **One strict reading of a page value**: the lists that refuse a `page`/`per_page` they cannot
+ read (the glossary on both doors; over REST the people directory, knowledge and meetings) read it
+ through `ListPaging.strict_number`: a whole number from 1 to the maximum (as text digits only,
+ as a JSON number also `2.0`), absent or empty the default, one wording in the token owner's
+ language. Each door keeps its own error class and status (400 or 422). A new strict list uses it;
+ the inbox, the posts of a ticket and `list_projects` keep rules of their own (they clamp).
+ Guard: `spec/services/list_paging_spec.rb`.
* **`GET /api/v1/me`** names `api_version` and `capabilities` from `Api::V1::Capabilities`,
pinned against the routes both ways (`spec/requests/api/v1/capabilities_spec.rb`): a new
endpoint adds its line there. Additive changes bump the minor.
diff --git a/app/controllers/api/v1/people_controller.rb b/app/controllers/api/v1/people_controller.rb
index 1a6a14e..b5ec62d 100644
--- a/app/controllers/api/v1/people_controller.rb
+++ b/app/controllers/api/v1/people_controller.rb
@@ -19,9 +19,6 @@ module Api
MAX_PER_PAGE = 100
# Far beyond any directory, so an absurd page number is refused rather than skipped to.
MAX_PAGE = 100_000
- # How much of a refused value an error message quotes back: enough to recognise it, not
- # a mirror for any amount of input.
- QUOTED_LENGTH = 20
# A list parameter the endpoint cannot take (q, page, per_page).
class InvalidParameter < StandardError; end
@@ -80,18 +77,13 @@ module Api
value.strip
end
- # A whole number from 1 to max; absent or blank is the default. A refused value is quoted
- # back only when it is text, and only its start: a list or a nested value would show
- # Ruby's insides.
+ # A whole number from 1 to max, absent or blank the default, read the strict way
+ # (ListPaging.strict_number: the rule and the wording of every list that refuses a page
+ # value, in the token owner's language).
def whole_number(name, default:, max:)
- raw = params[name]
- return default if raw.nil? || raw == ''
-
- number = Integer(raw, 10) if raw.is_a?(String) && raw.match?(/\A\d+\z/)
- return number if number&.between?(1, max)
-
- shown = raw.is_a?(String) ? " #{raw.truncate(QUOTED_LENGTH).inspect}" : ''
- raise InvalidParameter, "invalid #{name}#{shown} (expected a whole number from 1 to #{max})"
+ ListPaging.strict_number(params[name], name: name, default: default, max: max)
+ rescue ListPaging::InvalidArgument => e
+ raise InvalidParameter, e.message
end
end
end
diff --git a/app/services/CLAUDE.md b/app/services/CLAUDE.md
index 2466af9..00645bb 100644
--- a/app/services/CLAUDE.md
+++ b/app/services/CLAUDE.md
@@ -28,7 +28,9 @@ Verzeichnis-Übersicht (Auswahl):
Serialisierung mit dem Link aus `Documentation::KnowledgeLink`. Ohne Suchwort listet es
alles Lesbare (nur REST nutzt das, MCP verlangt `q`). `.options(args, strict:)`: MCP liest
Unlesbares als Standard und klemmt `per_page`, REST (`strict: true`) lehnt ab
- (`InvalidOption`, 422). Eine neue Such- oder Seitenregel gehört hierher, nicht in eine Hülle.
+ (`InvalidOption`, 422), Seitenwerte über `ListPaging.strict_number` (Regel und Text aller
+ strengen Listen). Eine neue Suchregel gehört hierher, eine neue strenge Seitenregel nach
+ `list_paging.rb`, keine in eine Hülle.
* `time_sessions/` — Lese-Objekte der Zeitdomäne. `viewing_scope.rb` ist der EINE Besitzer der
Regel „eigene oder alle Zeiten" (`:all`/`:own`/`:none` plus `#apply(relation)`), die
`ProjectPolicy#area_access?(:time_sessions)` nicht ausdrücken kann (`can_view_own ||
@@ -262,7 +264,13 @@ Verzeichnis-Übersicht (Auswahl):
REST and MCP via `Tickets::Filter`, the time session lists of `/api/v1`). A string that is no
number stays the default, as before; refused (`InvalidArgument`, REST 400, MCP invalid input)
are only a page above `MAX_PAGE` (its offset left bigint) and a list or a hash, which
- raised into a 500. Inbox and knowledge keep their own strict rule.
+ raised into a 500. Since 06.11.2026 also the strict reading, `.strict_number`: a whole number
+ from 1 to max (text digits only; a JSON number also `2.0`), absent or empty the default,
+ anything else refused with one wording in DE and EN (`services.list_paging.invalid_number`,
+ the value quoted only in part). The glossary (`Glossary::Lookup`), the people directory over
+ REST and knowledge and meetings over REST (`Knowledge::Lookup`, `strict: true`) read through
+ it, each raising its own error class. The inbox, the posts of a ticket (`Tickets::Reading`)
+ and `list_projects` keep their own rules (they clamp).
* `posts/` — `comment.rb` (REST R3a, 29.10.2026) is the ONE rule of a comment written through
a token: the MCP tool `post_comment` and `POST /api/v1/tickets/:ticket_id/posts` call it.
`parse` (format `html`/`plain`, valid UTF-8, no NUL in plain, `plain_text_body.rb`, empty
diff --git a/app/services/glossary/lookup.rb b/app/services/glossary/lookup.rb
index b75f5b2..d453055 100644
--- a/app/services/glossary/lookup.rb
+++ b/app/services/glossary/lookup.rb
@@ -35,8 +35,6 @@ module Glossary
MAX_PER_PAGE = 100
# Far beyond any glossary, so an absurd page number is refused rather than skipped to.
MAX_PAGE = 100_000
- # How much of a refused value a message quotes back.
- QUOTED_LENGTH = 20
# The machine word of a refusal for want of the glossary right, on both doors.
FORBIDDEN_REASON = 'glossary_forbidden'
@@ -99,8 +97,8 @@ module Glossary
def read(project_id: nil, page: nil, per_page: nil)
raise Refused unless allowed?
- page = whole_number(:page, page, max: MAX_PAGE) || 1
- per_page = whole_number(:per_page, per_page, max: MAX_PER_PAGE) || DEFAULT_PER_PAGE
+ page = paging(:page, page, default: 1, max: MAX_PAGE)
+ per_page = paging(:per_page, per_page, default: DEFAULT_PER_PAGE, max: MAX_PER_PAGE)
ActsAsTenant.with_tenant(@organisation) do
first = first_project_id(project_id)
terms = Pundit.policy_scope!(@viewer, GlossaryTerm).confirmed
@@ -206,20 +204,13 @@ module Glossary
id
end
- # A whole number from 1 to max, as text (REST: digits only) or as a JSON
- # number (MCP: an Integer, or a Float with a whole value, which JSON Schema
- # counts as an integer: 2.0); absent or empty is nil (the default). A refused
- # value is quoted back only when it is text or a number, and only its start.
- def whole_number(name, raw, max:)
- return nil if raw.nil? || raw == ''
-
- number = raw if raw.is_a?(Integer)
- number = raw.to_i if raw.is_a?(Float) && raw.finite? && raw == raw.floor
- number = Integer(raw, 10) if raw.is_a?(String) && raw.match?(/\A\d+\z/)
- return number if number&.between?(1, max)
-
- shown = raw.is_a?(String) || raw.is_a?(Numeric) ? " #{raw.to_s.truncate(QUOTED_LENGTH).inspect}" : ''
- raise InvalidArgument, I18n.t('services.glossary.lookup.invalid_number', name: name, shown: shown, max: max)
+ # A page value read the strict way (ListPaging.strict_number, the rule and the
+ # wording of every list that refuses one), refused as this lookup's
+ # InvalidArgument, which both doors answer.
+ def paging(name, value, default:, max:)
+ ListPaging.strict_number(value, name: name, default: default, max: max)
+ rescue ListPaging::InvalidArgument => e
+ raise InvalidArgument, e.message
end
end
end
diff --git a/app/services/knowledge/lookup.rb b/app/services/knowledge/lookup.rb
index 0e12ad1..f063a65 100644
--- a/app/services/knowledge/lookup.rb
+++ b/app/services/knowledge/lookup.rb
@@ -25,7 +25,6 @@ module Knowledge
# Bounds LIMIT page * per_page of each arm (the reasoning of Tickets::Reading::MAX_PAGE).
MAX_PAGE = 100_000
SEARCH_MODE = 'title_only'
- WHOLE_NUMBER = /\A[0-9]+\z/
Options = Struct.new(:query, :type, :page, :per_page, keyword_init: true)
class InvalidOption < ArgumentError; end
@@ -41,8 +40,8 @@ module Knowledge
# Reads the options of a lookup. An unknown type is refused on both surfaces. Page and
# per_page differ by surface: MCP has always read garbage as the default and clamped a
- # large per_page (`strict: false`); REST refuses what it cannot read (`strict: true`),
- # where an absent or empty value still means the default.
+ # large per_page (`strict: false`); REST refuses what it cannot read (`strict: true`,
+ # ListPaging.strict_number), where an absent or empty value still means the default.
#
# @param args [Hash] symbol keys q, type, page, per_page
# @raise [InvalidOption] with a message naming the argument
@@ -103,14 +102,11 @@ module Knowledge
end
private_class_method :type_arg
+ # The rule and the wording of every list that refuses a page value, refused as InvalidOption.
def self.strict_number(value, name, default, max)
- return default if value.nil? || value == ''
-
- text = value.is_a?(Integer) ? value.to_s : value
- valid = text.is_a?(String) && text.match?(WHOLE_NUMBER) && text.to_i.between?(1, max)
- raise InvalidOption, "#{name} must be a whole number from 1 to #{max}" unless valid
-
- text.to_i
+ ListPaging.strict_number(value, name: name, default: default, max: max)
+ rescue ListPaging::InvalidArgument => e
+ raise InvalidOption, e.message
end
private_class_method :strict_number
diff --git a/app/services/list_paging.rb b/app/services/list_paging.rb
index 0344343..29e0282 100644
--- a/app/services/list_paging.rb
+++ b/app/services/list_paging.rb
@@ -1,19 +1,30 @@
# frozen_string_literal: true
-# The page and per_page of a token list (the ticket list of REST and MCP, the time
-# sessions of /api/v1), read the lenient way those lists always read them: a string
-# that is no number is the default. Only what used to raise past the callers into a
-# 500 is refused: a page so far out that the offset leaves PostgreSQL's bigint, and
-# a value that is a list or a hash (`page[]=1`), where `.to_i` raised NoMethodError.
+# The page and per_page of a token list, read one of two ways.
#
-# The inbox (Notifications::InboxQuery) and knowledge (Knowledge::Lookup) read
-# their paging strictly by a contract of their own; this does not replace theirs.
+# * Lenient (.page, .per_page): the ticket list of REST and MCP and the time sessions of
+# /api/v1 read them the way those lists always did: a string that is no number is the
+# default. Only what used to raise past the callers into a 500 is refused: a page so far
+# out that the offset leaves PostgreSQL's bigint, and a value that is a list or a hash
+# (`page[]=1`), where `.to_i` raised NoMethodError.
+# * Strict (.strict_number): the lists that refuse what they cannot read rather than take
+# the default, so a program never gets fewer rows than it asked for without being told: the
+# glossary (Glossary::Lookup, REST and MCP) and, over /api/v1, the people directory and the
+# knowledge and meetings lists (Knowledge::Lookup, strict: true). One rule and one wording
+# for them all, in the language of the moment (the token owner's on a token request).
+#
+# Three lists keep a rule of their own: the inbox (Notifications::InboxQuery clamps per_page
+# and reads a page below 1 as 1), the posts of a ticket (Tickets::Reading, which may clamp
+# posts_per_page) and the MCP tool list_projects (clamps per_page).
#
# Entry point: page
class ListPaging
# Far beyond any real list (100_000 pages of 100 rows), close enough to keep
# (page - 1) * per_page inside PostgreSQL's OFFSET range. The inbox's bound.
MAX_PAGE = 100_000
+ # How much of a refused value a strict refusal quotes back: enough to recognise it, not a
+ # mirror for any amount of input.
+ QUOTED_LENGTH = 20
class InvalidArgument < ArgumentError; end
@@ -33,6 +44,25 @@ class ListPaging
[number, max].min
end
+ # => Integer from 1 to max; absent or empty is the default. A whole number as text (the
+ # query string: digits only) or as a JSON number (an Integer, or a Float with a whole value,
+ # which JSON Schema counts as an integer: 2.0). Anything else is refused, the value quoted
+ # back only when it is text or a number, and only its start: a list or a nested value would
+ # show Ruby's insides.
+ #
+ # @raise [InvalidArgument]
+ def self.strict_number(value, name:, default:, max:)
+ return default if value.nil? || value == ''
+
+ number = value if value.is_a?(Integer)
+ number = value.to_i if value.is_a?(Float) && value.finite? && value == value.floor
+ number = Integer(value, 10) if value.is_a?(String) && value.match?(/\A\d+\z/)
+ return number if number&.between?(1, max)
+
+ shown = value.is_a?(String) || value.is_a?(Numeric) ? " #{value.to_s.truncate(QUOTED_LENGTH).inspect}" : ''
+ raise InvalidArgument, I18n.t('services.list_paging.invalid_number', name: name, shown: shown, max: max)
+ end
+
def self.scalar(value, name:)
return value if value.nil? || value.is_a?(String) || value.is_a?(Integer)
diff --git a/config/locales/services.de.yml b/config/locales/services.de.yml
index 729896a..0d86c53 100644
--- a/config/locales/services.de.yml
+++ b/config/locales/services.de.yml
@@ -128,12 +128,15 @@ de:
# unknown, missing endpoint, invalid access), the raw English exception must
# not end up in the user-visible summary_creation_error column.
provider_error: "Der gewählte KI-Anbieter konnte keine Zusammenfassung erstellen. Bitte prüfen Sie Anbieter, Modell und Zugang in den KI-Einstellungen."
- # The refusals of the glossary read through a token (Glossary::Lookup), on
+ # The refusal of the glossary read through a token (Glossary::Lookup), on
# both doors: GET /api/v1/organisations/:id/terms and the MCP tool get_glossary.
glossary:
lookup:
forbidden: Sie dürfen das Glossar dieser Organisation nicht lesen.
- invalid_number: "ungültiger Wert für %{name}%{shown} (erwartet ist eine ganze Zahl von 1 bis %{max})"
+ # A page or per_page the strict lists refuse (ListPaging.strict_number): the
+ # glossary, and over /api/v1 the people directory and the knowledge and meetings lists.
+ list_paging:
+ invalid_number: "ungültiger Wert für %{name}%{shown} (erwartet ist eine ganze Zahl von 1 bis %{max})"
meetings:
intake:
meeting_inbox_missing: Ohne Projekt braucht die Organisation ein Eingangsprojekt. Dort ist keines gesetzt.
diff --git a/config/locales/services.en.yml b/config/locales/services.en.yml
index 65ddc5e..dcf3b10 100644
--- a/config/locales/services.en.yml
+++ b/config/locales/services.en.yml
@@ -128,12 +128,15 @@ en:
# unknown, missing endpoint, invalid access), the raw English exception must
# not end up in the user-visible summary_creation_error column.
provider_error: "The selected AI provider could not create a summary. Please check provider, model and access in the AI settings."
- # The refusals of the glossary read through a token (Glossary::Lookup), on
+ # The refusal of the glossary read through a token (Glossary::Lookup), on
# both doors: GET /api/v1/organisations/:id/terms and the MCP tool get_glossary.
glossary:
lookup:
forbidden: You may not read the glossary of this organisation.
- invalid_number: "invalid %{name}%{shown} (expected a whole number from 1 to %{max})"
+ # A page or per_page the strict lists refuse (ListPaging.strict_number): the
+ # glossary, and over /api/v1 the people directory and the knowledge and meetings lists.
+ list_paging:
+ invalid_number: "invalid %{name}%{shown} (expected a whole number from 1 to %{max})"
meetings:
intake:
meeting_inbox_missing: Without a project the organisation needs an inbox project, and none is set.
diff --git a/spec/requests/api/v1/knowledge_spec.rb b/spec/requests/api/v1/knowledge_spec.rb
index 2a47e82..dc40cef 100644
--- a/spec/requests/api/v1/knowledge_spec.rb
+++ b/spec/requests/api/v1/knowledge_spec.rb
@@ -273,6 +273,20 @@ RSpec.describe 'REST knowledge', :ci_guard, type: :request do
expect_invalid_input(/per_page/)
end
+ # One wording for every list that refuses a page value (ListPaging.strict_number), the
+ # glossary's, in the token owner's language.
+ it 'names the refused value in the language of the token owner' do
+ token = token_for(reader)
+ get_json(reader, { per_page: '101' }, token: token)
+ expect_invalid_input(/per_page/)
+ expect(response.parsed_body['message'])
+ .to eq('ungültiger Wert für per_page "101" (erwartet ist eine ganze Zahl von 1 bis 100)')
+
+ reader.update!(language_preference: 'en')
+ get_json(reader, { page: '0' }, token: token)
+ expect(response.parsed_body['message']).to eq('invalid page "0" (expected a whole number from 1 to 100000)')
+ end
+
it 'refuses a NUL in q, which would otherwise reach the database' do
get "/api/v1/projects/#{project.id}/knowledge?q=a%00b", headers: { 'Authorization' => "Bearer #{token_for(reader)}" }
expect_invalid_input(/q/)
diff --git a/spec/requests/api/v1/meetings_read_spec.rb b/spec/requests/api/v1/meetings_read_spec.rb
index 7e73ee8..87563cb 100644
--- a/spec/requests/api/v1/meetings_read_spec.rb
+++ b/spec/requests/api/v1/meetings_read_spec.rb
@@ -186,6 +186,18 @@ RSpec.describe 'REST meetings', :ci_guard, type: :request do
end
end
+ # One wording for every list that refuses a page value (ListPaging.strict_number), the
+ # glossary's, in the token owner's language.
+ it 'names the refused value in the language of the token owner' do
+ list('?per_page=101')
+ expect(response.parsed_body['message'])
+ .to eq('ungültiger Wert für per_page "101" (erwartet ist eine ganze Zahl von 1 bis 100)')
+
+ reader.update!(language_preference: 'en')
+ list('?page=0')
+ expect(response.parsed_body['message']).to eq('invalid page "0" (expected a whole number from 1 to 100000)')
+ end
+
['q=a%00b', 'q[]=a'].each do |query|
it "refuses #{query} with 422" do
expect(list("?#{query}")).to have_http_status(:unprocessable_content)
diff --git a/spec/requests/api/v1/people_spec.rb b/spec/requests/api/v1/people_spec.rb
index bf0440b..b2f408e 100644
--- a/spec/requests/api/v1/people_spec.rb
+++ b/spec/requests/api/v1/people_spec.rb
@@ -177,10 +177,21 @@ RSpec.describe 'API V1 people', :ci_guard, type: :request do
list(per_page: '9' * 5000)
expect(response).to have_http_status(:bad_request)
- expect(body['message']).to start_with('invalid per_page "999')
+ expect(body['message']).to start_with('ungültiger Wert für per_page "999')
expect(body['message'].length).to be < 100
end
+ # One wording for every list that refuses a page value (ListPaging.strict_number), the
+ # glossary's, in the token owner's language.
+ it 'names the refused value in the language of the token owner' do
+ list(per_page: '101')
+ expect(body['message']).to eq('ungültiger Wert für per_page "101" (erwartet ist eine ganze Zahl von 1 bis 100)')
+
+ user.update!(language_preference: 'en')
+ list(page: '0')
+ expect(body['message']).to eq('invalid page "0" (expected a whole number from 1 to 100000)')
+ end
+
it 'answers a page past the end with no rows and the total' do
list(page: 2)
@@ -213,11 +224,13 @@ RSpec.describe 'API V1 people', :ci_guard, type: :request do
end
# A list or a nested value is no number and no text either: 400, never a 500 from code that
- # expected a string, and the message names the parameter without Ruby's insides.
+ # expected a string, and the message names the parameter without Ruby's insides (read in
+ # English, where it starts with the parameter).
{ page: [['2'], { 'a' => '1' }], per_page: [['2'], { 'a' => '1' }], q: [['doris'], { 'a' => 'x' }] }
.each do |name, values|
values.each do |value|
it "refuses #{name} given as a #{value.class.name.downcase} with invalid_input" do
+ user.update!(language_preference: 'en')
list(name => value)
expect(response).to have_http_status(:bad_request)
diff --git a/spec/services/list_paging_spec.rb b/spec/services/list_paging_spec.rb
new file mode 100644
index 0000000..3bc7bbf
--- /dev/null
+++ b/spec/services/list_paging_spec.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+require 'rails_helper'
+
+# The strict reading of one paging value (ListPaging.strict_number): the one rule of the lists
+# that refuse what they cannot read, the glossary (REST and MCP) and, over /api/v1, the people
+# directory and the knowledge and meetings lists. The lenient ListPaging.page and .per_page are
+# held where their lists are read (Tickets::Filter, list_tickets).
+RSpec.describe ListPaging, :ci_guard do
+ describe '.strict_number' do
+ def strict(value, name: :per_page, default: 50, max: 100)
+ described_class.strict_number(value, name: name, default: default, max: max)
+ end
+
+ it 'takes an absent or empty value as the default' do
+ expect(strict(nil)).to eq(50)
+ expect(strict('')).to eq(50)
+ end
+
+ it 'takes a whole number from 1 to max, as text (a query string) or as a JSON number' do
+ expect(strict('1')).to eq(1)
+ expect(strict('100')).to eq(100)
+ expect(strict('007')).to eq(7)
+ expect(strict(42)).to eq(42)
+ end
+
+ # JSON Schema counts 2.0 as an integer, so the MCP SDK lets it through and a client that
+ # sends numbers as floats sends it.
+ it 'takes a whole number written with a point (2.0) as that number' do
+ expect(strict(2.0)).to eq(2)
+ end
+
+ it 'refuses whatever is no whole number from 1 to max' do
+ ['0', '101', '-1', '+2', ' 2', '2 ', '1.5', '2.0', 'x', '1e2', 0, 101, -1, 2.5, 0.0,
+ Float::INFINITY, Float::NAN, ['2'], { 'a' => '1' }, true].each do |value|
+ expect { strict(value) }.to raise_error(described_class::InvalidArgument), "value #{value.inspect}"
+ end
+ end
+
+ it 'names the refused value and what it takes, in English' do
+ I18n.with_locale(:en) do
+ expect { strict('101') }
+ .to raise_error(described_class::InvalidArgument, 'invalid per_page "101" (expected a whole number from 1 to 100)')
+ expect { strict(2.5, name: :page, max: 100_000) }
+ .to raise_error(described_class::InvalidArgument, 'invalid page "2.5" (expected a whole number from 1 to 100000)')
+ end
+ end
+
+ it 'names them in German' do
+ I18n.with_locale(:de) do
+ expect { strict('101') }
+ .to raise_error(described_class::InvalidArgument,
+ 'ungültiger Wert für per_page "101" (erwartet ist eine ganze Zahl von 1 bis 100)')
+ end
+ end
+
+ # The message names the refused value, but mirrors no amount of input back, and never
+ # Ruby's insides of a list or a nested value.
+ it 'quotes only the start of a text or a number, and nothing of a list or a hash' do
+ I18n.with_locale(:en) do
+ expect { strict('9' * 5000) }.to raise_error(described_class::InvalidArgument) { |error|
+ expect(error.message).to start_with('invalid per_page "99999999999999999..." (expected')
+ expect(error.message.length).to be < 100
+ }
+ [['2'], { 'a' => '1' }, true].each do |value|
+ expect { strict(value) }
+ .to raise_error(described_class::InvalidArgument, 'invalid per_page (expected a whole number from 1 to 100)')
+ end
+ end
+ end
+ end
+end