Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/form_descriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ def set_conference
end

def set_form_description
@form_description = FormDescription.where(conference: @conference).find(params[:id])
@form_description = FormDescription.where(conference: @conference).find_by!(locale: params[:locale])
end
end
4 changes: 4 additions & 0 deletions app/models/form_description.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def to_dataset

validate :validate_fallback_options_json

def to_param
locale
end

before_save :render_markdown

def fallback_options
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

resources :form_descriptions, except: %i(index)
resources :form_descriptions, param: :locale, except: %i(index)
resources :plans, except: %i(index show)

resources :sponsorships, except: %i(index new create) do
Expand Down
15 changes: 15 additions & 0 deletions spec/models/form_description_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
RSpec.describe FormDescription, type: :model do
let(:conference) { FactoryBot.create(:conference) }

describe '#to_param' do
it 'returns locale instead of id' do
form = FactoryBot.create(:form_description, conference:, locale: 'en')
expect(form.to_param).to eq('en')
end

it 'returns different locales correctly' do
form_en = FactoryBot.create(:form_description, conference:, locale: 'en')
form_ja = FactoryBot.create(:form_description, conference:, locale: 'ja')

expect(form_en.to_param).to eq('en')
expect(form_ja.to_param).to eq('ja')
end
end

describe '#render_markdown callback' do
it 'renders markdown fields to HTML on save' do
form = FactoryBot.create(:form_description,
Expand Down
66 changes: 66 additions & 0 deletions spec/routing/form_descriptions_routing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'rails_helper'

RSpec.describe Admin::FormDescriptionsController, type: :routing do
describe 'routing' do
it 'routes to #new' do
expect(get: '/admin/conferences/rk2025/form_descriptions/new').to route_to(
controller: 'admin/form_descriptions',
action: 'new',
conference_slug: 'rk2025'
)
end

it 'routes to #create' do
expect(post: '/admin/conferences/rk2025/form_descriptions').to route_to(
controller: 'admin/form_descriptions',
action: 'create',
conference_slug: 'rk2025'
)
end

it 'routes to #show using locale parameter' do
expect(get: '/admin/conferences/rk2025/form_descriptions/en').to route_to(
controller: 'admin/form_descriptions',
action: 'show',
conference_slug: 'rk2025',
locale: 'en'
)
end

it 'routes to #edit using locale parameter' do
expect(get: '/admin/conferences/rk2025/form_descriptions/ja/edit').to route_to(
controller: 'admin/form_descriptions',
action: 'edit',
conference_slug: 'rk2025',
locale: 'ja'
)
end

it 'routes to #update via PUT using locale parameter' do
expect(put: '/admin/conferences/rk2025/form_descriptions/en').to route_to(
controller: 'admin/form_descriptions',
action: 'update',
conference_slug: 'rk2025',
locale: 'en'
)
end

it 'routes to #update via PATCH using locale parameter' do
expect(patch: '/admin/conferences/rk2025/form_descriptions/en').to route_to(
controller: 'admin/form_descriptions',
action: 'update',
conference_slug: 'rk2025',
locale: 'en'
)
end

it 'routes to #destroy using locale parameter' do
expect(delete: '/admin/conferences/rk2025/form_descriptions/ja').to route_to(
controller: 'admin/form_descriptions',
action: 'destroy',
conference_slug: 'rk2025',
locale: 'ja'
)
end
end
end