Project

General

Profile

Feature #15180 » 0001-Add-a-start-date-to-versions.patch

Patch against trunk @ r21131 - Mischa The Evil, 2021-08-13 23:04

View differences:

app/models/version.rb
validates_uniqueness_of :name, :scope => [:project_id], :case_sensitive => true
validates_length_of :name, :maximum => 60
validates_length_of :description, :wiki_page_title, :maximum => 255
validates :effective_date, :date => true
validates :start_date, :effective_date, :date => true
validates_inclusion_of :status, :in => VERSION_STATUSES
validates_inclusion_of :sharing, :in => VERSION_SHARINGS
......
safe_attributes 'name',
'description',
'start_date',
'effective_date',
'due_date',
'wiki_page_title',
......
base_reload(*args)
end
# Returns the start_date of a given version from the database
def self.persistent_start_date(version)
Version.visible.where(id: version.id).pluck(:start_date)
end
def start_date
@start_date ||= fixed_issues.minimum('start_date')
@start_date = (read_attribute('start_date') || fixed_issues.minimum('start_date'))
end
def due_date
app/views/projects/settings/_versions.html.erb
<thead><tr>
<th><%= l(:label_version) %></th>
<th><%= l(:field_default_version) %></th>
<th><%= l(:field_start_date) %></th>
<th><%= l(:field_effective_date) %></th>
<th><%= l(:field_description) %></th>
<th><%= l(:field_status) %></th>
......
<tr class="version <%=h version.status %> <%= 'shared' if version.project != @project %>">
<td class="name <%= 'icon icon-shared' if version.project != @project %>"><%= link_to_version version %></td>
<td class="tick"><%= checked_image(version.id == @project.default_version_id) %></td>
<td class="date"><%= format_date(version.effective_date) %></td>
<td class="start_date"><%= format_date(version.start_date) %></td>
<td class="due_date"><%= format_date(version.effective_date) %></td>
<td class="description"><%= version.description %></td>
<td class="status"><%= l("version_status_#{version.status}") %></td>
<td class="sharing"><%=h format_version_sharing(version.sharing) %></td>
app/views/versions/_form.html.erb
<p><%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %></p>
<% end %>
<p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p>
<p>
<%= f.date_field :start_date, :size => 10,
:value => Version.persistent_start_date(@version) %>
<%= calendar_for('version_start_date') %>
</p>
<p><%= f.date_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
<p><%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %></p>
<% if @version.new_record? %>
app/views/versions/_overview.html.erb
<div class="version-overview">
<% if version.completed? %>
<p><%= format_date(version.effective_date) %></p>
<% elsif version.effective_date %>
<p><strong><%= due_date_distance_in_words(version.effective_date) %></strong> (<%= format_date(version.effective_date) %>)</p>
<p>
<%= "#{l(:field_start_date)}: #{format_date(version.start_date)}" if version.start_date %>
<% if version.start_date && version.due_date %>
&#8211;
<% end %>
<%= "#{l(:field_due_date)}: #{format_date(version.due_date)}" if version.due_date %>
<% if version.effective_date && !version.completed? %>
<strong><%= "(#{due_date_distance_in_words(version.effective_date)})" %></strong>
<% end %>
</p>
<p><%=h version.description %></p>
<% if version.custom_field_values.any? %>
app/views/versions/index.api.rsb
api.name version.name
api.description version.description
api.status version.status
api.start_date version.start_date
api.due_date version.effective_date
api.sharing version.sharing
api.wiki_page_title version.wiki_page_title
app/views/versions/show.api.rsb
api.name @version.name
api.description @version.description
api.status @version.status
api.start_date @version.start_date
api.due_date @version.effective_date
api.sharing @version.sharing
api.wiki_page_title @version.wiki_page_title
db/migrate/20210806100000_add_start_date_to_versions.rb
class AddStartDateToVersions < ActiveRecord::Migration[5.2]
def change
add_column :versions, :start_date, :date, :after => :description
end
end
test/functional/versions_controller_test.rb
def test_post_update
@request.session[:user_id] = 2
today = Date.today
put :update, :params => {
:id => 2,
:version => {
:name => 'New version name',
:effective_date => Date.today.strftime("%Y-%m-%d")
:start_date => today.yesterday.strftime("%Y-%m-%d"),
:effective_date => today.strftime("%Y-%m-%d")
}
}
assert_redirected_to :controller => 'projects', :action => 'settings',
:tab => 'versions', :id => 'ecookbook'
version = Version.find(2)
assert_equal 'New version name', version.name
assert_equal Date.today, version.effective_date
assert_equal today.yesterday, version.start_date
assert_equal today, version.effective_date
end
def test_post_update_with_validation_failure
test/unit/version_test.rb
assert_nil project.reload.default_version
end
def test_invalid_start_date_validation
v = Version.new(:project => Project.find(1), :name => '1.1',
:start_date => '99999-01-01')
assert !v.valid?
v.start_date = '2012-11-33'
assert !v.valid?
v.start_date = '2012-31-11'
assert !v.valid?
v.start_date = '-2012-31-11'
assert !v.valid?
v.start_date = 'ABC'
assert !v.valid?
assert_include I18n.translate('activerecord.errors.messages.not_a_date'),
v.errors[:start_date]
end
def test_invalid_effective_date_validation
v = Version.new(:project => Project.find(1), :name => '1.1',
:effective_date => '99999-01-01')
......
v.errors[:effective_date]
end
def test_start_date_with_no_value_saved_should_be_the_date_of_the_earliest_issue
project = Project.find(1)
Issue.generate!(:project => project, :subject => 'not assigned', :start_date => '2021-01-01')
v = Version.create!(:project => project, :name => 'Progress')
add_issue(v, :estimated_hours => 10, :start_date => '2021-03-01')
add_issue(v, :estimated_hours => 10, :start_date => '2021-02-01')
assert_equal '2021-02-01', v.start_date.to_s
end
def test_start_date_with_a_value_saved_should_be_the_value
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress', :start_date => '2021-01-05')
add_issue(v, :estimated_hours => 10, :start_date => '2020-03-01')
assert_equal '2021-01-05', v.start_date.to_s
end
def test_progress_should_be_0_with_no_assigned_issues
project = Project.find(1)
v = Version.create!(:project => project, :name => 'Progress')
(3-3/3)