|
5 | 5 |
|
6 | 6 | expect(response).to have_http_status(:ok)
|
7 | 7 |
|
8 |
| - response_body = JSON.parse(response.body) |
9 |
| - expect(response_body['data']['attributes']['message']).to eq('Hello world') |
| 8 | + expect(json_response['data']['attributes']['message']).to eq('Hello world') |
10 | 9 | end
|
11 | 10 |
|
12 |
| - it 'returns Croatian hello message when Accept-Language is hr' do |
13 |
| - get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'hr') |
| 11 | + it 'returns German hello message when Accept-Language is de' do |
| 12 | + get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'de') |
14 | 13 |
|
15 | 14 | expect(response).to have_http_status(:ok)
|
16 | 15 |
|
17 |
| - response_body = JSON.parse(response.body) |
18 |
| - expect(response_body['data']['attributes']['message']).to eq('Pozdrav svijetu') |
| 16 | + expect(json_response['data']['attributes']['message']).to eq('Hallo Welt') |
19 | 17 | end
|
20 | 18 |
|
21 |
| - it 'returns Croatian hello message when Accept-Language is hr-HR (region variant)' do |
22 |
| - get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'hr-HR') |
| 19 | + it 'returns German hello message when Accept-Language is de-DE (region variant)' do |
| 20 | + get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'de-DE') |
23 | 21 |
|
24 | 22 | expect(response).to have_http_status(:ok)
|
25 | 23 |
|
26 |
| - response_body = JSON.parse(response.body) |
27 |
| - expect(response_body['data']['attributes']['message']).to eq('Pozdrav svijetu') |
| 24 | + expect(json_response['data']['attributes']['message']).to eq('Hallo Welt') |
28 | 25 | end
|
29 | 26 |
|
30 | 27 | it 'returns default English message when no Accept-Language header provided' do
|
31 | 28 | get '/api/v1/hello', headers: default_headers
|
32 | 29 |
|
33 | 30 | expect(response).to have_http_status(:ok)
|
34 | 31 |
|
35 |
| - response_body = JSON.parse(response.body) |
36 |
| - expect(response_body['data']['attributes']['message']).to eq('Hello world') |
| 32 | + expect(json_response['data']['attributes']['message']).to eq('Hello world') |
37 | 33 | end
|
38 | 34 |
|
39 | 35 | it 'prioritizes first valid locale from complex Accept-Language header' do
|
40 |
| - get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'hr-HR,hr;q=0.9,en;q=0.8') |
| 36 | + get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'de-DE,de;q=0.9,en;q=0.8') |
41 | 37 |
|
42 | 38 | expect(response).to have_http_status(:ok)
|
43 | 39 |
|
44 |
| - response_body = JSON.parse(response.body) |
45 |
| - expect(response_body['data']['attributes']['message']).to eq('Pozdrav svijetu') |
| 40 | + expect(json_response['data']['attributes']['message']).to eq('Hallo Welt') |
46 | 41 | end
|
47 | 42 |
|
48 | 43 | it 'falls back to default locale when Accept-Language header is malformed' do
|
|
57 | 52 |
|
58 | 53 | describe 'error handling with localized messages' do
|
59 | 54 | it 'responds with 400 Bad Request and English error message for invalid locale' do
|
60 |
| - get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'de') |
| 55 | + get '/api/v1/hello', headers: default_headers.merge('Accept-Language': 'fr') |
61 | 56 |
|
62 | 57 | expect(response).to have_http_status(:bad_request)
|
63 |
| - expect(response).to include_error_detail('"de" is not a valid locale') |
| 58 | + expect(response).to include_error_detail('"fr" is not a valid locale') |
64 | 59 | end
|
65 | 60 | end
|
66 | 61 | end
|
0 commit comments