Fix legislation options not being updated

We broke this behaviour by introducing translations and not allowing the
`id` parameter anymore.
This commit is contained in:
Javi Martín
2018-10-15 16:33:46 +02:00
parent 3db145d5db
commit 6952c9c9db
2 changed files with 50 additions and 34 deletions

View File

@@ -47,7 +47,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll
def question_params def question_params
params.require(:legislation_question).permit( params.require(:legislation_question).permit(
translation_params(::Legislation::Question), translation_params(::Legislation::Question),
question_options_attributes: [translation_params(::Legislation::QuestionOption)]) question_options_attributes: [:id, translation_params(::Legislation::QuestionOption)])
end end
def resource def resource

View File

@@ -113,11 +113,8 @@ feature 'Admin legislation questions' do
end end
end end
context "Special translation behaviour" do context "Legislation options" do
let!(:question) { create(:legislation_question) }
let!(:question) { create(:legislation_question,
title_en: "Title in English",
title_es: "Título en Español") }
let(:edit_question_url) do let(:edit_question_url) do
edit_admin_legislation_process_question_path(question.process, question) edit_admin_legislation_process_question_path(question.process, question)
@@ -132,49 +129,68 @@ feature 'Admin legislation questions' do
end end
end end
scenario 'Add translation for question option', :js do scenario "Edit an existing option", :js do
create(:legislation_question_option, question: question, value: "Original")
visit edit_question_url visit edit_question_url
find("#nested-question-options input").set("Changed")
click_on 'Add option'
find('#nested-question-options input').set('Option 1')
click_link "Español"
find('#nested-question-options input').set('Opción 1')
click_button "Save changes" click_button "Save changes"
expect(page).not_to have_css "#error_explanation"
visit edit_question_url visit edit_question_url
expect(page).to have_field(field_en[:id], with: "Changed")
expect(page).to have_field(field_en[:id], with: 'Option 1')
click_link "Español"
expect(page).to have_field(field_es[:id], with: 'Opción 1')
end end
scenario 'Add new question option after changing active locale', :js do context "Special translation behaviour" do
visit edit_question_url before do
question.update_attributes(title_en: "Title in English", title_es: "Título en Español")
end
click_link "Español" scenario 'Add translation for question option', :js do
visit edit_question_url
click_on 'Add option' click_on 'Add option'
find('#nested-question-options input').set('Opción 1') find('#nested-question-options input').set('Option 1')
click_link "English" click_link "Español"
find('#nested-question-options input').set('Option 1') find('#nested-question-options input').set('Opción 1')
click_button "Save changes" click_button "Save changes"
visit edit_question_url
visit edit_question_url expect(page).to have_field(field_en[:id], with: 'Option 1')
expect(page).to have_field(field_en[:id], with: 'Option 1') click_link "Español"
click_link "Español" expect(page).to have_field(field_es[:id], with: 'Opción 1')
end
expect(page).to have_field(field_es[:id], with: 'Opción 1') scenario 'Add new question option after changing active locale', :js do
visit edit_question_url
click_link "Español"
click_on 'Add option'
find('#nested-question-options input').set('Opción 1')
click_link "English"
find('#nested-question-options input').set('Option 1')
click_button "Save changes"
visit edit_question_url
expect(page).to have_field(field_en[:id], with: 'Option 1')
click_link "Español"
expect(page).to have_field(field_es[:id], with: 'Opción 1')
end
end end
end end
end end