Merge pull request #2195 from consul/milestones_improvements

Make Milestones description required, hide title usage
This commit is contained in:
Alberto García
2017-12-15 18:47:30 +01:00
committed by GitHub
6 changed files with 11 additions and 10 deletions

View File

@@ -10,12 +10,14 @@ class Budget
belongs_to :investment belongs_to :investment
validates :title, presence: true validates :title, presence: true
validates :description, presence: true
validates :investment, presence: true validates :investment, presence: true
validates :publication_date, presence: true validates :publication_date, presence: true
def self.title_max_length def self.title_max_length
80 80
end end
end end
end end
end end

View File

@@ -1,6 +1,6 @@
<%= form_for [:admin, @investment.budget, @investment, @milestone] do |f| %> <%= form_for [:admin, @investment.budget, @investment, @milestone] do |f| %>
<%= f.text_field :title, maxlength: Budget::Investment::Milestone.title_max_length %> <%= f.hidden_field :title, value: l(Time.current, format: :datetime), maxlength: Budget::Investment::Milestone.title_max_length %>
<%= f.text_area :description, rows: 5 %> <%= f.text_area :description, rows: 5 %>
<%= f.text_field :publication_date, <%= f.text_field :publication_date,
value: @milestone.publication_date.present? ? l(@milestone.publication_date.to_date) : nil, value: @milestone.publication_date.present? ? l(@milestone.publication_date.to_date) : nil,

View File

@@ -11,7 +11,6 @@
<% @investment.milestones.each do |milestone| %> <% @investment.milestones.each do |milestone| %>
<li> <li>
<div class="milestone-content"> <div class="milestone-content">
<h3><%= milestone.title %></h3>
<% if milestone.publication_date.present? %> <% if milestone.publication_date.present? %>
<span class="milestone-date"> <span class="milestone-date">
<strong><%= t("budgets.investments.show.milestone_publication_date", <strong><%= t("budgets.investments.show.milestone_publication_date",

View File

@@ -39,15 +39,13 @@ feature 'Admin budget investment milestones' do
click_link 'Create new milestone' click_link 'Create new milestone'
fill_in 'budget_investment_milestone_title', with: 'New title milestone'
fill_in 'budget_investment_milestone_description', with: 'New description milestone' fill_in 'budget_investment_milestone_description', with: 'New description milestone'
fill_in 'budget_investment_milestone_publication_date', with: Time.zone.today.to_date fill_in 'budget_investment_milestone_publication_date', with: Time.zone.today
click_button 'Create milestone' click_button 'Create milestone'
expect(page).to have_content 'New title milestone'
expect(page).to have_content 'New description milestone' expect(page).to have_content 'New description milestone'
expect(page).to have_content Time.zone.today.to_date expect(page).to have_content Time.zone.today
end end
scenario "Show validation errors on milestone form" do scenario "Show validation errors on milestone form" do
@@ -60,7 +58,7 @@ feature 'Admin budget investment milestones' do
click_button 'Create milestone' click_button 'Create milestone'
within "#new_budget_investment_milestone" do within "#new_budget_investment_milestone" do
expect(page).to have_content "can't be blank", count: 2 expect(page).to have_content "can't be blank", count: 1
expect(page).to have_content 'New description milestone' expect(page).to have_content 'New description milestone'
end end
end end
@@ -79,14 +77,12 @@ 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_title', with: 'Changed title'
fill_in 'budget_investment_milestone_description', with: 'Changed description' fill_in 'budget_investment_milestone_description', with: 'Changed description'
fill_in 'budget_investment_milestone_publication_date', with: Time.zone.today.to_date fill_in 'budget_investment_milestone_publication_date', with: Time.zone.today.to_date
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'
click_button 'Update milestone' click_button 'Update milestone'
expect(page).to have_content 'Changed title'
expect(page).to have_content 'Changed description' expect(page).to have_content 'Changed description'
expect(page).to have_content Time.zone.today.to_date expect(page).to have_content Time.zone.today.to_date
expect(page).to have_link 'Show image' expect(page).to have_link 'Show image'

View File

@@ -515,7 +515,6 @@ feature 'Budget Investments' do
find("#tab-milestones-label").trigger('click') find("#tab-milestones-label").trigger('click')
within("#tab-milestones") do within("#tab-milestones") do
expect(page).to have_content(milestone.title)
expect(page).to have_content(milestone.description) expect(page).to have_content(milestone.description)
expect(page).to have_content(Time.zone.today.to_date) expect(page).to have_content(Time.zone.today.to_date)
expect(page.find("#image_#{milestone.id}")['alt']).to have_content image.title expect(page.find("#image_#{milestone.id}")['alt']).to have_content image.title

View File

@@ -14,6 +14,11 @@ describe "Budget::Investment::Milestone" do
expect(milestone).to_not be_valid expect(milestone).to_not be_valid
end end
it "Should not be valid without a description" do
milestone.description = nil
expect(milestone).to_not be_valid
end
it "Should not be valid without an investment" do it "Should not be valid without an investment" do
milestone.investment_id = nil milestone.investment_id = nil
expect(milestone).to_not be_valid expect(milestone).to_not be_valid