Update legislation questions translatable fields
This commit is contained in:
@@ -9,7 +9,6 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll
|
|||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@question.question_options.build
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -47,11 +46,8 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll
|
|||||||
|
|
||||||
def question_params
|
def question_params
|
||||||
params.require(:legislation_question).permit(
|
params.require(:legislation_question).permit(
|
||||||
:title,
|
translation_params(::Legislation::Question),
|
||||||
*translation_params(::Legislation::Question),
|
question_options_attributes: [translation_params(::Legislation::QuestionOption)])
|
||||||
question_options_attributes: [:id, :value,
|
|
||||||
*translation_params(::Legislation::QuestionOption)]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource
|
def resource
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ class Legislation::Question < ActiveRecord::Base
|
|||||||
|
|
||||||
translates :title, touch: true
|
translates :title, touch: true
|
||||||
globalize_accessors
|
globalize_accessors
|
||||||
|
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||||
|
|
||||||
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
|
||||||
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id'
|
||||||
@@ -17,7 +18,10 @@ class Legislation::Question < ActiveRecord::Base
|
|||||||
accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true
|
accepts_nested_attributes_for :question_options, reject_if: proc { |attributes| attributes.all? { |k, v| v.blank? } }, allow_destroy: true
|
||||||
|
|
||||||
validates :process, presence: true
|
validates :process, presence: true
|
||||||
|
|
||||||
|
translation_class.instance_eval do
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
|
end
|
||||||
|
|
||||||
scope :sorted, -> { order('id ASC') }
|
scope :sorted, -> { order('id ASC') }
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,14 @@ class Legislation::QuestionOption < ActiveRecord::Base
|
|||||||
|
|
||||||
translates :value, touch: true
|
translates :value, touch: true
|
||||||
globalize_accessors
|
globalize_accessors
|
||||||
|
accepts_nested_attributes_for :translations, allow_destroy: true
|
||||||
|
|
||||||
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options
|
||||||
has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question
|
||||||
|
|
||||||
validates :question, presence: true
|
validates :question, presence: true
|
||||||
validates :value, presence: true, uniqueness: { scope: :legislation_question_id }
|
|
||||||
|
translation_class.instance_eval do
|
||||||
|
validates :value, presence: true # TODO: add uniqueness again
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,12 +17,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= f.translatable_text_area :title,
|
<%= translations_form.text_area :title,
|
||||||
rows: 5,
|
rows: 5,
|
||||||
placeholder: t("admin.legislation.questions.form.title_placeholder"),
|
placeholder: t("admin.legislation.questions.form.title_placeholder"),
|
||||||
label: t("admin.legislation.questions.form.title") %>
|
label: t("admin.legislation.questions.form.title") %>
|
||||||
</div>
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= f.label :question_options, t("admin.legislation.questions.form.question_options") %>
|
<%= f.label :question_options, t("admin.legislation.questions.form.question_options") %>
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
<div class="nested-fields">
|
<div class="nested-fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="small-12 medium-9 column">
|
<div class="small-12 medium-9 column">
|
||||||
<%= f.translatable_text_field :value,
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
|
<%= translations_form.text_field :value,
|
||||||
placeholder: t("admin.legislation.questions.form.value_placeholder"),
|
placeholder: t("admin.legislation.questions.form.value_placeholder"),
|
||||||
label: false %>
|
label: false %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-3 column">
|
<div class="small-12 medium-3 column">
|
||||||
<%= link_to_remove_association t("admin.legislation.questions.question_option_fields.remove_option"), f, class: "delete"%>
|
<%= link_to_remove_association t("admin.legislation.questions.question_option_fields.remove_option"), f, class: "delete"%>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ feature 'Admin legislation questions' do
|
|||||||
|
|
||||||
click_link 'Create question'
|
click_link 'Create question'
|
||||||
|
|
||||||
fill_in 'legislation_question_title_en', with: 'Question 3'
|
fill_in 'Question', with: 'Question 3'
|
||||||
click_button 'Create question'
|
click_button 'Create question'
|
||||||
|
|
||||||
expect(page).to have_content 'Question 3'
|
expect(page).to have_content 'Question 3'
|
||||||
@@ -92,7 +92,7 @@ feature 'Admin legislation questions' do
|
|||||||
|
|
||||||
click_link 'Question 2'
|
click_link 'Question 2'
|
||||||
|
|
||||||
fill_in 'legislation_question_title_en', with: 'Question 2b'
|
fill_in 'Question', with: 'Question 2b'
|
||||||
click_button 'Save changes'
|
click_button 'Save changes'
|
||||||
|
|
||||||
expect(page).to have_content 'Question 2b'
|
expect(page).to have_content 'Question 2b'
|
||||||
@@ -123,12 +123,20 @@ feature 'Admin legislation questions' do
|
|||||||
title_en: "Title in English",
|
title_en: "Title in English",
|
||||||
title_es: "Título en Español") }
|
title_es: "Título en Español") }
|
||||||
|
|
||||||
before do
|
let(:edit_question_url) do
|
||||||
@edit_question_url = edit_admin_legislation_process_question_path(question.process, question)
|
edit_admin_legislation_process_question_path(question.process, question)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:field_en) do
|
||||||
|
page.all("[data-locale='en'][id^='legislation_question_question_options'][id$='value']").first
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:field_es) do
|
||||||
|
page.all("[data-locale='es'][id^='legislation_question_question_options'][id$='value']").first
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario 'Add translation for question option', :js do
|
scenario 'Add translation for question option', :js do
|
||||||
visit @edit_question_url
|
visit edit_question_url
|
||||||
|
|
||||||
click_on 'Add option'
|
click_on 'Add option'
|
||||||
|
|
||||||
@@ -139,17 +147,17 @@ feature 'Admin legislation questions' do
|
|||||||
find('#nested-question-options input').set('Opción 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('legislation_question_question_options_attributes_0_value_en', 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('legislation_question_question_options_attributes_0_value_es', with: 'Opción 1')
|
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
|
scenario 'Add new question option after changing active locale', :js do
|
||||||
visit @edit_question_url
|
visit edit_question_url
|
||||||
|
|
||||||
click_link "Español"
|
click_link "Español"
|
||||||
|
|
||||||
@@ -163,13 +171,13 @@ feature 'Admin legislation questions' do
|
|||||||
|
|
||||||
click_button "Save changes"
|
click_button "Save changes"
|
||||||
|
|
||||||
visit @edit_question_url
|
visit edit_question_url
|
||||||
|
|
||||||
expect(page).to have_field('legislation_question_question_options_attributes_0_value_en', 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('legislation_question_question_options_attributes_0_value_es', with: 'Opción 1')
|
expect(page).to have_field(field_es[:id], with: 'Opción 1')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user