diff options
| author | Teddy Wing | 2017-08-25 18:11:06 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-08-25 18:11:06 +0200 | 
| commit | 9e4616f8dd82545aa2101aee96ca08615343c28e (patch) | |
| tree | 7bf09039a1147c5fabff28b25c0eac82499b668f /spec/models/concerns | |
| parent | 614719bfd45d496c686366842fa57277e71664dd (diff) | |
| download | chouette-core-9e4616f8dd82545aa2101aee96ca08615343c28e.tar.bz2 | |
ErrorFormat: Change collection structure
These tests were failing:
    1) NetexImport POST netex_imports with correct credentials and incorrect request behaves like illegal attributes missing file does not succeed
       Failure/Error: expect( json_response_body['errors'][bad_attribute.to_s] ).not_to be_empty
       TypeError:
         no implicit conversion of String into Integer
       Shared Example Group: "illegal attributes" called from ./spec/requests/api/v1/netex_import_spec.rb:90
       # ./spec/requests/api/v1/netex_import_spec.rb:77:in `[]'
       # ./spec/requests/api/v1/netex_import_spec.rb:77:in `block (6 levels) in <top (required)>'
       # -e:1:in `<main>'
    2) NetexImport POST netex_imports with correct credentials and incorrect request name already taken behaves like illegal attributes missing name does not succeed
       Failure/Error: expect( json_response_body['errors'][bad_attribute.to_s] ).not_to be_empty
       TypeError:
         no implicit conversion of String into Integer
       Shared Example Group: "illegal attributes" called from ./spec/requests/api/v1/netex_import_spec.rb:96
       # ./spec/requests/api/v1/netex_import_spec.rb:77:in `[]'
       # ./spec/requests/api/v1/netex_import_spec.rb:77:in `block (6 levels) in <top (required)>'
       # -e:1:in `<main>'
The problem was caused by the fact that the error messages come back
from `ErrorFormat` as an array of hashes, which contain a single key
corresponding to the invalid field.
Instead, the error messages should be returned as a single hash with a
bunch of keys corresponding to the invalid fields.
This change gets the above tests to pass.
Diffstat (limited to 'spec/models/concerns')
| -rw-r--r-- | spec/models/concerns/error_format_spec.rb | 14 | 
1 files changed, 7 insertions, 7 deletions
diff --git a/spec/models/concerns/error_format_spec.rb b/spec/models/concerns/error_format_spec.rb index 9b0110bcd..45b4c2f60 100644 --- a/spec/models/concerns/error_format_spec.rb +++ b/spec/models/concerns/error_format_spec.rb @@ -18,9 +18,9 @@ RSpec.describe ErrorFormat do        it 'if an error is present and validation has been carried out' do          invalid = build_stubbed(:referential, name: nil)          expect( invalid ).not_to be_valid -        expect( described_class.details(invalid) ).to eq([ -          {name: {error: 'doit ĂȘtre rempli(e)', value: nil}} -        ]) +        expect( described_class.details(invalid) ).to eq({ +          name: { error: 'doit ĂȘtre rempli(e)', value: nil } +        })        end        it 'and can even hold many errors' do @@ -31,10 +31,10 @@ RSpec.describe ErrorFormat do            slug: 'hello world'          )          expect( invalid ).not_to be_valid -        expect( described_class.details(invalid) ).to eq([ -          {name: {error: "n'est pas disponible", value: 'hello'}}, -          {slug: {error: "n'est pas valide", value: 'hello world'}} -        ]) +        expect( described_class.details(invalid) ).to eq({ +          name: { error: "n'est pas disponible", value: 'hello' }, +          slug: { error: "n'est pas valide", value: 'hello world' } +        })        end      end    end  | 
