Skip to content

Commit

Permalink
AP-5141: Add test to validate document length
Browse files Browse the repository at this point in the history
If a new file name is added that is too long, e.g.

```ruby
  VALID_DOCUMENT_TYPES = %w[
    part_bank_state_evidence_pdf
    this_file_name_is_far_too_long_pdf
  ].freeze
```

Then the test will fail with

```ruby
Failures:

  1) DocumentCategoryValidator VALID_DOCUMENT_TYPE length has 30 characters or fewer to be valid
     Failure/Error: expect(doc_types).to be_empty

                            Expected { "this_file_name_is_far_too_long_pdf" => 34 }
       to return a truthy result for empty? or emptys?
```

So it will show the offending file name and how. long it is
  • Loading branch information
colinbruce committed Jul 10, 2024
1 parent 914028c commit 98ff000
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/validators/document_category_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class DummyDocumentCategory
end

RSpec.describe DocumentCategoryValidator do
describe "VALID_DOCUMENT_TYPE length" do
it "has 30 characters or fewer to be valid" do
doc_types = DocumentCategoryValidator::VALID_DOCUMENT_TYPES
.index_with(&:length)
.reject { |_k, v| v <= 30 }
expect(doc_types).to be_empty
end
end

context "with Attachment" do
subject(:document_category_validator) { Attachment.create! legal_aid_application: laa, attachment_type: }

Expand Down

0 comments on commit 98ff000

Please sign in to comment.