generated from betagouv/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
asp: truncate the persphysique names attributes
Piggyback the `limit` option for ActiveModel's attribute method (which might be a thing one day[1]) to chop the value of the string directly on the XML-generating class. This keeps the mapping classes in charge of translating our data into the ASP stuff, semantically, but keeps the actual XML-maker in control of the formatted length, which makes more sense to me: all the XML tags have an associated length in the ASP documentation, so keeping it as close as possible to the XML generation code is nicer. It's also coherent with the custom :asp_date type which we use in a couple places (ie: prestadoss.rb) and takes care of formatting a date object in the format dictated by the ASP. Closes #678. [1]: rails/rails#51494
- Loading branch information
Showing
4 changed files
with
37 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.shared_examples "a limited string attribute" do |attribute:, length:| | ||
it "chops the '#{attribute}' attribute to #{length} characters" do | ||
model.send "#{attribute}=", Faker::Alphanumeric.alpha(number: length + 1) | ||
|
||
expect(model.send(attribute).to_s).to have(length).characters | ||
end | ||
end |