|
1 | 1 | RSpec.describe 'errors shared automatically', type: :request do
|
| 2 | + context 'always_include_errors_hash configuration' do |
| 3 | + let(:server_version) { 1.0 } |
| 4 | + let(:headers) { { 'X-Inertia' => true } } |
| 5 | + |
| 6 | + after { InertiaRails.configure { |c| c.always_include_errors_hash = nil } } |
| 7 | + |
| 8 | + context 'when always_include_errors_hash is true' do |
| 9 | + before { InertiaRails.configure { |c| c.always_include_errors_hash = true } } |
| 10 | + |
| 11 | + it 'includes empty errors hash when no errors present' do |
| 12 | + get empty_test_path, headers: headers |
| 13 | + expect(response.body).to include({ errors: {} }.to_json) |
| 14 | + end |
| 15 | + |
| 16 | + it 'still includes actual errors when they exist' do |
| 17 | + post redirect_with_inertia_errors_path, headers: headers |
| 18 | + get response.headers['Location'], headers: headers |
| 19 | + expect(response.body).to include({ errors: { uh: 'oh' } }.to_json) |
| 20 | + end |
| 21 | + end |
| 22 | + |
| 23 | + context 'when always_include_errors_hash is false' do |
| 24 | + before { InertiaRails.configure { |c| c.always_include_errors_hash = false } } |
| 25 | + |
| 26 | + it 'does not include errors hash when no errors present' do |
| 27 | + get empty_test_path, headers: headers |
| 28 | + expect(response.body).not_to include('"errors"') |
| 29 | + end |
| 30 | + |
| 31 | + it 'still includes actual errors when they exist' do |
| 32 | + post redirect_with_inertia_errors_path, headers: headers |
| 33 | + get response.headers['Location'], headers: headers |
| 34 | + expect(response.body).to include({ errors: { uh: 'oh' } }.to_json) |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + context 'when always_include_errors_hash is nil (default)' do |
| 39 | + before { InertiaRails.configure { |c| c.always_include_errors_hash = nil } } |
| 40 | + |
| 41 | + it 'shows deprecation warning and does not include empty errors hash' do |
| 42 | + expect { get empty_test_path, headers: headers } |
| 43 | + .to output(/To comply with the Inertia protocol/).to_stderr |
| 44 | + expect(response.body).not_to include('"errors"') |
| 45 | + end |
| 46 | + |
| 47 | + it 'still includes actual errors when they exist' do |
| 48 | + post redirect_with_inertia_errors_path, headers: headers |
| 49 | + get response.headers['Location'], headers: headers |
| 50 | + expect(response.body).to include({ errors: { uh: 'oh' } }.to_json) |
| 51 | + end |
| 52 | + end |
| 53 | + end |
| 54 | + |
2 | 55 | context 'rendering errors across redirects' do
|
3 | 56 | let(:server_version){ 1.0 }
|
4 | 57 | let(:headers){ { 'X-Inertia' => true, 'X-Inertia-Version' => server_version } }
|
|
0 commit comments