Project

General

Profile

Feature #1459 » 0001-Allow-non-working-dates-such-as-holidays-to-be-regis.patch

Go MAEDA, 2026-10-08 10:29

View differences:

app/assets/stylesheets/application.css
input#content_comments {inline-size: 99%}
span.pagination {margin-inline-start: 3px; color: var(--oc-gray-6); display: block;}
.non-working-dates-year {display: block; margin-block-end: 1em;}
.non-working-dates-year span.pagination {display: inline-block;}
.non-working-dates-year .pagination ul.pages li {margin-block-end: 0;}
.pagination ul.pages {
margin-block: 0;
margin-inline: 0 5px;
app/assets/stylesheets/responsive.css
}
div.issue .next-prev-links .pagination ul.pages li.previous,
div.issue .next-prev-links .pagination ul.pages li.position,
div.issue .next-prev-links .pagination ul.pages li.next {
div.issue .next-prev-links .pagination ul.pages li.next,
.non-working-dates-year .pagination ul.pages li.previous,
.non-working-dates-year .pagination ul.pages li.next {
display: inline-block;
inline-size: auto;
overflow: visible;
app/controllers/context_menus/non_working_dates_controller.rb
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module ContextMenus
class NonWorkingDatesController < BaseController
before_action :require_admin
before_action :find_non_working_dates
def index
render_context_menu 'non_working_dates'
end
private
def find_non_working_dates
@non_working_dates = NonWorkingDate.where(id: params[:id] || params[:ids]).to_a
(render_404; return) if @non_working_dates.empty?
if @non_working_dates.size == 1
@non_working_date = @non_working_dates.first
end
end
end
end
app/controllers/non_working_dates_controller.rb
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class NonWorkingDatesController < ApplicationController
layout 'admin'
self.main_menu = false
menu_item :settings
before_action :require_admin
before_action :find_non_working_date, :only => [:edit, :update, :destroy]
def index
@year = params[:year].to_i if /\A\d{4}\z/.match?(params[:year].to_s)
@year ||= User.current.today.year
years = NonWorkingDate.years
@years = (years | [@year, User.current.today.year]).sort
@previous_year = @year - 1 if years.any? {|year| year < @year}
@next_year = @year + 1 if years.any? {|year| year > @year}
@non_working_dates = NonWorkingDate.in_year(@year).sorted.to_a
@non_working_date_count = NonWorkingDate.count
end
def new
@non_working_date = NonWorkingDate.new
end
def create
@non_working_date = NonWorkingDate.new
@non_working_date.safe_attributes = params[:non_working_date]
if @non_working_date.save
flash[:notice] = l(:notice_successful_create)
if params[:continue]
redirect_to new_non_working_date_path
else
redirect_to non_working_dates_path(:year => @non_working_date.date.year)
end
else
render :action => 'new'
end
end
def edit
end
def update
@non_working_date.safe_attributes = params[:non_working_date]
if @non_working_date.save
flash[:notice] = l(:notice_successful_update)
redirect_to non_working_dates_path(:year => @non_working_date.date.year)
else
render :action => 'edit'
end
end
def destroy
@non_working_date.destroy
flash[:notice] = l(:notice_successful_delete)
redirect_to non_working_dates_path(:year => @non_working_date.date.year)
end
def bulk_destroy
NonWorkingDate.where(:id => params[:ids]).delete_all
NonWorkingDate.clear_dates_cache
flash[:notice] = l(:notice_successful_delete)
redirect_back_or_default non_working_dates_path
end
private
def find_non_working_date
@non_working_date = NonWorkingDate.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
end
app/helpers/gantt_helper.rb
Period.new(
date: date,
width: zoom,
non_working: @gantt.non_working_week_days.include?(date.cwday),
non_working: @gantt.non_working_day?(date),
spans_body: spans_body,
last: date == @gantt.date_to
)
app/models/non_working_date.rb
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class NonWorkingDate < ApplicationRecord
include Redmine::SafeAttributes
class Current < ActiveSupport::CurrentAttributes
attribute :sorted_dates, :dates
end
after_save {self.class.clear_dates_cache}
after_destroy {self.class.clear_dates_cache}
after_rollback {self.class.clear_dates_cache}
validates_presence_of :date
validates_uniqueness_of :date
validates :date, :date => true
validates_length_of :name, :maximum => 255
scope :sorted, lambda {order(:date)}
scope :in_year, lambda {|year| where(:date => Date.new(year, 1, 1)..Date.new(year, 12, 31))}
safe_attributes 'date', 'name'
# Returns the registered dates as a sorted Array.
# The result is cached for the duration of the current request.
def self.sorted_dates
Current.sorted_dates ||= order(:date).pluck(:date)
end
# Returns the registered dates as a Set.
# The result is cached for the duration of the current request.
def self.dates
Current.dates ||= sorted_dates.to_set
end
def self.clear_dates_cache
Current.reset
end
# Returns the years that have at least one non-working date
def self.years
pluck(:date).map(&:year).uniq.sort
end
end
app/views/context_menus/non_working_dates.html.erb
<ul>
<% if @non_working_date %>
<li>
<%= context_menu_link sprite_icon('edit', l(:button_edit)), edit_non_working_date_path(@non_working_date), class: 'icon icon-edit' %>
</li>
<% end %>
<li>
<%= context_menu_link sprite_icon('del', l(:button_delete)),
{controller: 'non_working_dates', action: 'bulk_destroy', ids: @non_working_dates.map(&:id), back_url: @back},
method: :delete, data: {confirm: l(:text_are_you_sure)}, class: 'icon icon-del' %>
</li>
</ul>
app/views/non_working_dates/_form.html.erb
<%= error_messages_for 'non_working_date' %>
<div class="box tabular">
<p><%= f.date_field :date, :size => 10, :required => true %><%= calendar_for('non_working_date_date') %></p>
<p><%= f.text_field :name, :size => 40 %></p>
</div>
app/views/non_working_dates/edit.html.erb
<%= title [l(:label_non_working_date_plural), non_working_dates_path(:year => @non_working_date.date_was.year)], format_date(@non_working_date.date_was) %>
<%= labelled_form_for @non_working_date do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_save) %>
<% end %>
app/views/non_working_dates/index.html.erb
<div class="contextual">
<%= link_to(sprite_icon('add', l(:label_non_working_date_new)), new_non_working_date_path, :class => 'icon icon-add') %>
</div>
<h2><%= l(:label_non_working_date_plural) %></h2>
<%= form_tag(non_working_dates_path, :method => :get, :class => 'non-working-dates-year') do %>
<%= label_tag 'year', l(:label_year) %>
<%= select_tag 'year', options_for_select(@years, @year), :onchange => 'this.form.submit();' %>
<span class="pagination">
<ul class="pages">
<li class="previous<%= ' page' if @previous_year %>">
<%= link_to_if(@previous_year, "\xc2\xab #{l(:label_previous)}", non_working_dates_path(:year => @previous_year), :title => @previous_year, :accesskey => accesskey(:previous)) {|text| content_tag('span', text)} %>
</li><li class="next<%= ' page' if @next_year %>">
<%= link_to_if(@next_year, "#{l(:label_next)} \xc2\xbb", non_working_dates_path(:year => @next_year), :title => @next_year, :accesskey => accesskey(:next)) {|text| content_tag('span', text)} %>
</li>
</ul>
</span>
<% end %>
<% if @non_working_dates.any? %>
<%= form_tag({}, :data => {:cm_url => non_working_dates_context_menu_path}) do -%>
<%= hidden_field_tag 'back_url', url_for(:params => request.query_parameters), :id => nil %>
<table class="list odd-even non_working_dates">
<thead><tr>
<th class="checkbox hide-when-print">
<%= check_box_tag 'check_all', '', false, :class => 'toggle-selection',
:title => "#{l(:button_check_all)} / #{l(:button_uncheck_all)}" %>
</th>
<th><%= l(:field_date) %></th>
<th><%= l(:field_name) %></th>
<th></th>
</tr></thead>
<tbody>
<% @non_working_dates.each do |non_working_date| %>
<tr id="non-working-date-<%= non_working_date.id %>" class="hascontextmenu <%= cycle("odd", "even") %>">
<td class="checkbox hide-when-print"><%= check_box_tag("ids[]", non_working_date.id, false, :id => nil) %></td>
<td class="date"><%= link_to "#{format_date(non_working_date.date)} (#{abbr_day_name(non_working_date.date.cwday)})", edit_non_working_date_path(non_working_date) %></td>
<td class="name"><%= non_working_date.name %></td>
<td class="buttons">
<%= link_to_context_menu %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end -%>
<span class="pagination"><span class="items">(<%= @non_working_dates.size %>/<%= @non_working_date_count %>)</span></span>
<%= context_menu %>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>
<% html_title(l(:label_non_working_date_plural)) -%>
app/views/non_working_dates/new.html.erb
<%= title [l(:label_non_working_date_plural), non_working_dates_path], l(:label_non_working_date_new) %>
<%= labelled_form_for @non_working_date do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
<% end %>
app/views/settings/_issues.html.erb
<p><%= setting_select :issue_done_ratio_interval, [5, 10].collect {|i| ["#{i} %", i]} %></p>
<p><%= setting_multiselect :non_working_week_days, (1..7).map {|d| [day_name(d), d.to_s]}, :inline => true %></p>
<p>
<%= setting_multiselect :non_working_week_days, (1..7).map {|d| [day_name(d), d.to_s]}, :inline => true %>
<em class="info"><%= t(:text_non_working_dates_html, non_working_dates_path: non_working_dates_path) %></em>
</p>
<p><%= setting_text_field :issues_export_limit, :size => 6 %></p>
config/locales/en.yml
mail_destroy_project_with_subprojects_successful: Project %{value} and its subprojects were deleted successfully.
field_date: Date
field_name: Name
field_description: Description
field_summary: Summary
......
label_custom_field_new: New custom field
label_enumerations: Enumerations
label_enumeration_new: New value
label_non_working_date_plural: Non-working dates
label_non_working_date_new: New non-working date
label_information: Information
label_information_plural: Information
label_register: Register
......
description_wiki_subpages_reassign: Choose new parent page
text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'
text_login_required_html: When not requiring authentication, public projects and their contents are openly available on the network. You can <a href="%{anonymous_role_path}">edit the applicable permissions</a>.
text_non_working_dates_html: 'You can add non-working dates such as holidays: <a href="%{non_working_dates_path}">Manage non-working dates</a>'
label_login_required_yes: "Yes"
label_login_required_no: "No, allow anonymous access to public projects"
text_project_is_public_non_member: Public projects and their contents are available to all logged-in users.
config/routes.rb
end
resources :enumerations, :except => :show
match 'enumerations/:type', :to => 'enumerations#index', :via => :get
match '/non_working_dates/context_menu', :to => 'context_menus/non_working_dates#index', :as => :non_working_dates_context_menu, :via => [:get, :post]
resources :non_working_dates, :except => :show do
collection do
delete 'bulk_destroy'
end
end
get '(projects/:id)/search', :controller => 'search', :action => 'index', :as => 'search'
db/migrate/20261005121927_create_non_working_dates.rb
class CreateNonWorkingDates < ActiveRecord::Migration[8.1]
def change
create_table :non_working_dates do |t|
t.date :date, :null => false
t.string :name
end
add_index :non_working_dates, :date, :unique => true
end
end
lib/redmine/helpers/calendar.rb
def day_css_classes(day)
css = day.month==month ? +'this-month' : +'other-month'
css << " today" if User.current.today == day
css << " nwday" if non_working_week_days.include?(day.cwday)
css << " nwday" if non_working_day?(day)
css
end
lib/redmine/helpers/gantt.rb
height = g_height + header_height - 1
(@date_from..date_to).each do |g_date|
width = zoom
gc.fill(non_working_week_days.include?(g_date.cwday) ? '#eee' : 'white')
gc.fill(non_working_day?(g_date) ? '#eee' : 'white')
gc.stroke('#ddd')
gc.strokewidth(1)
gc.draw('rectangle %d,%d %d,%d' % [
......
width = zoom
pdf.SetY(y_start + header_height * 2)
pdf.SetX(left)
pdf.SetTextColor(non_working_week_days.include?(g_date.cwday) ? 150 : 0)
pdf.SetTextColor(non_working_day?(g_date) ? 150 : 0)
pdf.RDMCell(width, height, day_num.day.to_s, "LTR", 0, "C")
left = left + width
day_num = day_num + 1
......
width = zoom
pdf.SetY(y_start + header_height * (show_day_num ? 3 : 2))
pdf.SetX(left)
pdf.SetTextColor(non_working_week_days.include?(g_date.cwday) ? 150 : 0)
pdf.SetTextColor(non_working_day?(g_date) ? 150 : 0)
pdf.RDMCell(width, height, day_name(g_date.cwday).first, "LTR", 0, "C")
left = left + width
end
lib/redmine/utils/date_calculation.rb
result += 1
end
end
result
result - non_working_dates_count(from, to)
else
0
end
......
# Adds working days to the given date
def add_working_days(date, working_days)
if working_days > 0
weeks = working_days / (7 - non_working_week_days.size)
result = weeks * 7
days_left = working_days - weeks * (7 - non_working_week_days.size)
cwday = date.cwday
while days_left > 0
cwday += 1
unless non_working_week_days.include?(((cwday - 1) % 7) + 1)
days_left -= 1
end
result += 1
result = add_working_week_days(date, working_days)
# Each registered non working date that was passed over
# pushes the result back by one more working day
from = date
while (skipped = non_working_dates_count(from + 1, result + 1)) > 0
from = result
result = add_working_week_days(result, skipped)
end
next_working_date(date + result)
next_working_date(result)
else
date
end
......
# Returns the date of the first day on or after the given date that is a working day
def next_working_date(date)
date += 1 while non_working_day?(date)
date
end
# Returns true if the given date is a non working day
def non_working_day?(date)
non_working_week_days.include?(date.cwday) || NonWorkingDate.dates.include?(date)
end
# Adds working days to the given date,
# taking only non working week days into account
def add_working_week_days(date, working_days)
weeks = working_days / (7 - non_working_week_days.size)
result = weeks * 7
days_left = working_days - weeks * (7 - non_working_week_days.size)
cwday = date.cwday
days = 0
days += 1 while non_working_week_days.include?(((cwday + days - 1) % 7) + 1)
date + days
while days_left > 0
cwday += 1
unless non_working_week_days.include?(((cwday - 1) % 7) + 1)
days_left -= 1
end
result += 1
end
date + result
end
# Returns the number of registered non working dates that are on or after from
# and before to, and that do not fall on a non working week day
def non_working_dates_count(from, to)
dates = NonWorkingDate.sorted_dates
first = dates.bsearch_index {|date| date >= from} || dates.size
last = dates.bsearch_index {|date| date >= to} || dates.size
dates[first...last].count {|date| non_working_week_days.exclude?(date.cwday)}
end
# Returns the index of non working week days (1=monday, 7=sunday)
test/functional/calendars_controller_test.rb
assert_select 'li.nwday', :text => /^10/
end
end
def test_show_calendar_should_mark_non_working_dates
NonWorkingDate.create!(:date => '2016-12-29')
get(
:show,
:params => {
:month => '12',
:year => '2016'
}
)
assert_response :success
assert_select 'li.nwday', 11
assert_select 'li.nwday', :text => /^29/
end
end
test/functional/context_menus/non_working_dates_controller_test.rb
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative '../../test_helper'
module ContextMenus
class NonWorkingDatesControllerTest < Redmine::ControllerTest
def setup
User.current = nil
@request.session[:user_id] = 1 # admin
end
def test_context_menu_with_one_non_working_date
non_working_date = NonWorkingDate.create!(:date => '2026-06-25')
get :index, :params => {:ids => [non_working_date.id]}
assert_response :success
assert_select 'a.icon-edit[href=?]', "/non_working_dates/#{non_working_date.id}/edit"
assert_select 'a.icon-del[href$=?]', "/non_working_dates/bulk_destroy?ids%5B%5D=#{non_working_date.id}"
end
def test_context_menu_with_multiple_non_working_dates
ids = %w(2026-08-13 2026-08-14).map {|date| NonWorkingDate.create!(:date => date).id}
get :index, :params => {:ids => ids}
assert_response :success
assert_select 'a.icon-edit', 0
assert_select 'a.icon-del[href$=?]', "/non_working_dates/bulk_destroy?ids%5B%5D=#{ids[0]}&ids%5B%5D=#{ids[1]}"
end
def test_context_menu_by_non_admin_should_respond_with_403
@request.session[:user_id] = 2
get :index, :params => {:ids => [NonWorkingDate.create!(:date => '2026-06-25').id]}
assert_response :forbidden
end
end
end
test/functional/gantts_controller_test.rb
assert_select 'a', :text => /Private child of eCookbook/, :count => 0
end
def test_gantt_should_mark_non_working_dates
NonWorkingDate.create!(:date => '2016-12-29')
get :show, :params => {:year => '2016', :month => '12', :months => '1', :zoom => '4'}
assert_response :success
# 9 week-end days and 1 non-working date, in both the day number and the day name rows
assert_select 'div.gantt-period-non-working', 20
assert_select 'div.gantt-period-non-working', :text => '29'
end
def test_gantt_should_display_relations
IssueRelation.delete_all
issue1 = Issue.generate!(:start_date => 1.day.from_now.to_date, :due_date => 3.day.from_now.to_date)
test/functional/non_working_dates_controller_test.rb
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative '../test_helper'
class NonWorkingDatesControllerTest < Redmine::ControllerTest
def setup
User.current = nil
@request.session[:user_id] = 1 # admin
end
def test_index_should_list_non_working_dates_of_the_current_year_by_default
year = User.find(1).today.year
NonWorkingDate.create!(:date => Date.new(year, 6, 25), :name => 'Company Foundation Day')
NonWorkingDate.create!(:date => Date.new(year - 1, 8, 13), :name => 'Summer Shutdown')
get :index
assert_response :success
assert_select 'table.non_working_dates tbody tr', 1
assert_select 'table.non_working_dates td.name', :text => 'Company Foundation Day'
assert_select 'form[data-cm-url=?] input[name=?]', '/non_working_dates/context_menu', 'ids[]', 1
assert_select 'span.pagination span.items', :text => '(1/2)'
assert_select 'form.non-working-dates-year' do
assert_select 'select[name=year] option', 2
assert_select 'select[name=year] option[selected=selected]', :text => year.to_s
assert_select 'li.previous a[href=?]', "/non_working_dates?year=#{year - 1}"
assert_select 'li.next span', :text => /Next/
assert_select 'li.next a', 0
end
end
def test_index_with_year
NonWorkingDate.create!(:date => '2020-12-30', :name => 'Year-end Shutdown')
NonWorkingDate.create!(:date => '2021-12-30')
get :index, :params => {:year => '2020'}
assert_response :success
assert_select 'table.non_working_dates tbody tr', 1
assert_select 'table.non_working_dates td.name', :text => 'Year-end Shutdown'
end
def test_index_by_non_admin_should_respond_with_403
@request.session[:user_id] = 2
get :index
assert_response :forbidden
end
def test_create
assert_difference 'NonWorkingDate.count' do
post :create, :params => {:non_working_date => {:date => '2026-06-25', :name => 'Company Foundation Day'}}
end
assert_redirected_to '/non_working_dates?year=2026'
non_working_date = NonWorkingDate.order(:id).last
assert_equal Date.new(2026, 6, 25), non_working_date.date
assert_equal 'Company Foundation Day', non_working_date.name
end
def test_create_and_continue
assert_difference 'NonWorkingDate.count' do
post :create, :params => {:non_working_date => {:date => '2026-06-25'}, :continue => 'Create and continue'}
end
assert_redirected_to '/non_working_dates/new'
end
def test_create_with_duplicate_date_should_fail
NonWorkingDate.create!(:date => '2026-06-25')
assert_no_difference 'NonWorkingDate.count' do
post :create, :params => {:non_working_date => {:date => '2026-06-25'}}
end
assert_response :success
assert_select_error /Date has already been taken/
end
def test_update
non_working_date = NonWorkingDate.create!(:date => '2026-08-13', :name => 'Summer Shutdown')
put :update, :params => {:id => non_working_date.id, :non_working_date => {:date => '2027-08-12', :name => 'Summer Holidays'}}
assert_redirected_to '/non_working_dates?year=2027'
non_working_date.reload
assert_equal Date.new(2027, 8, 12), non_working_date.date
assert_equal 'Summer Holidays', non_working_date.name
end
def test_destroy
non_working_date = NonWorkingDate.create!(:date => '2026-06-25')
assert_difference 'NonWorkingDate.count', -1 do
delete :destroy, :params => {:id => non_working_date.id}
end
assert_redirected_to '/non_working_dates?year=2026'
end
def test_bulk_destroy
first, second, third = %w(2026-08-12 2026-08-13 2026-08-14).map {|date| NonWorkingDate.create!(:date => date)}
assert_difference 'NonWorkingDate.count', -2 do
delete :bulk_destroy, :params => {:ids => [first.id, third.id], :back_url => '/non_working_dates?year=2026'}
end
assert_redirected_to '/non_working_dates?year=2026'
assert_equal [second], NonWorkingDate.all.to_a
end
end
test/helpers/gantt_helper_test.rb
months: 1, zoom: 3, number_of_rows: 0, non_working_week_days: [6, 7])
gantt = stub(
date_from: date_from, date_to: date_to, months: months, zoom: zoom,
number_of_rows: number_of_rows, non_working_week_days: non_working_week_days
number_of_rows: number_of_rows
)
gantt.define_singleton_method(:non_working_day?) {|date| non_working_week_days.include?(date.cwday)}
GanttHelper::ChartLayout.new(gantt)
end
end
test/unit/issue_test.rb
end
end
def test_rescheduling_an_issue_should_skip_non_working_dates
NonWorkingDate.create!(:date => '2012-10-18')
NonWorkingDate.create!(:date => '2012-10-22')
with_settings :non_working_week_days => %w(6 7) do
issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
IssueRelation.create!(:issue_from => issue1, :issue_to => issue2,
:relation_type => IssueRelation::TYPE_PRECEDES)
issue2.reload
assert_equal Date.parse('2012-10-19'), issue2.start_date
assert_equal Date.parse('2012-10-24'), issue2.due_date
end
end
def test_rescheduling_an_issue_to_an_earlier_due_date_should_reschedule_following_issue
issue1 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
issue2 = Issue.generate!(:start_date => '2012-10-15', :due_date => '2012-10-17')
test/unit/lib/redmine/utils/date_calculation_test.rb
end
end
def test_working_days_with_non_working_dates
NonWorkingDate.create!(:date => '2012-10-10')
# Registered on a non-working week day, should not be counted twice
NonWorkingDate.create!(:date => '2012-10-13')
with_settings :non_working_week_days => %w(6 7) do
assert_working_days 13, '2012-10-09', '2012-10-27'
assert_working_days 1, '2012-10-09', '2012-10-11'
assert_working_days 0, '2012-10-10', '2012-10-11'
assert_working_days 3, '2012-10-11', '2012-10-16'
end
end
def test_add_working_days_with_non_working_dates
NonWorkingDate.create!(:date => '2012-10-11')
NonWorkingDate.create!(:date => '2012-10-15')
with_settings :non_working_week_days => %w(6 7) do
assert_add_working_days '2012-10-10', '2012-10-10', 0
assert_add_working_days '2012-10-12', '2012-10-10', 1
assert_add_working_days '2012-10-16', '2012-10-10', 2
assert_add_working_days '2012-10-17', '2012-10-10', 3
# From a non-working date
assert_add_working_days '2012-10-16', '2012-10-13', 1
end
end
def assert_working_days(expected_days, from, to)
assert_equal expected_days, working_days(from.to_date, to.to_date)
end
test/unit/non_working_date_test.rb
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require_relative '../test_helper'
class NonWorkingDateTest < ActiveSupport::TestCase
def test_dates_should_be_cached_and_refreshed_on_change
non_working_date = NonWorkingDate.create!(:date => '2026-08-13')
assert_equal [Date.new(2026, 8, 13)], NonWorkingDate.sorted_dates
assert_no_queries {NonWorkingDate.sorted_dates}
non_working_date.update!(:date => '2026-08-14')
assert_equal [Date.new(2026, 8, 14)], NonWorkingDate.sorted_dates
non_working_date.destroy
assert_empty NonWorkingDate.sorted_dates
end
end
(7-7/8)