Update milestones translatable fields

Note the title field was hidden since commit 01b9aa8, even though it was
required and translatable. I've removed the required validation rule,
since it doesn't seem to make much sense and made the translatable
tests harder to write.

Also note the method `I18n.localize`, which is used to set the
milestone's title, uses `I18n.locale` even if it's inside a
`Globalize.with_locale` block, and so the same format is generated for
every locale.
This commit is contained in:
Javi Martín
2018-10-09 00:08:02 +02:00
parent a326bcb0a1
commit 01a254545f
5 changed files with 16 additions and 14 deletions

View File

@@ -46,8 +46,8 @@ class Admin::BudgetInvestmentMilestonesController < Admin::BaseController
def milestone_params def milestone_params
image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] image_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:title, :description, :publication_date, :budget_investment_id, :status_id, attributes = [:publication_date, :budget_investment_id, :status_id,
*translation_params(Budget::Investment::Milestone), translation_params(Budget::Investment::Milestone),
image_attributes: image_attributes, documents_attributes: documents_attributes] image_attributes: image_attributes, documents_attributes: documents_attributes]
params.require(:budget_investment_milestone).permit(*attributes) params.require(:budget_investment_milestone).permit(*attributes)

View File

@@ -9,11 +9,11 @@ class Budget
translates :title, :description, touch: true translates :title, :description, touch: true
globalize_accessors globalize_accessors
accepts_nested_attributes_for :translations, allow_destroy: true
belongs_to :investment belongs_to :investment
belongs_to :status, class_name: 'Budget::Investment::Status' belongs_to :status, class_name: 'Budget::Investment::Status'
validates :title, presence: true
validates :investment, presence: true validates :investment, presence: true
validates :publication_date, presence: true validates :publication_date, presence: true
validate :description_or_status_present? validate :description_or_status_present?

View File

@@ -2,9 +2,6 @@
<%= translatable_form_for [:admin, @investment.budget, @investment, @milestone] do |f| %> <%= translatable_form_for [:admin, @investment.budget, @investment, @milestone] do |f| %>
<%= f.hidden_field :title, value: l(Time.current, format: :datetime),
maxlength: Budget::Investment::Milestone.title_max_length %>
<div class="small-12 medium-6 margin-bottom"> <div class="small-12 medium-6 margin-bottom">
<%= f.select :status_id, <%= f.select :status_id,
@statuses.collect { |s| [s.name, s.id] }, @statuses.collect { |s| [s.name, s.id] },
@@ -14,9 +11,14 @@
admin_budget_investment_statuses_path %> admin_budget_investment_statuses_path %>
</div> </div>
<%= f.translatable_text_area :description, <%= f.translatable_fields do |translations_form| %>
rows: 5, <%= translations_form.hidden_field :title, value: l(Time.current, format: :datetime),
label: t("admin.milestones.new.description") %> maxlength: Budget::Investment::Milestone.title_max_length %>
<%= translations_form.text_area :description,
rows: 5,
label: t("admin.milestones.new.description") %>
<% end %>
<%= f.label :publication_date, t("admin.milestones.new.date") %> <%= f.label :publication_date, t("admin.milestones.new.date") %>
<%= f.text_field :publication_date, <%= f.text_field :publication_date,

View File

@@ -47,7 +47,7 @@ feature 'Admin budget investment milestones' do
click_link 'Create new milestone' click_link 'Create new milestone'
select status.name, from: 'budget_investment_milestone_status_id' select status.name, from: 'budget_investment_milestone_status_id'
fill_in 'budget_investment_milestone_description_en', with: 'New description milestone' fill_in 'Description', with: 'New description milestone'
fill_in 'budget_investment_milestone_publication_date', with: Date.current fill_in 'budget_investment_milestone_publication_date', with: Date.current
click_button 'Create milestone' click_button 'Create milestone'
@@ -69,7 +69,7 @@ feature 'Admin budget investment milestones' do
click_link 'Create new milestone' click_link 'Create new milestone'
fill_in 'budget_investment_milestone_description_en', with: 'New description milestone' fill_in 'Description', with: 'New description milestone'
click_button 'Create milestone' click_button 'Create milestone'
@@ -93,7 +93,7 @@ feature 'Admin budget investment milestones' do
expect(page).to have_css("img[alt='#{milestone.image.title}']") expect(page).to have_css("img[alt='#{milestone.image.title}']")
fill_in 'budget_investment_milestone_description_en', with: 'Changed description' fill_in 'Description', with: 'Changed description'
fill_in 'budget_investment_milestone_publication_date', with: Date.current fill_in 'budget_investment_milestone_publication_date', with: Date.current
fill_in 'budget_investment_milestone_documents_attributes_0_title', with: 'New document title' fill_in 'budget_investment_milestone_documents_attributes_0_title', with: 'New document title'

View File

@@ -9,9 +9,9 @@ describe Budget::Investment::Milestone do
expect(milestone).to be_valid expect(milestone).to be_valid
end end
it "is not valid without a title" do it "is valid without a title" do
milestone.title = nil milestone.title = nil
expect(milestone).not_to be_valid expect(milestone).to be_valid
end end
it "is not valid without a description if status is empty" do it "is not valid without a description if status is empty" do