Skip to content

Commit 30e323a

Browse files
authored
Merge pull request #106 from ruby-no-kai/copilot/change-form-descriptions-id-to-locale
Change FormDescription routes to use locale parameter instead of id
2 parents ca549b7 + dc38ef9 commit 30e323a

File tree

5 files changed

+87
-2
lines changed

5 files changed

+87
-2
lines changed

app/controllers/admin/form_descriptions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def set_conference
5555
end
5656

5757
def set_form_description
58-
@form_description = FormDescription.where(conference: @conference).find(params[:id])
58+
@form_description = FormDescription.where(conference: @conference).find_by!(locale: params[:locale])
5959
end
6060
end

app/models/form_description.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def to_dataset
3131

3232
validate :validate_fallback_options_json
3333

34+
def to_param
35+
locale
36+
end
37+
3438
before_save :render_markdown
3539

3640
def fallback_options

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
resource :booth_assignment, only: %i(show update)
2020

21-
resources :form_descriptions, except: %i(index)
21+
resources :form_descriptions, param: :locale, except: %i(index)
2222
resources :plans, except: %i(show)
2323

2424
resources :sponsorships, except: %i(index new create) do

spec/models/form_description_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@
33
RSpec.describe FormDescription, type: :model do
44
let(:conference) { FactoryBot.create(:conference) }
55

6+
describe '#to_param' do
7+
it 'returns locale instead of id' do
8+
form = FactoryBot.create(:form_description, conference:, locale: 'en')
9+
expect(form.to_param).to eq('en')
10+
end
11+
12+
it 'returns different locales correctly' do
13+
form_en = FactoryBot.create(:form_description, conference:, locale: 'en')
14+
form_ja = FactoryBot.create(:form_description, conference:, locale: 'ja')
15+
16+
expect(form_en.to_param).to eq('en')
17+
expect(form_ja.to_param).to eq('ja')
18+
end
19+
end
20+
621
describe '#render_markdown callback' do
722
it 'renders markdown fields to HTML on save' do
823
form = FactoryBot.create(:form_description,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Admin::FormDescriptionsController, type: :routing do
4+
describe 'routing' do
5+
it 'routes to #new' do
6+
expect(get: '/admin/conferences/rk2025/form_descriptions/new').to route_to(
7+
controller: 'admin/form_descriptions',
8+
action: 'new',
9+
conference_slug: 'rk2025'
10+
)
11+
end
12+
13+
it 'routes to #create' do
14+
expect(post: '/admin/conferences/rk2025/form_descriptions').to route_to(
15+
controller: 'admin/form_descriptions',
16+
action: 'create',
17+
conference_slug: 'rk2025'
18+
)
19+
end
20+
21+
it 'routes to #show using locale parameter' do
22+
expect(get: '/admin/conferences/rk2025/form_descriptions/en').to route_to(
23+
controller: 'admin/form_descriptions',
24+
action: 'show',
25+
conference_slug: 'rk2025',
26+
locale: 'en'
27+
)
28+
end
29+
30+
it 'routes to #edit using locale parameter' do
31+
expect(get: '/admin/conferences/rk2025/form_descriptions/ja/edit').to route_to(
32+
controller: 'admin/form_descriptions',
33+
action: 'edit',
34+
conference_slug: 'rk2025',
35+
locale: 'ja'
36+
)
37+
end
38+
39+
it 'routes to #update via PUT using locale parameter' do
40+
expect(put: '/admin/conferences/rk2025/form_descriptions/en').to route_to(
41+
controller: 'admin/form_descriptions',
42+
action: 'update',
43+
conference_slug: 'rk2025',
44+
locale: 'en'
45+
)
46+
end
47+
48+
it 'routes to #update via PATCH using locale parameter' do
49+
expect(patch: '/admin/conferences/rk2025/form_descriptions/en').to route_to(
50+
controller: 'admin/form_descriptions',
51+
action: 'update',
52+
conference_slug: 'rk2025',
53+
locale: 'en'
54+
)
55+
end
56+
57+
it 'routes to #destroy using locale parameter' do
58+
expect(delete: '/admin/conferences/rk2025/form_descriptions/ja').to route_to(
59+
controller: 'admin/form_descriptions',
60+
action: 'destroy',
61+
conference_slug: 'rk2025',
62+
locale: 'ja'
63+
)
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)