Skip to content

Commit 13ae6e7

Browse files
Replace hr with de locale in localization specs
1 parent 51b2d28 commit 13ae6e7

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
I18n.available_locales = [:en, :hr]
1+
I18n.available_locales = [:en, :de]
22

33
I18n.default_locale = :en

spec/dummy/config/locales/de.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
de:
2+
hello: "Hallo Welt"
3+
4+

spec/dummy/config/locales/hr.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
de:
2+
json_api:
3+
errors:
4+
bad_request:
5+
title: Ungültige Anfrage
6+
detail: Ungültige Anfrage
7+
invalid_locale: Ungültige Sprache
8+
not_found:
9+
title: Nicht gefunden
10+
detail: Ressource nicht gefunden
11+
forbidden:
12+
title: Verboten
13+
detail: Sie dürfen diese Aktion nicht ausführen
14+
unauthorized:
15+
title: Nicht autorisiert
16+
detail: Sie müssen angemeldet sein, um diese Aktion auszuführen
17+
unprocessable_entity:
18+
title: Nicht verarbeitbar
19+
detail: Anfrage kann nicht verarbeitet werden
20+
internal_server_error:
21+
title: Interner Fehler
22+
detail: Ein interner Fehler ist aufgetreten
23+
24+

spec/requests/api/v1/error_handling_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535

3636
context 'with another locale' do
3737
it 'responds with localized error message' do
38-
get '/api/v1/locations/0', headers: default_headers.merge('Accept-Language' => 'hr')
38+
get '/api/v1/locations/0', headers: default_headers.merge('Accept-Language' => 'de')
3939

4040
expect(response).to have_http_status(:not_found)
41-
expect(json_response['errors'].first['title']).to eq('Nije pronađen')
42-
expect(json_response['errors'].first['detail']).to eq('Resurs nije pronađen')
41+
expect(json_response['errors'].first['title']).to eq('Nicht gefunden')
42+
expect(json_response['errors'].first['detail']).to eq('Ressource nicht gefunden')
4343
end
4444
end
4545
end
@@ -58,11 +58,11 @@
5858

5959
context 'with another locale' do
6060
it 'responds with localized error message' do
61-
get "/api/v1/locations/#{loc.id}", headers: default_headers.merge('Accept-Language' => 'hr')
61+
get "/api/v1/locations/#{loc.id}", headers: default_headers.merge('Accept-Language' => 'de')
6262

6363
expect(response).to have_http_status(:forbidden)
64-
expect(json_response['errors'].first['title']).to eq('Zabranjeno')
65-
expect(json_response['errors'].first['detail']).to eq('Nije Vam dozvoljeno izvršiti ovu radnju')
64+
expect(json_response['errors'].first['title']).to eq('Verboten')
65+
expect(json_response['errors'].first['detail']).to eq('Sie dürfen diese Aktion nicht ausführen')
6666
end
6767
end
6868
end

spec/requests/api/v1/locale_negotiation_spec.rb

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,39 @@
55

66
expect(response).to have_http_status(:ok)
77

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')
109
end
1110

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')
1413

1514
expect(response).to have_http_status(:ok)
1615

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')
1917
end
2018

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')
2321

2422
expect(response).to have_http_status(:ok)
2523

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')
2825
end
2926

3027
it 'returns default English message when no Accept-Language header provided' do
3128
get '/api/v1/hello', headers: default_headers
3229

3330
expect(response).to have_http_status(:ok)
3431

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')
3733
end
3834

3935
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')
4137

4238
expect(response).to have_http_status(:ok)
4339

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')
4641
end
4742

4843
it 'falls back to default locale when Accept-Language header is malformed' do
@@ -57,10 +52,10 @@
5752

5853
describe 'error handling with localized messages' do
5954
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')
6156

6257
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')
6459
end
6560
end
6661
end

0 commit comments

Comments
 (0)