|
| 1 | +# frozen_string_literal: true |
| 2 | + |
1 | 3 | RSpec.describe InertiaRails::Middleware, type: :request do |
2 | | - context 'the version is stale' do |
3 | | - it 'tells the client to refresh' do |
4 | | - get empty_test_path, headers: {'X-Inertia' => true, 'X-Inertia-Version' => 'blkajdf'} |
| 4 | + context 'the version is set' do |
| 5 | + with_inertia_config version: '1.0' |
| 6 | + |
| 7 | + it 'tells the client with stale version to refresh' do |
| 8 | + get empty_test_path, headers: { 'X-Inertia' => true, 'X-Inertia-Version' => 'stale' } |
5 | 9 |
|
6 | 10 | expect(response.status).to eq 409 |
7 | 11 | expect(response.headers['X-Inertia-Location']).to eq request.original_url |
8 | 12 | end |
| 13 | + |
| 14 | + it 'returns page when version is up to date' do |
| 15 | + get empty_test_path, headers: { 'X-Inertia' => true, 'X-Inertia-Version' => '1.0' } |
| 16 | + |
| 17 | + expect(response.status).to eq 200 |
| 18 | + end |
| 19 | + |
| 20 | + it 'returns response for non-inertia requests' do |
| 21 | + get empty_test_path, headers: { 'X-Inertia-Version' => 'stale' } |
| 22 | + |
| 23 | + expect(response.status).to eq 200 |
| 24 | + end |
| 25 | + |
| 26 | + it 'returns 404 on unknown route' do |
| 27 | + expect do |
| 28 | + get '/unknown_route', headers: { 'X-Inertia' => true, 'X-Inertia-Version' => '1.0' } |
| 29 | + end.to raise_error(ActionController::RoutingError) |
| 30 | + end |
9 | 31 | end |
10 | 32 |
|
11 | 33 | context 'a redirect status was passed with an http method that preserves itself on 302 redirect' do |
12 | 34 | subject { response.status } |
13 | 35 |
|
14 | 36 | context 'PUT' do |
15 | | - before { put redirect_test_path, headers: {'X-Inertia' => true} } |
| 37 | + before { put redirect_test_path, headers: { 'X-Inertia' => true } } |
16 | 38 |
|
17 | 39 | it { is_expected.to eq 303 } |
18 | 40 | end |
19 | 41 |
|
20 | 42 | context 'PATCH' do |
21 | | - before { patch redirect_test_path, headers: {'X-Inertia' => true} } |
| 43 | + before { patch redirect_test_path, headers: { 'X-Inertia' => true } } |
22 | 44 |
|
23 | 45 | it { is_expected.to eq 303 } |
24 | 46 | end |
25 | 47 |
|
26 | 48 | context 'DELETE' do |
27 | | - before { delete redirect_test_path, headers: {'X-Inertia' => true} } |
| 49 | + before { delete redirect_test_path, headers: { 'X-Inertia' => true } } |
28 | 50 |
|
29 | 51 | it { is_expected.to eq 303 } |
30 | 52 | end |
|
47 | 69 | expect(statusses.uniq).to eq([303]) |
48 | 70 | end |
49 | 71 | end |
50 | | - |
51 | | - context 'a request not originating from inertia' do |
52 | | - it 'is ignored' do |
53 | | - get empty_test_path, headers: {'X-Inertia-Version' => 'blkajdf'} |
54 | | - |
55 | | - expect(response.status).to eq 200 |
56 | | - end |
57 | | - end |
58 | 72 | end |
0 commit comments