Patch #1650 » timelogging-r2641.patch
| app/controllers/application.rb (working copy) | ||
|---|---|---|
|
def filename_for_content_disposition(name)
|
||
|
request.env['HTTP_USER_AGENT'] =~ %r{MSIE} ? ERB::Util.url_encode(name) : name
|
||
|
end
|
||
|
def url_path(url_parameters)
|
||
|
rs = ::ActionController::Routing::Routes
|
||
|
rs.generate url_parameters
|
||
|
end
|
||
|
end
|
||
| app/controllers/issues_controller.rb (working copy) | ||
|---|---|---|
|
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
|
||
|
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
|
||
|
@priorities = Enumeration.priorities
|
||
|
@time_entry = TimeEntry.new
|
||
|
@time_entry = @issue.time_entry_in_progress(User.current) || TimeEntry.new
|
||
|
respond_to do |format|
|
||
|
format.html { render :template => 'issues/show.rhtml' }
|
||
|
format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
|
||
| ... | ... | |
|
end
|
||
|
if request.post?
|
||
|
@time_entry = TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||
|
@time_entry = TimeEntry.find_by_id(params[:time_entry][:id]) if params[:time_entry]
|
||
|
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue,
|
||
|
:user => User.current, :spent_on => Date.today)
|
||
|
@time_entry.attributes = params[:time_entry]
|
||
|
attachments = attach_files(@issue, params[:attachments])
|
||
|
attachments.each {|a| journal.details << JournalDetail.new(:property => 'attachment', :prop_key => a.id, :value => a.filename)}
|
||
| app/controllers/timelog_controller.rb (working copy) | ||
|---|---|---|
|
end
|
||
|
|
||
|
def edit
|
||
|
return if redirect_if_in_progress
|
||
|
render_403 and return if @time_entry && !@time_entry.editable_by?(User.current)
|
||
|
@time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => Date.today)
|
||
|
@time_entry.attributes = params[:time_entry]
|
||
|
if !@time_entry.hours
|
||
|
if !@time_entry.start_time
|
||
|
@activate_field = 'time_entry_start_time'
|
||
|
else
|
||
|
@activate_field = 'time_entry_end_time'
|
||
|
end
|
||
|
end
|
||
|
|
||
|
url_writer = lambda do |entry|
|
||
|
"<a href = \"#{url_path(:controller => :timelog, :action => :edit,
|
||
|
:id => entry.id)}\">##{entry.issue_id}-#{entry.id}</a>"
|
||
|
end
|
||
|
if request.post? and @time_entry.save
|
||
|
flash[:notice] = l(:notice_successful_update)
|
||
|
intersecting = @time_entry.find_intersecting_entries
|
||
|
logger.debug "intersecting = #{intersecting.inspect}"
|
||
|
msg = l(:notice_successful_update)
|
||
|
if !intersecting.empty?
|
||
|
|
||
|
list = l_hours(:text_time_entry_intersecting_notice_entry) + ' ' + intersecting.
|
||
|
map { |entry| url_writer.call(entry) }.
|
||
|
to_sentence(:skip_last_comma => true, :connector => l(:text_and))
|
||
|
|
||
|
msg += ' ' + l(:text_time_entry_intersecting_notice,
|
||
|
url_writer.call(@time_entry), list)
|
||
|
end
|
||
|
flash[:notice] = msg
|
||
|
redirect_back_or_default :action => 'details', :project_id => @time_entry.project
|
||
|
return
|
||
|
end
|
||
| ... | ... | |
|
@from ||= (TimeEntry.minimum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today) - 1
|
||
|
@to ||= (TimeEntry.maximum(:spent_on, :include => :project, :conditions => Project.allowed_to_condition(User.current, :view_time_entries)) || Date.today)
|
||
|
end
|
||
|
|
||
|
def redirect_if_in_progress
|
||
|
if !@time_entry && @issue
|
||
|
in_progress_entry = @issue.time_entry_in_progress(User.current)
|
||
|
if in_progress_entry
|
||
|
#in order to avoid :id form parameter and not complicate :find_project filter
|
||
|
redirect_to(:controller => 'timelog', :action => 'edit',
|
||
|
:id => in_progress_entry)
|
||
|
return true
|
||
|
end
|
||
|
end
|
||
|
false
|
||
|
end
|
||
|
end
|
||
| app/helpers/issues_helper.rb (working copy) | ||
|---|---|---|
|
export.rewind
|
||
|
export
|
||
|
end
|
||
|
|
||
|
def spent_hours(issue)
|
||
|
return '-' if issue.time_entries.empty?
|
||
|
spent_hours = l_hours(issue.spent_hours)
|
||
|
spent_hours += " (#{l(:text_in_progress)})" if issue.time_entry_in_progress
|
||
|
link_to spent_hours, {:controller => 'timelog', :action => 'details', :project_id => issue.project, :issue_id => issue}, :class => 'icon icon-time'
|
||
|
end
|
||
|
end
|
||
| app/helpers/timelog_helper.rb (working copy) | ||
|---|---|---|
|
sum
|
||
|
end
|
||
|
|
||
|
def hours(entry)
|
||
|
return '<span class="hours hours-dec">[%s]</span>' % l(:text_in_progress) if !entry.hours
|
||
|
html_hours("%.2f" % entry.hours)
|
||
|
end
|
||
|
|
||
|
def options_for_period_select(value)
|
||
|
options_for_select([[l(:label_all_time), 'all'],
|
||
|
[l(:label_today), 'today'],
|
||
| app/models/issue.rb (working copy) | ||
|---|---|---|
|
"#{tracker} ##{id}: #{subject}"
|
||
|
end
|
||
|
|
||
|
def time_entry_in_progress(user = nil)
|
||
|
TimeEntry.find_by_issue_id(self.id,
|
||
|
:conditions => 'start_time IS NOT NULL and hours IS NULL' + (user ? " and user_id = #{user.id}" : ''))
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
# Callback on attachment deletion
|
||
| app/models/time_entry.rb (working copy) | ||
|---|---|---|
|
attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
|
||
|
acts_as_customizable
|
||
|
acts_as_event :title => Proc.new {|o| "#{o.user}: #{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
|
||
|
:url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}},
|
||
|
title_proc = Proc.new do |entry|
|
||
|
hours = entry.hours ? l_hours(entry.hours) : "[#{l(:text_in_progress)}]"
|
||
|
"#{entry.user}: #{hours} (#{(entry.issue || entry.project).event_title})"
|
||
|
end
|
||
|
|
||
|
acts_as_event :title => title_proc,
|
||
|
:url => Proc.new {|entry| {:controller => 'timelog', :action => 'details', :project_id => entry.project}},
|
||
|
:author => :user,
|
||
|
:description => :comments
|
||
|
|
||
|
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
|
||
|
validates_presence_of :user_id, :activity_id, :project_id, :spent_on
|
||
|
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
||
|
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
||
| ... | ... | |
|
|
||
|
def validate
|
||
|
errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
|
||
|
|
||
|
if !start_time && !hours
|
||
|
#rather verbose, but l() always translate to English here for some reason
|
||
|
errors.add :hours, ll(User.current.language,
|
||
|
:activerecord_error_field_must_be_set_if_other_is_not,
|
||
|
ll(User.current.language, :field_start_time))
|
||
|
errors.add :start_time, ll(User.current.language,
|
||
|
:activerecord_error_field_must_be_set_if_other_is_not,
|
||
|
ll(User.current.language, :field_hours))
|
||
|
end
|
||
|
errors.add :project_id, :invalid if project.nil?
|
||
|
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project)
|
||
|
end
|
||
| ... | ... | |
|
yield
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def before_save
|
||
|
if !hours && start_time && end_time
|
||
|
self.hours = (end_time - start_time) / 3600
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def find_intersecting_entries
|
||
|
params = {:start_time => start_time, :end_time => end_time, :id => id}
|
||
|
|
||
|
self.class.find_all_by_user_id(user_id, :conditions =>
|
||
|
["(" +
|
||
|
#this entry's start time or end time is between other's start_time and end_time
|
||
|
"start_time < :start_time and :start_time < end_time OR " +
|
||
|
"start_time < :end_time and :end_time < end_time OR " +
|
||
|
#other's entry's start time or end time is between this entry's start_time and end_time
|
||
|
"start_time > :start_time and start_time < :end_time OR " +
|
||
|
"end_time > :start_time and end_time < :end_time" +
|
||
|
")" +
|
||
|
"and id <> :id", params])
|
||
|
end
|
||
|
end
|
||
| app/views/issues/_edit.rhtml (working copy) | ||
|---|---|---|
|
<% content_for :header_tags do %>
|
||
|
<%= javascript_include_tag 'time' %>
|
||
|
<% end %>
|
||
|
<% labelled_tabular_form_for :issue, @issue,
|
||
|
:url => {:action => 'edit', :id => @issue},
|
||
|
:html => {:id => 'issue-form',
|
||
| ... | ... | |
|
<% if authorize_for('timelog', 'edit') %>
|
||
|
<fieldset class="tabular"><legend><%= l(:button_log_time) %></legend>
|
||
|
<% fields_for :time_entry, @time_entry, { :builder => TabularFormBuilder, :lang => current_language} do |time_entry| %>
|
||
|
<%= time_entry.hidden_field :id %>
|
||
|
<div class="splitcontentleft">
|
||
|
<p><%= time_entry.text_field :hours, :size => 6, :label => :label_spent_time %> <%= l(:field_hours) %></p>
|
||
|
<p><%= time_entry.time_field :start_time %></p>
|
||
|
</div>
|
||
|
<div class="splitcontentright">
|
||
|
<p><%= time_entry.select :activity_id, activity_collection_for_select_options %></p>
|
||
|
<p><%= time_entry.time_field :end_time %></p>
|
||
|
</div>
|
||
|
<p><%= time_entry.text_field :comments, :size => 60 %></p>
|
||
|
<% @time_entry.custom_field_values.each do |value| %>
|
||
| app/views/issues/show.rhtml (working copy) | ||
|---|---|---|
|
<td class="category"><b><%=l(:field_category)%>:</b></td><td><%=h @issue.category ? @issue.category.name : "-" %></td>
|
||
|
<% if User.current.allowed_to?(:view_time_entries, @project) %>
|
||
|
<td class="spent-time"><b><%=l(:label_spent_time)%>:</b></td>
|
||
|
<td class="spent-hours"><%= @issue.spent_hours > 0 ? (link_to l_hours(@issue.spent_hours), {:controller => 'timelog', :action => 'details', :project_id => @project, :issue_id => @issue}) : "-" %></td>
|
||
|
<td><%= spent_hours(@issue) %></td>
|
||
|
<% end %>
|
||
|
</tr>
|
||
|
<tr>
|
||
| app/views/timelog/_list.rhtml (working copy) | ||
|---|---|---|
|
<thead>
|
||
|
<tr>
|
||
|
<%= sort_header_tag('spent_on', :caption => l(:label_date), :default_order => 'desc') %>
|
||
|
<%= sort_header_tag('start_time', :caption => l(:field_start_time), :default_order => 'desc') %>
|
||
|
<%= sort_header_tag('end_time', :caption => l(:field_end_time), :default_order => 'desc') %>
|
||
|
<%= sort_header_tag('hours', :caption => l(:field_hours)) %>
|
||
|
<%= sort_header_tag('user', :caption => l(:label_member)) %>
|
||
|
<%= sort_header_tag('activity', :caption => l(:label_activity)) %>
|
||
|
<%= sort_header_tag('project', :caption => l(:label_project)) %>
|
||
|
<%= sort_header_tag('issue', :caption => l(:label_issue), :default_order => 'desc') %>
|
||
|
<th><%= l(:field_comments) %></th>
|
||
|
<%= sort_header_tag('hours', :caption => l(:field_hours)) %>
|
||
|
<th></th>
|
||
|
</tr>
|
||
|
</thead>
|
||
| ... | ... | |
|
<% entries.each do |entry| -%>
|
||
|
<tr class="time-entry <%= cycle("odd", "even") %>">
|
||
|
<td class="spent_on"><%= format_date(entry.spent_on) %></td>
|
||
|
<td class="start_time"><%= format_time(entry.start_time) %></td>
|
||
|
<td class="end_time"><%= format_time(entry.end_time) %></td>
|
||
|
<td class="hours"><%= hours(entry) %></td>
|
||
|
<td class="user"><%=h entry.user %></td>
|
||
|
<td class="activity"><%=h entry.activity %></td>
|
||
|
<td class="project"><%=h entry.project %></td>
|
||
| ... | ... | |
|
<% end -%>
|
||
|
</td>
|
||
|
<td class="comments"><%=h entry.comments %></td>
|
||
|
<td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
|
||
|
<td align="center">
|
||
|
<% if entry.editable_by?(User.current) -%>
|
||
|
<%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry, :project_id => nil},
|
||
| app/views/timelog/edit.rhtml (working copy) | ||
|---|---|---|
|
<% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :id => @time_entry, :project_id => @time_entry.project} do |f| %>
|
||
|
<%= error_messages_for 'time_entry' %>
|
||
|
<%= back_url_hidden_field_tag %>
|
||
|
<% content_for :header_tags do %>
|
||
|
<%= javascript_include_tag 'time' %>
|
||
|
<% end %>
|
||
|
|
||
|
<% content_for :header_tags do %>
|
||
|
<script language="javascript">
|
||
|
window.onload = function() {
|
||
|
$('<%= @activate_field %>').activate();
|
||
|
};
|
||
|
</script>
|
||
|
<% end %>
|
||
|
|
||
|
<div class="box">
|
||
|
<p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
|
||
|
<p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
|
||
|
<p><%= f.text_field :hours, :size => 6, :required => true %></p>
|
||
|
<p><%= f.time_field :start_time %></p>
|
||
|
<p><%= f.time_field :end_time %></p>
|
||
|
<p><%= f.text_field :hours, :size => 6 %> <em> <%= l(:text_clear_to_recalculate_time_by_range) %></em></p>
|
||
|
<p><%= f.text_field :comments, :size => 100 %></p>
|
||
|
<p><%= f.select :activity_id, activity_collection_for_select_options, :required => true %></p>
|
||
|
<% @time_entry.custom_field_values.each do |value| %>
|
||
| db/migrate/20090330000200_add_start_and_end_time_to_time_entries.rb (revision 0) | ||
|---|---|---|
|
class AddStartAndEndTimeToTimeEntries < ActiveRecord::Migration
|
||
|
def self.up
|
||
|
add_column :time_entries, :start_time, :datetime
|
||
|
add_column :time_entries, :end_time, :datetime
|
||
|
end
|
||
|
|
||
|
def self.down
|
||
|
remove_column :time_entries, :start_time
|
||
|
remove_column :time_entries, :end_time
|
||
|
end
|
||
|
end
|
||
| db/migrate/20090330000300_allow_null_time_entry_hours.rb (revision 0) | ||
|---|---|---|
|
class AllowNullTimeEntryHours < ActiveRecord::Migration
|
||
|
def self.up
|
||
|
change_column :time_entries, :hours, :float, :null => true
|
||
|
end
|
||
|
|
||
|
def self.down
|
||
|
# not needed
|
||
|
end
|
||
|
end
|
||
| lib/tabular_form_builder.rb (working copy) | ||
|---|---|---|
|
END_SRC
|
||
|
class_eval src, __FILE__, __LINE__
|
||
|
end
|
||
|
def time_field(field)
|
||
|
value = nil
|
||
|
value = @object.send(field) if @object
|
||
|
value = value.strftime('%Y-%m-%d %H:%M') if value
|
||
|
result = text_field field, :size => 15, :value => value
|
||
|
result += (' <input type="button" onclick="maybeSetTimeNow($(\'%s\'))' +
|
||
|
'" value="' + l(:button_now) +
|
||
|
'" name="action"/>') % "#{@object_name}_#{field}"
|
||
|
result
|
||
|
end
|
||
|
|
||
|
def select(field, choices, options = {}, html_options = {})
|
||
|
label_for_field(field, options) + super
|
||
| public/javascripts/time.js (revision 0) | ||
|---|---|---|
|
//taken from XPlanner
|
||
|
var dateFormatChars = "dMyhHmsa";
|
||
|
|
||
|
function formatDate(date, format) {
|
||
|
return formatDate2(date, format, 0);
|
||
|
}
|
||
|
|
||
|
function formatDate2(date, format, offset) {
|
||
|
if (offset >= format.length) {
|
||
|
return "";
|
||
|
} else if (dateFormatChars.indexOf(format.charAt(offset)) != -1) {
|
||
|
return formatDateElement(date, format, offset);
|
||
|
} else {
|
||
|
return formatDateLiteral(date, format, offset);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function formatDateElement(date, format, offset) {
|
||
|
var end = offset;
|
||
|
var ch = format.charAt(offset);
|
||
|
while (++end < format.length && format.charAt(end) == ch);
|
||
|
var count = end - offset;
|
||
|
var value;
|
||
|
if (ch == 'd') {
|
||
|
value = padValue(count, date.getDate());
|
||
|
}
|
||
|
else if (ch == 'M') {
|
||
|
value = padValue(count, date.getMonth()+1);
|
||
|
}
|
||
|
else if (ch == 'y') {
|
||
|
value = padValue(count, date.getFullYear());
|
||
|
}
|
||
|
else if (ch == 'H') {
|
||
|
value = padValue(count, date.getHours());
|
||
|
}
|
||
|
else if (ch == 'h') {
|
||
|
value = padValue(count, date.getHours() % 12);
|
||
|
}
|
||
|
else if (ch == 'm') {
|
||
|
value = padValue(count, date.getMinutes());
|
||
|
}
|
||
|
else if (ch == 's') {
|
||
|
value = padValue(count, date.getSeconds());
|
||
|
}
|
||
|
else if (ch == 'a') {
|
||
|
value = date.getHours() > 12 ? 'PM' : 'AM';
|
||
|
}
|
||
|
return value + formatDate2(date, format, end);
|
||
|
}
|
||
|
|
||
|
function padValue(count, value) {
|
||
|
for (i = value.toString().length; i < count; i++) {
|
||
|
value = '0'+value;
|
||
|
}
|
||
|
return value;
|
||
|
}
|
||
|
|
||
|
function formatDateLiteral(date, format, offset) {
|
||
|
end = offset;
|
||
|
while (++end < format.length && dateFormatChars.indexOf(format.charAt(end)) == -1);
|
||
|
return format.substr(offset, end - offset) + formatDate2(date, format, end);
|
||
|
}
|
||
|
|
||
|
function maybeSetTimeNow(field) {
|
||
|
if (field.value == "") {
|
||
|
field.value = formatDate(new Date(), "yyyy-MM-dd HH:mm");
|
||
|
}
|
||
|
}
|
||
| test/fixtures/time_entries.yml (working copy) | ||
|---|---|---|
|
hours: 7.65
|
||
|
user_id: 1
|
||
|
tyear: 2007
|
||
|
|
||
|
|
||
|
#this is to run existing controller tests with Start/End time improvement - specific entries
|
||
|
time_entry_in_progress:
|
||
|
created_on: 2007-04-22 12:20:48 +02:00
|
||
|
tweek: 16
|
||
|
tmonth: 4
|
||
|
project_id: 1
|
||
|
comments: Time spent on a subproject (in progress)
|
||
|
updated_on: 2007-04-22 12:20:48 +02:00
|
||
|
activity_id: 10
|
||
|
spent_on: 2007-04-22
|
||
|
issue_id: 1
|
||
|
id: 5
|
||
|
user_id: 1
|
||
|
tyear: 2007
|
||
|
start_time: 2007-07-11 16:20
|
||
|
|
||
|
#same user but another issue and project, and intersects with time_entry_in_progress
|
||
|
intersecting_time_entry:
|
||
|
created_on: 2007-04-22 12:20:48 +02:00
|
||
|
tweek: 16
|
||
|
tmonth: 4
|
||
|
project_id: 2
|
||
|
comments: Time entry intersecting with time_entry_in_progress
|
||
|
updated_on: 2007-04-22 12:20:48 +02:00
|
||
|
activity_id: 10
|
||
|
spent_on: 2007-04-22
|
||
|
issue_id: 4
|
||
|
id: 6
|
||
|
user_id: 1
|
||
|
tyear: 2007
|
||
|
start_time: 2007-07-11 15:20
|
||
|
end_time: 2007-07-11 17:20
|
||
|
hours: 0 #to not break time calculation tests
|
||
|
|
||
|
#this spans several years - should intersect with time_entry_in_progress as well
|
||
|
big_intersecting_time_entry:
|
||
|
created_on: 2007-04-22 12:20:48 +02:00
|
||
|
tweek: 16
|
||
|
tmonth: 4
|
||
|
project_id: 1
|
||
|
comments: Time entry intersecting with time_entry_in_progress
|
||
|
updated_on: 2007-04-22 12:20:48 +02:00
|
||
|
activity_id: 10
|
||
|
spent_on: 2007-04-22
|
||
|
issue_id: 1
|
||
|
id: 7
|
||
|
user_id: 1
|
||
|
tyear: 2007
|
||
|
start_time: 2005-07-11 16:30
|
||
|
end_time: 2007-07-11 17:20
|
||
|
hours: 0 #to not break time calculation tests
|
||
| test/functional/issues_controller_test.rb (working copy) | ||
|---|---|---|
|
assert_not_nil assigns(:issue)
|
||
|
end
|
||
|
def test_show_in_progress
|
||
|
@request.session[:user_id] = 1
|
||
|
get :show, :id => 1
|
||
|
assert_equal time_entries(:time_entry_in_progress), assigns(:time_entry),
|
||
|
'there should be an in-progress time entry for this user'
|
||
|
end
|
||
|
|
||
|
def test_show_not_in_progress
|
||
|
@request.session[:user_id] = 2
|
||
|
get :show, :id => 1
|
||
|
assert_nil assigns(:time_entry).id, 'time entry for this user should be new'
|
||
|
end
|
||
|
|
||
|
def test_get_new
|
||
|
@request.session[:user_id] = 2
|
||
|
get :new, :project_id => 1, :tracker_id => 1
|
||
| ... | ... | |
|
issue = Issue.find(1)
|
||
|
assert_equal 1, issue.status_id
|
||
|
@request.session[:user_id] = 2
|
||
|
assert_difference('TimeEntry.count', 0) do
|
||
|
assert_difference('TimeEntry.count', 0) do #time entries count should not change because given entry is empty (hence invalid)
|
||
|
post :edit,
|
||
|
:id => 1,
|
||
|
:issue => { :status_id => 2, :assigned_to_id => 3 },
|
||
| ... | ... | |
|
assert mail.body.include?("Status changed from New to Assigned")
|
||
|
end
|
||
|
|
||
|
def test_post_edit_with_task_in_progress
|
||
|
user_id = 1
|
||
|
@request.session[:user_id] = user_id
|
||
|
issue = Issue.find(1)
|
||
|
time_entry = issue.time_entry_in_progress(User.find(user_id))
|
||
|
assert_not_nil time_entry, 'there should be time entry in progress'
|
||
|
assert_difference('TimeEntry.count', 0) do #time entries count should not change because entry in progress should be updated
|
||
|
post :edit,
|
||
|
:id => 1,
|
||
|
:issue => { },
|
||
|
:notes => 'Assigned to dlopper',
|
||
|
:time_entry => { :id => time_entry.id, :comments => 'xyz' }
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def test_post_edit_with_note_only
|
||
|
notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
|
||
|
# anonymous user
|
||
| ... | ... | |
|
|
||
|
issue = Issue.find(1)
|
||
|
|
||
|
j = issue.journals.find(:first, :order => 'id DESC')
|
||
|
assert_equal '2.5 hours added', j.notes
|
||
|
assert_equal 0, j.details.size
|
||
|
#:first doesn't work sometimes here with MySQL 5.0.51b
|
||
|
e = issue.journals.find(:all, :order => 'id DESC')[0]
|
||
|
assert_equal '2.5 hours added', e.notes
|
||
|
assert_equal 0, e.details.size
|
||
|
|
||
|
t = issue.time_entries.find(:first, :order => 'id DESC')
|
||
|
#:first doesn't work sometimes here with MySQL 5.0.51b
|
||
|
t = issue.time_entries.find(:all, :order => 'id DESC')[0]
|
||
|
assert_not_nil t
|
||
|
assert_equal 2.5, t.hours
|
||
|
assert_equal spent_hours_before + 2.5, issue.spent_hours
|
||
| test/functional/timelog_controller_test.rb (working copy) | ||
|---|---|---|
|
:content => 'Development'
|
||
|
end
|
||
|
|
||
|
def test_get_edit_in_progress_by_entry_id
|
||
|
@request.session[:user_id] = 1 #to avoid 'no permission' error
|
||
|
get :edit, :id => time_entries(:time_entry_in_progress)
|
||
|
assert_response :success
|
||
|
assert_equal 'time_entry_end_time', assigns(:activate_field)
|
||
|
end
|
||
|
|
||
|
def test_get_edit_not_in_progress
|
||
|
@request.session[:user_id] = 2 #there are no in-progress entries of this user for the issue
|
||
|
get :edit, :issue_id => 1
|
||
|
assert_response :success
|
||
|
assert_equal 'time_entry_start_time', assigns(:activate_field)
|
||
|
end
|
||
|
|
||
|
def test_get_edit_in_progress_by_issue_id
|
||
|
user_id = 1
|
||
|
@request.session[:user_id] = user_id #there is in-progress entry of this user for the issue
|
||
|
issue_id = 1
|
||
|
get :edit, :issue_id => issue_id
|
||
|
assert_redirected_to :action => "edit", :id => Issue.find(issue_id).time_entry_in_progress(User.find(user_id)).id
|
||
|
end
|
||
|
|
||
|
def test_get_edit_existing_time
|
||
|
@request.session[:user_id] = 2
|
||
|
get :edit, :id => 2, :project_id => nil
|
||
| ... | ... | |
|
post :edit, :id => 1,
|
||
|
:time_entry => {:issue_id => '2',
|
||
|
:hours => '8'}
|
||
|
assert_no_errors(assigns(:time_entry))
|
||
|
assert_redirected_to :action => 'details', :project_id => 'ecookbook'
|
||
|
entry.reload
|
||
|
|
||
| ... | ... | |
|
assert_response :success
|
||
|
assert_template 'details'
|
||
|
assert_not_nil assigns(:entries)
|
||
|
assert_equal 4, assigns(:entries).size
|
||
|
assert_equal 6, assigns(:entries).size
|
||
|
# project and subproject
|
||
|
assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
|
||
|
assert_not_nil assigns(:total_hours)
|
||
| ... | ... | |
|
assert_response :success
|
||
|
assert_template 'details'
|
||
|
assert_not_nil assigns(:entries)
|
||
|
assert_equal 3, assigns(:entries).size
|
||
|
assert_equal 5, assigns(:entries).size
|
||
|
assert_not_nil assigns(:total_hours)
|
||
|
assert_equal "12.90", "%.2f" % assigns(:total_hours)
|
||
|
assert_equal '2007-03-20'.to_date, assigns(:from)
|
||
| ... | ... | |
|
assert_response :success
|
||
|
assert_template 'details'
|
||
|
assert_not_nil assigns(:entries)
|
||
|
assert_equal 2, assigns(:entries).size
|
||
|
assert_equal 4, assigns(:entries).size
|
||
|
assert_not_nil assigns(:total_hours)
|
||
|
assert_equal 154.25, assigns(:total_hours)
|
||
|
# display all time by default
|
||
| test/test_helper.rb (working copy) | ||
|---|---|---|
|
Dir.mkdir "#{RAILS_ROOT}/tmp/test/attachments" unless File.directory?("#{RAILS_ROOT}/tmp/test/attachments")
|
||
|
Attachment.storage_path = "#{RAILS_ROOT}/tmp/test/attachments"
|
||
|
end
|
||
|
def assert_error_on(object, field)
|
||
|
object.valid?
|
||
|
assert object.errors.on(field), "expected error on #{field} attribute"
|
||
|
end
|
||
|
def assert_no_error_on(object, field)
|
||
|
object.valid?
|
||
|
assert !object.errors.on(field), "expected no error on #{field} attribute"
|
||
|
end
|
||
|
def assert_no_errors(object, options = {})
|
||
|
object.valid? if options[:validate]
|
||
|
assert_equal [], object.errors.full_messages
|
||
|
end
|
||
|
|
||
|
def with_settings(options, &block)
|
||
|
saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].dup; h}
|
||
| test/unit/issue_test.rb (working copy) | ||
|---|---|---|
|
assert_nil TimeEntry.find_by_issue_id(1)
|
||
|
end
|
||
|
|
||
|
def test_find_in_progress_success
|
||
|
assert_equal time_entries(:time_entry_in_progress),
|
||
|
issues(:issues_001).time_entry_in_progress(users(:users_001))
|
||
|
end
|
||
|
def test_find_in_progress_failure
|
||
|
assert_nil issues(:issues_001).time_entry_in_progress(users(:users_002))
|
||
|
end
|
||
|
|
||
|
def test_overdue
|
||
|
assert Issue.new(:due_date => 1.day.ago.to_date).overdue?
|
||
|
assert !Issue.new(:due_date => Date.today).overdue?
|
||
| test/unit/time_entry_test.rb (working copy) | ||
|---|---|---|
|
class TimeEntryTest < Test::Unit::TestCase
|
||
|
fixtures :issues, :projects, :users, :time_entries
|
||
|
def setup
|
||
|
User.current.language = 'en'
|
||
|
end
|
||
|
|
||
|
def test_hours_format
|
||
|
assertions = { "2" => 2.0,
|
||
|
"21.1" => 21.1,
|
||
| ... | ... | |
|
assert_equal v, t.hours, "Converting #{k} failed:"
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def test_start_time_must_be_set_if_hours_are_not_and_reverse
|
||
|
entry = TimeEntry.new
|
||
|
assert_error_on(entry, :start_time)
|
||
|
assert_error_on(entry, :hours)
|
||
|
end
|
||
|
def test_start_time_can_be_absent_if_hours_are_set_and_reverse
|
||
|
entry = TimeEntry.new :hours => 1
|
||
|
entry.valid?
|
||
|
assert_no_error_on(entry, :start_time)
|
||
|
entry = TimeEntry.new :start_time => Time.now
|
||
|
entry.valid?
|
||
|
assert_no_error_on(entry, :hours)
|
||
|
end
|
||
|
def successful_params
|
||
|
{:spent_on => '2008-07-13', :issue_id => 1, :user => users(:users_004),
|
||
|
:activity_id => Enumeration.get_values('ACTI').first}
|
||
|
end
|
||
|
|
||
|
def test_hours_not_calculated_if_set_explicitly
|
||
|
#I worked on this time to time during the day, and it was 1 hour in sum
|
||
|
entry = TimeEntry.new successful_params.merge(:hours => 1,
|
||
|
:start_time => '2008-07-13 10:56', :end_time => '2008-07-14 10:56')
|
||
|
|
||
|
entry.save!
|
||
|
assert_equal 1, entry.hours
|
||
|
end
|
||
|
{['10:56', '11:56'] => 1, ['10:56', '11:26'] => 0.5,
|
||
|
['10:56', '10:57'] => 0.0167,
|
||
|
['2008-07-13 23:50', '2008-07-14 00:20'] => 0.5}.each do |range, hours|
|
||
|
|
||
|
define_method "test_hours_calculated_#{range[0]}_to_#{range[1]}" do
|
||
|
|
||
|
#add default day if not specified
|
||
|
range = range.map {|time| time['-'] ? time : '2008-07-13 ' + time}
|
||
|
|
||
|
entry = TimeEntry.new successful_params.merge(:hours => nil,
|
||
|
:start_time => range[0], :end_time => range[1])
|
||
|
entry.save!
|
||
|
assert_in_delta hours, entry.hours, 0.0001
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def assert_intersects(source, dest)
|
||
|
intersecting = time_entries(source).find_intersecting_entries
|
||
|
|
||
|
assert !intersecting.empty?,
|
||
|
"there should be intersecting entries for #{source.inspect}"
|
||
|
|
||
|
assert intersecting.map {|e| e.id}.
|
||
|
include?(time_entries(dest).id),
|
||
|
"#{source.inspect} should intersect with #{dest.inspect}"
|
||
|
|
||
|
intersecting
|
||
|
end
|
||
|
|
||
|
def test_find_intersecting_entries_for_incomplete
|
||
|
assert_intersects(:time_entry_in_progress, :intersecting_time_entry)
|
||
|
end
|
||
|
def test_find_intersecting_entries_for_complete_doesnt_find_itself
|
||
|
intersecting = assert_intersects(:intersecting_time_entry,
|
||
|
:time_entry_in_progress)
|
||
|
assert !intersecting.map {|e| e.id}.include?(
|
||
|
time_entries(:intersecting_time_entry)), 'time entry\'s ' +
|
||
|
'intersecting entries shouldn\'t include itself'
|
||
|
end
|
||
|
def test_find_intersecting_entries_for_big
|
||
|
assert_intersects(:big_intersecting_time_entry, :time_entry_in_progress)
|
||
|
assert_intersects(:big_intersecting_time_entry, :intersecting_time_entry)
|
||
|
end
|
||
|
end
|
||
| vendor/plugins/test_utils/MIT-LICENSE (revision 0) | ||
|---|---|---|
|
Copyright (C) 2008 Texuna Technologies
|
||
|
|
||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||
|
a copy of this software and associated documentation files (the
|
||
|
"Software"), to deal in the Software without restriction, including
|
||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||
|
permit persons to whom the Software is furnished to do so, subject to
|
||
|
the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be
|
||
|
included in all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
|
||
| vendor/plugins/test_utils/tasks/test_utils.rake (revision 0) | ||
|---|---|---|
|
##
|
||
|
# based on http://nubyonrails.com/articles/foscon-and-living-dangerously-with-rake
|
||
|
# Run a single test (or group of tests started with given string) in Rails.
|
||
|
#
|
||
|
# rake blogs-list (or f_blogs-list)
|
||
|
# => Runs test_list for BlogsController (functional test; use f_blogs-list to force it if unit test found)
|
||
|
#
|
||
|
# rake blog-create (or u_blog-create)
|
||
|
# => Runs test_create for BlogTest (unit test; use u_blog-create to force it if functional test found))
|
||
|
|
||
|
#test file will be matched in the order of this array items
|
||
|
TEST_TYPES = [
|
||
|
['u_', "unit/[file_name]_test.rb"],
|
||
|
['f_', "functional/[file_name]_controller_test.rb"],
|
||
|
['i_', "integration/[file_name]_test.rb"],
|
||
|
['l_', "long/[file_name]_test.rb"],
|
||
|
]
|
||
|
|
||
|
rule "" do |t|
|
||
|
all_flags = TEST_TYPES.map { |item| item[0] }
|
||
|
if Regexp.new("(#{all_flags.join '|'}|)(.*)\\-([^.]+)$").match(t.name)
|
||
|
flag = $1
|
||
|
file_name = $2
|
||
|
test_name = $3
|
||
|
|
||
|
path_getter = lambda { |type_info| type_info[1].gsub '[file_name]', file_name}
|
||
|
file_path = nil
|
||
|
TEST_TYPES.each do |type_info|
|
||
|
my_file_path = path_getter.call(type_info)
|
||
|
if flag == type_info[0]
|
||
|
type_info[1].match /((.+)\/)/
|
||
|
type = $2
|
||
|
puts "forced #{type} test"
|
||
|
file_path = my_file_path
|
||
|
break
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if file_path && !File.exist?("test/#{file_path}")
|
||
|
raise "No file found for #{file_path}"
|
||
|
end
|
||
|
|
||
|
if !file_path
|
||
|
TEST_TYPES.each do |type_info|
|
||
|
my_file_path = path_getter.call(type_info)
|
||
|
if File.exist? "test/#{my_file_path}"
|
||
|
puts "found #{my_file_path}"
|
||
|
file_path = my_file_path
|
||
|
break
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
if !file_path
|
||
|
raise "No file found for #{file_name}"
|
||
|
end
|
||
|
|
||
|
begin
|
||
|
sh "ruby -Ilib:test test/#{file_path} -n /^test_#{test_name}/"
|
||
|
rescue Exception => e
|
||
|
#no logger here, oops!
|
||
|
#log.debug "error executing tests: #{e.inspect}"
|
||
|
puts "error executing tests: #{e.inspect}"
|
||
|
end
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- 4
- Next »