Sha256: 0d3e2f7c9b020b97d1e85e994cf3ca8d7750a1185d2f3da7696d17268163186c
Contents?: true
Size: 1.63 KB
Versions: 76
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true require 'rails_helper' describe LHS::Item do context 'error codes' do before do I18n.reload! I18n.backend.store_translations(:en, YAML.safe_load(translation)) if translation.present? class Record < LHS::Record endpoint 'http://datastore/records' end end let(:translation) do %q{ lhs: errors: fallback_message: 'This value is wrong' } end it 'provides error codes along side with translated messages' do stub_request(:post, 'http://datastore/records') .to_return(body: { field_errors: [{ code: 'UNSUPPORTED_PROPERTY_VALUE', path: ['gender'], message: 'The property value is unsupported.' }, { code: 'INCOMPLETE_PROPERTY_VALUE', path: ['gender'], message: 'The property value is incomplete. It misses some data' }, { code: 'INCOMPLETE_PROPERTY_VALUE', path: ['contract', 'entry_id'], message: 'The property value is incomplete. It misses some data' }] }.to_json) record = Record.create expect(record.errors.messages['gender']).to eq( ['This value is wrong', 'This value is wrong'] ) expect(record.errors.codes['gender']).to eq( ['UNSUPPORTED_PROPERTY_VALUE', 'INCOMPLETE_PROPERTY_VALUE'] ) expect(record.errors.messages['contract.entry_id']).to eq( ['This value is wrong'] ) expect(record.errors.codes['contract.entry_id']).to eq( ['INCOMPLETE_PROPERTY_VALUE'] ) end end end
Version data entries
76 entries across 76 versions & 1 rubygems