@@ -1,119 +1,129 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class TimeEntry < ActiveRecord::Base |
|
18 | class TimeEntry < ActiveRecord::Base | |
19 | include Redmine::SafeAttributes |
|
19 | include Redmine::SafeAttributes | |
20 | # could have used polymorphic association |
|
20 | # could have used polymorphic association | |
21 | # project association here allows easy loading of time entries at project level with one database trip |
|
21 | # project association here allows easy loading of time entries at project level with one database trip | |
22 | belongs_to :project |
|
22 | belongs_to :project | |
23 | belongs_to :issue |
|
23 | belongs_to :issue | |
24 | belongs_to :user |
|
24 | belongs_to :user | |
25 | belongs_to :activity, :class_name => 'TimeEntryActivity', :foreign_key => 'activity_id' |
|
25 | belongs_to :activity, :class_name => 'TimeEntryActivity', :foreign_key => 'activity_id' | |
26 |
|
26 | |||
27 | attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek |
|
27 | attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek | |
28 |
|
28 | |||
29 | acts_as_customizable |
|
29 | acts_as_customizable | |
30 | acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"}, |
|
30 | acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"}, | |
31 | :url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}}, |
|
31 | :url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}}, | |
32 | :author => :user, |
|
32 | :author => :user, | |
33 | :group => :issue, |
|
33 | :group => :issue, | |
34 | :description => :comments |
|
34 | :description => :comments | |
35 |
|
35 | |||
36 | acts_as_activity_provider :timestamp => "#{table_name}.created_on", |
|
36 | acts_as_activity_provider :timestamp => "#{table_name}.created_on", | |
37 | :author_key => :user_id, |
|
37 | :author_key => :user_id, | |
38 | :find_options => {:include => :project} |
|
38 | :find_options => {:include => :project} | |
39 |
|
39 | |||
40 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on |
|
40 | validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on | |
41 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid |
|
41 | validates_numericality_of :hours, :allow_nil => true, :message => :invalid | |
42 | validates_length_of :comments, :maximum => 255, :allow_nil => true |
|
42 | validates_length_of :comments, :maximum => 255, :allow_nil => true | |
43 | validates :spent_on, :date => true |
|
43 | validates :spent_on, :date => true | |
44 | before_validation :set_project_if_nil |
|
44 | before_validation :set_project_if_nil | |
45 | validate :validate_time_entry |
|
45 | validate :validate_time_entry | |
46 |
|
46 | |||
47 | scope :visible, lambda {|*args| |
|
47 | scope :visible, lambda {|*args| | |
48 | includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)) |
|
48 | includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_time_entries, *args)) | |
49 | } |
|
49 | } | |
50 | scope :on_issue, lambda {|issue| |
|
50 | scope :on_issue, lambda {|issue| | |
51 | includes(:issue).where("#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}") |
|
51 | includes(:issue).where("#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}") | |
52 | } |
|
52 | } | |
53 | scope :on_project, lambda {|project, include_subprojects| |
|
53 | scope :on_project, lambda {|project, include_subprojects| | |
54 | includes(:project).where(project.project_condition(include_subprojects)) |
|
54 | includes(:project).where(project.project_condition(include_subprojects)) | |
55 | } |
|
55 | } | |
56 | scope :spent_between, lambda {|from, to| |
|
56 | scope :spent_between, lambda {|from, to| | |
57 | if from && to |
|
57 | if from && to | |
58 | where("#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to) |
|
58 | where("#{TimeEntry.table_name}.spent_on BETWEEN ? AND ?", from, to) | |
59 | elsif from |
|
59 | elsif from | |
60 | where("#{TimeEntry.table_name}.spent_on >= ?", from) |
|
60 | where("#{TimeEntry.table_name}.spent_on >= ?", from) | |
61 | elsif to |
|
61 | elsif to | |
62 | where("#{TimeEntry.table_name}.spent_on <= ?", to) |
|
62 | where("#{TimeEntry.table_name}.spent_on <= ?", to) | |
63 | else |
|
63 | else | |
64 | where(nil) |
|
64 | where(nil) | |
65 | end |
|
65 | end | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields' |
|
68 | safe_attributes 'hours', 'comments', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields' | |
69 |
|
69 | |||
70 | def initialize(attributes=nil, *args) |
|
70 | def initialize(attributes=nil, *args) | |
71 | super |
|
71 | super | |
72 | if new_record? && self.activity.nil? |
|
72 | if new_record? && self.activity.nil? | |
73 | if default_activity = TimeEntryActivity.default |
|
73 | if default_activity = TimeEntryActivity.default | |
74 | self.activity_id = default_activity.id |
|
74 | self.activity_id = default_activity.id | |
75 | end |
|
75 | end | |
76 | self.hours = nil if hours == 0 |
|
76 | self.hours = nil if hours == 0 | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
|
80 | def safe_attributes=(attrs, user=User.current) | |||
|
81 | attrs = super | |||
|
82 | if !new_record? && issue && issue.project_id != project_id | |||
|
83 | if user.allowed_to?(:log_time, issue.project) | |||
|
84 | self.project_id = issue.project_id | |||
|
85 | end | |||
|
86 | end | |||
|
87 | attrs | |||
|
88 | end | |||
|
89 | ||||
80 | def set_project_if_nil |
|
90 | def set_project_if_nil | |
81 | self.project = issue.project if issue && project.nil? |
|
91 | self.project = issue.project if issue && project.nil? | |
82 | end |
|
92 | end | |
83 |
|
93 | |||
84 | def validate_time_entry |
|
94 | def validate_time_entry | |
85 | errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000) |
|
95 | errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000) | |
86 | errors.add :project_id, :invalid if project.nil? |
|
96 | errors.add :project_id, :invalid if project.nil? | |
87 | errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) |
|
97 | errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) | |
88 | end |
|
98 | end | |
89 |
|
99 | |||
90 | def hours=(h) |
|
100 | def hours=(h) | |
91 | write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h) |
|
101 | write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h) | |
92 | end |
|
102 | end | |
93 |
|
103 | |||
94 | def hours |
|
104 | def hours | |
95 | h = read_attribute(:hours) |
|
105 | h = read_attribute(:hours) | |
96 | if h.is_a?(Float) |
|
106 | if h.is_a?(Float) | |
97 | h.round(2) |
|
107 | h.round(2) | |
98 | else |
|
108 | else | |
99 | h |
|
109 | h | |
100 | end |
|
110 | end | |
101 | end |
|
111 | end | |
102 |
|
112 | |||
103 | # tyear, tmonth, tweek assigned where setting spent_on attributes |
|
113 | # tyear, tmonth, tweek assigned where setting spent_on attributes | |
104 | # these attributes make time aggregations easier |
|
114 | # these attributes make time aggregations easier | |
105 | def spent_on=(date) |
|
115 | def spent_on=(date) | |
106 | super |
|
116 | super | |
107 | if spent_on.is_a?(Time) |
|
117 | if spent_on.is_a?(Time) | |
108 | self.spent_on = spent_on.to_date |
|
118 | self.spent_on = spent_on.to_date | |
109 | end |
|
119 | end | |
110 | self.tyear = spent_on ? spent_on.year : nil |
|
120 | self.tyear = spent_on ? spent_on.year : nil | |
111 | self.tmonth = spent_on ? spent_on.month : nil |
|
121 | self.tmonth = spent_on ? spent_on.month : nil | |
112 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil |
|
122 | self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil | |
113 | end |
|
123 | end | |
114 |
|
124 | |||
115 | # Returns true if the time entry can be edited by usr, otherwise false |
|
125 | # Returns true if the time entry can be edited by usr, otherwise false | |
116 | def editable_by?(usr) |
|
126 | def editable_by?(usr) | |
117 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) |
|
127 | (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project) | |
118 | end |
|
128 | end | |
119 | end |
|
129 | end |
@@ -1,663 +1,685 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # Redmine - project management software |
|
2 | # Redmine - project management software | |
3 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | # Copyright (C) 2006-2014 Jean-Philippe Lang | |
4 | # |
|
4 | # | |
5 | # This program is free software; you can redistribute it and/or |
|
5 | # This program is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU General Public License |
|
6 | # modify it under the terms of the GNU General Public License | |
7 | # as published by the Free Software Foundation; either version 2 |
|
7 | # as published by the Free Software Foundation; either version 2 | |
8 | # of the License, or (at your option) any later version. |
|
8 | # of the License, or (at your option) any later version. | |
9 | # |
|
9 | # | |
10 | # This program is distributed in the hope that it will be useful, |
|
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. |
|
13 | # GNU General Public License for more details. | |
14 | # |
|
14 | # | |
15 | # You should have received a copy of the GNU General Public License |
|
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software |
|
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
18 |
|
18 | |||
19 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | require File.expand_path('../../test_helper', __FILE__) | |
20 |
|
20 | |||
21 | class TimelogControllerTest < ActionController::TestCase |
|
21 | class TimelogControllerTest < ActionController::TestCase | |
22 | fixtures :projects, :enabled_modules, :roles, :members, |
|
22 | fixtures :projects, :enabled_modules, :roles, :members, | |
23 | :member_roles, :issues, :time_entries, :users, |
|
23 | :member_roles, :issues, :time_entries, :users, | |
24 | :trackers, :enumerations, :issue_statuses, |
|
24 | :trackers, :enumerations, :issue_statuses, | |
25 | :custom_fields, :custom_values, |
|
25 | :custom_fields, :custom_values, | |
26 | :projects_trackers, :custom_fields_trackers, |
|
26 | :projects_trackers, :custom_fields_trackers, | |
27 | :custom_fields_projects |
|
27 | :custom_fields_projects | |
28 |
|
28 | |||
29 | include Redmine::I18n |
|
29 | include Redmine::I18n | |
30 |
|
30 | |||
31 | def test_new_with_project_id |
|
31 | def test_new_with_project_id | |
32 | @request.session[:user_id] = 3 |
|
32 | @request.session[:user_id] = 3 | |
33 | get :new, :project_id => 1 |
|
33 | get :new, :project_id => 1 | |
34 | assert_response :success |
|
34 | assert_response :success | |
35 | assert_template 'new' |
|
35 | assert_template 'new' | |
36 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
36 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 | |
37 | assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]' |
|
37 | assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]' | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def test_new_with_issue_id |
|
40 | def test_new_with_issue_id | |
41 | @request.session[:user_id] = 3 |
|
41 | @request.session[:user_id] = 3 | |
42 | get :new, :issue_id => 2 |
|
42 | get :new, :issue_id => 2 | |
43 | assert_response :success |
|
43 | assert_response :success | |
44 | assert_template 'new' |
|
44 | assert_template 'new' | |
45 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
45 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 | |
46 | assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]' |
|
46 | assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]' | |
47 | end |
|
47 | end | |
48 |
|
48 | |||
49 | def test_new_without_project |
|
49 | def test_new_without_project | |
50 | @request.session[:user_id] = 3 |
|
50 | @request.session[:user_id] = 3 | |
51 | get :new |
|
51 | get :new | |
52 | assert_response :success |
|
52 | assert_response :success | |
53 | assert_template 'new' |
|
53 | assert_template 'new' | |
54 | assert_select 'select[name=?]', 'time_entry[project_id]' |
|
54 | assert_select 'select[name=?]', 'time_entry[project_id]' | |
55 | assert_select 'input[name=?]', 'time_entry[project_id]', 0 |
|
55 | assert_select 'input[name=?]', 'time_entry[project_id]', 0 | |
56 | end |
|
56 | end | |
57 |
|
57 | |||
58 | def test_new_without_project_should_prefill_the_form |
|
58 | def test_new_without_project_should_prefill_the_form | |
59 | @request.session[:user_id] = 3 |
|
59 | @request.session[:user_id] = 3 | |
60 | get :new, :time_entry => {:project_id => '1'} |
|
60 | get :new, :time_entry => {:project_id => '1'} | |
61 | assert_response :success |
|
61 | assert_response :success | |
62 | assert_template 'new' |
|
62 | assert_template 'new' | |
63 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
63 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
64 | assert_select 'option[value=1][selected=selected]' |
|
64 | assert_select 'option[value=1][selected=selected]' | |
65 | end |
|
65 | end | |
66 | assert_select 'input[name=?]', 'time_entry[project_id]', 0 |
|
66 | assert_select 'input[name=?]', 'time_entry[project_id]', 0 | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_new_without_project_should_deny_without_permission |
|
69 | def test_new_without_project_should_deny_without_permission | |
70 | Role.all.each {|role| role.remove_permission! :log_time} |
|
70 | Role.all.each {|role| role.remove_permission! :log_time} | |
71 | @request.session[:user_id] = 3 |
|
71 | @request.session[:user_id] = 3 | |
72 |
|
72 | |||
73 | get :new |
|
73 | get :new | |
74 | assert_response 403 |
|
74 | assert_response 403 | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_new_should_select_default_activity |
|
77 | def test_new_should_select_default_activity | |
78 | @request.session[:user_id] = 3 |
|
78 | @request.session[:user_id] = 3 | |
79 | get :new, :project_id => 1 |
|
79 | get :new, :project_id => 1 | |
80 | assert_response :success |
|
80 | assert_response :success | |
81 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
81 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
82 | assert_select 'option[selected=selected]', :text => 'Development' |
|
82 | assert_select 'option[selected=selected]', :text => 'Development' | |
83 | end |
|
83 | end | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def test_new_should_only_show_active_time_entry_activities |
|
86 | def test_new_should_only_show_active_time_entry_activities | |
87 | @request.session[:user_id] = 3 |
|
87 | @request.session[:user_id] = 3 | |
88 | get :new, :project_id => 1 |
|
88 | get :new, :project_id => 1 | |
89 | assert_response :success |
|
89 | assert_response :success | |
90 | assert_no_tag 'option', :content => 'Inactive Activity' |
|
90 | assert_no_tag 'option', :content => 'Inactive Activity' | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | def test_get_edit_existing_time |
|
93 | def test_get_edit_existing_time | |
94 | @request.session[:user_id] = 2 |
|
94 | @request.session[:user_id] = 2 | |
95 | get :edit, :id => 2, :project_id => nil |
|
95 | get :edit, :id => 2, :project_id => nil | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_template 'edit' |
|
97 | assert_template 'edit' | |
98 | # Default activity selected |
|
98 | # Default activity selected | |
99 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' } |
|
99 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' } | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity |
|
102 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity | |
103 | te = TimeEntry.find(1) |
|
103 | te = TimeEntry.find(1) | |
104 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") |
|
104 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") | |
105 | te.save! |
|
105 | te.save! | |
106 |
|
106 | |||
107 | @request.session[:user_id] = 1 |
|
107 | @request.session[:user_id] = 1 | |
108 | get :edit, :project_id => 1, :id => 1 |
|
108 | get :edit, :project_id => 1, :id => 1 | |
109 | assert_response :success |
|
109 | assert_response :success | |
110 | assert_template 'edit' |
|
110 | assert_template 'edit' | |
111 | # Blank option since nothing is pre-selected |
|
111 | # Blank option since nothing is pre-selected | |
112 | assert_tag :tag => 'option', :content => '--- Please select ---' |
|
112 | assert_tag :tag => 'option', :content => '--- Please select ---' | |
113 | end |
|
113 | end | |
114 |
|
114 | |||
115 | def test_post_create |
|
115 | def test_post_create | |
116 | # TODO: should POST to issuesβ time log instead of project. change form |
|
116 | # TODO: should POST to issuesβ time log instead of project. change form | |
117 | # and routing |
|
117 | # and routing | |
118 | @request.session[:user_id] = 3 |
|
118 | @request.session[:user_id] = 3 | |
119 | post :create, :project_id => 1, |
|
119 | post :create, :project_id => 1, | |
120 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
120 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
121 | # Not the default activity |
|
121 | # Not the default activity | |
122 | :activity_id => '11', |
|
122 | :activity_id => '11', | |
123 | :spent_on => '2008-03-14', |
|
123 | :spent_on => '2008-03-14', | |
124 | :issue_id => '1', |
|
124 | :issue_id => '1', | |
125 | :hours => '7.3'} |
|
125 | :hours => '7.3'} | |
126 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
126 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
127 |
|
127 | |||
128 | i = Issue.find(1) |
|
128 | i = Issue.find(1) | |
129 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
129 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') | |
130 | assert_not_nil t |
|
130 | assert_not_nil t | |
131 | assert_equal 11, t.activity_id |
|
131 | assert_equal 11, t.activity_id | |
132 | assert_equal 7.3, t.hours |
|
132 | assert_equal 7.3, t.hours | |
133 | assert_equal 3, t.user_id |
|
133 | assert_equal 3, t.user_id | |
134 | assert_equal i, t.issue |
|
134 | assert_equal i, t.issue | |
135 | assert_equal i.project, t.project |
|
135 | assert_equal i.project, t.project | |
136 | end |
|
136 | end | |
137 |
|
137 | |||
138 | def test_post_create_with_blank_issue |
|
138 | def test_post_create_with_blank_issue | |
139 | # TODO: should POST to issuesβ time log instead of project. change form |
|
139 | # TODO: should POST to issuesβ time log instead of project. change form | |
140 | # and routing |
|
140 | # and routing | |
141 | @request.session[:user_id] = 3 |
|
141 | @request.session[:user_id] = 3 | |
142 | post :create, :project_id => 1, |
|
142 | post :create, :project_id => 1, | |
143 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
143 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
144 | # Not the default activity |
|
144 | # Not the default activity | |
145 | :activity_id => '11', |
|
145 | :activity_id => '11', | |
146 | :issue_id => '', |
|
146 | :issue_id => '', | |
147 | :spent_on => '2008-03-14', |
|
147 | :spent_on => '2008-03-14', | |
148 | :hours => '7.3'} |
|
148 | :hours => '7.3'} | |
149 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
149 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
150 |
|
150 | |||
151 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
151 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') | |
152 | assert_not_nil t |
|
152 | assert_not_nil t | |
153 | assert_equal 11, t.activity_id |
|
153 | assert_equal 11, t.activity_id | |
154 | assert_equal 7.3, t.hours |
|
154 | assert_equal 7.3, t.hours | |
155 | assert_equal 3, t.user_id |
|
155 | assert_equal 3, t.user_id | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def test_create_and_continue |
|
158 | def test_create_and_continue | |
159 | @request.session[:user_id] = 2 |
|
159 | @request.session[:user_id] = 2 | |
160 | post :create, :project_id => 1, |
|
160 | post :create, :project_id => 1, | |
161 | :time_entry => {:activity_id => '11', |
|
161 | :time_entry => {:activity_id => '11', | |
162 | :issue_id => '', |
|
162 | :issue_id => '', | |
163 | :spent_on => '2008-03-14', |
|
163 | :spent_on => '2008-03-14', | |
164 | :hours => '7.3'}, |
|
164 | :hours => '7.3'}, | |
165 | :continue => '1' |
|
165 | :continue => '1' | |
166 | assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=' |
|
166 | assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=' | |
167 | end |
|
167 | end | |
168 |
|
168 | |||
169 | def test_create_and_continue_with_issue_id |
|
169 | def test_create_and_continue_with_issue_id | |
170 | @request.session[:user_id] = 2 |
|
170 | @request.session[:user_id] = 2 | |
171 | post :create, :project_id => 1, |
|
171 | post :create, :project_id => 1, | |
172 | :time_entry => {:activity_id => '11', |
|
172 | :time_entry => {:activity_id => '11', | |
173 | :issue_id => '1', |
|
173 | :issue_id => '1', | |
174 | :spent_on => '2008-03-14', |
|
174 | :spent_on => '2008-03-14', | |
175 | :hours => '7.3'}, |
|
175 | :hours => '7.3'}, | |
176 | :continue => '1' |
|
176 | :continue => '1' | |
177 | assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1' |
|
177 | assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1' | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | def test_create_and_continue_without_project |
|
180 | def test_create_and_continue_without_project | |
181 | @request.session[:user_id] = 2 |
|
181 | @request.session[:user_id] = 2 | |
182 | post :create, :time_entry => {:project_id => '1', |
|
182 | post :create, :time_entry => {:project_id => '1', | |
183 | :activity_id => '11', |
|
183 | :activity_id => '11', | |
184 | :issue_id => '', |
|
184 | :issue_id => '', | |
185 | :spent_on => '2008-03-14', |
|
185 | :spent_on => '2008-03-14', | |
186 | :hours => '7.3'}, |
|
186 | :hours => '7.3'}, | |
187 | :continue => '1' |
|
187 | :continue => '1' | |
188 |
|
188 | |||
189 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' |
|
189 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' | |
190 | end |
|
190 | end | |
191 |
|
191 | |||
192 | def test_create_without_log_time_permission_should_be_denied |
|
192 | def test_create_without_log_time_permission_should_be_denied | |
193 | @request.session[:user_id] = 2 |
|
193 | @request.session[:user_id] = 2 | |
194 | Role.find_by_name('Manager').remove_permission! :log_time |
|
194 | Role.find_by_name('Manager').remove_permission! :log_time | |
195 | post :create, :project_id => 1, |
|
195 | post :create, :project_id => 1, | |
196 | :time_entry => {:activity_id => '11', |
|
196 | :time_entry => {:activity_id => '11', | |
197 | :issue_id => '', |
|
197 | :issue_id => '', | |
198 | :spent_on => '2008-03-14', |
|
198 | :spent_on => '2008-03-14', | |
199 | :hours => '7.3'} |
|
199 | :hours => '7.3'} | |
200 |
|
200 | |||
201 | assert_response 403 |
|
201 | assert_response 403 | |
202 | end |
|
202 | end | |
203 |
|
203 | |||
204 | def test_create_with_failure |
|
204 | def test_create_with_failure | |
205 | @request.session[:user_id] = 2 |
|
205 | @request.session[:user_id] = 2 | |
206 | post :create, :project_id => 1, |
|
206 | post :create, :project_id => 1, | |
207 | :time_entry => {:activity_id => '', |
|
207 | :time_entry => {:activity_id => '', | |
208 | :issue_id => '', |
|
208 | :issue_id => '', | |
209 | :spent_on => '2008-03-14', |
|
209 | :spent_on => '2008-03-14', | |
210 | :hours => '7.3'} |
|
210 | :hours => '7.3'} | |
211 |
|
211 | |||
212 | assert_response :success |
|
212 | assert_response :success | |
213 | assert_template 'new' |
|
213 | assert_template 'new' | |
214 | end |
|
214 | end | |
215 |
|
215 | |||
216 | def test_create_without_project |
|
216 | def test_create_without_project | |
217 | @request.session[:user_id] = 2 |
|
217 | @request.session[:user_id] = 2 | |
218 | assert_difference 'TimeEntry.count' do |
|
218 | assert_difference 'TimeEntry.count' do | |
219 | post :create, :time_entry => {:project_id => '1', |
|
219 | post :create, :time_entry => {:project_id => '1', | |
220 | :activity_id => '11', |
|
220 | :activity_id => '11', | |
221 | :issue_id => '', |
|
221 | :issue_id => '', | |
222 | :spent_on => '2008-03-14', |
|
222 | :spent_on => '2008-03-14', | |
223 | :hours => '7.3'} |
|
223 | :hours => '7.3'} | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
226 | assert_redirected_to '/projects/ecookbook/time_entries' | |
227 | time_entry = TimeEntry.order('id DESC').first |
|
227 | time_entry = TimeEntry.order('id DESC').first | |
228 | assert_equal 1, time_entry.project_id |
|
228 | assert_equal 1, time_entry.project_id | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | def test_create_without_project_should_fail_with_issue_not_inside_project |
|
231 | def test_create_without_project_should_fail_with_issue_not_inside_project | |
232 | @request.session[:user_id] = 2 |
|
232 | @request.session[:user_id] = 2 | |
233 | assert_no_difference 'TimeEntry.count' do |
|
233 | assert_no_difference 'TimeEntry.count' do | |
234 | post :create, :time_entry => {:project_id => '1', |
|
234 | post :create, :time_entry => {:project_id => '1', | |
235 | :activity_id => '11', |
|
235 | :activity_id => '11', | |
236 | :issue_id => '5', |
|
236 | :issue_id => '5', | |
237 | :spent_on => '2008-03-14', |
|
237 | :spent_on => '2008-03-14', | |
238 | :hours => '7.3'} |
|
238 | :hours => '7.3'} | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 | assert_response :success |
|
241 | assert_response :success | |
242 | assert assigns(:time_entry).errors[:issue_id].present? |
|
242 | assert assigns(:time_entry).errors[:issue_id].present? | |
243 | end |
|
243 | end | |
244 |
|
244 | |||
245 | def test_create_without_project_should_deny_without_permission |
|
245 | def test_create_without_project_should_deny_without_permission | |
246 | @request.session[:user_id] = 2 |
|
246 | @request.session[:user_id] = 2 | |
247 | Project.find(3).disable_module!(:time_tracking) |
|
247 | Project.find(3).disable_module!(:time_tracking) | |
248 |
|
248 | |||
249 | assert_no_difference 'TimeEntry.count' do |
|
249 | assert_no_difference 'TimeEntry.count' do | |
250 | post :create, :time_entry => {:project_id => '3', |
|
250 | post :create, :time_entry => {:project_id => '3', | |
251 | :activity_id => '11', |
|
251 | :activity_id => '11', | |
252 | :issue_id => '', |
|
252 | :issue_id => '', | |
253 | :spent_on => '2008-03-14', |
|
253 | :spent_on => '2008-03-14', | |
254 | :hours => '7.3'} |
|
254 | :hours => '7.3'} | |
255 | end |
|
255 | end | |
256 |
|
256 | |||
257 | assert_response 403 |
|
257 | assert_response 403 | |
258 | end |
|
258 | end | |
259 |
|
259 | |||
260 | def test_create_without_project_with_failure |
|
260 | def test_create_without_project_with_failure | |
261 | @request.session[:user_id] = 2 |
|
261 | @request.session[:user_id] = 2 | |
262 | assert_no_difference 'TimeEntry.count' do |
|
262 | assert_no_difference 'TimeEntry.count' do | |
263 | post :create, :time_entry => {:project_id => '1', |
|
263 | post :create, :time_entry => {:project_id => '1', | |
264 | :activity_id => '11', |
|
264 | :activity_id => '11', | |
265 | :issue_id => '', |
|
265 | :issue_id => '', | |
266 | :spent_on => '2008-03-14', |
|
266 | :spent_on => '2008-03-14', | |
267 | :hours => ''} |
|
267 | :hours => ''} | |
268 | end |
|
268 | end | |
269 |
|
269 | |||
270 | assert_response :success |
|
270 | assert_response :success | |
271 | assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}, |
|
271 | assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}, | |
272 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} |
|
272 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} | |
273 | end |
|
273 | end | |
274 |
|
274 | |||
275 | def test_update |
|
275 | def test_update | |
276 | entry = TimeEntry.find(1) |
|
276 | entry = TimeEntry.find(1) | |
277 | assert_equal 1, entry.issue_id |
|
277 | assert_equal 1, entry.issue_id | |
278 | assert_equal 2, entry.user_id |
|
278 | assert_equal 2, entry.user_id | |
279 |
|
279 | |||
280 | @request.session[:user_id] = 1 |
|
280 | @request.session[:user_id] = 1 | |
281 | put :update, :id => 1, |
|
281 | put :update, :id => 1, | |
282 | :time_entry => {:issue_id => '2', |
|
282 | :time_entry => {:issue_id => '2', | |
283 | :hours => '8'} |
|
283 | :hours => '8'} | |
284 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
284 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
285 | entry.reload |
|
285 | entry.reload | |
286 |
|
286 | |||
287 | assert_equal 8, entry.hours |
|
287 | assert_equal 8, entry.hours | |
288 | assert_equal 2, entry.issue_id |
|
288 | assert_equal 2, entry.issue_id | |
289 | assert_equal 2, entry.user_id |
|
289 | assert_equal 2, entry.user_id | |
290 | end |
|
290 | end | |
291 |
|
291 | |||
|
292 | def test_update_should_allow_to_change_issue_to_another_project | |||
|
293 | entry = TimeEntry.generate!(:issue_id => 1) | |||
|
294 | ||||
|
295 | @request.session[:user_id] = 1 | |||
|
296 | put :update, :id => entry.id, :time_entry => {:issue_id => '5'} | |||
|
297 | assert_response 302 | |||
|
298 | entry.reload | |||
|
299 | ||||
|
300 | assert_equal 5, entry.issue_id | |||
|
301 | assert_equal 3, entry.project_id | |||
|
302 | end | |||
|
303 | ||||
|
304 | def test_update_should_not_allow_to_change_issue_to_an_invalid_project | |||
|
305 | entry = TimeEntry.generate!(:issue_id => 1) | |||
|
306 | Project.find(3).disable_module!(:time_tracking) | |||
|
307 | ||||
|
308 | @request.session[:user_id] = 1 | |||
|
309 | put :update, :id => entry.id, :time_entry => {:issue_id => '5'} | |||
|
310 | assert_response 200 | |||
|
311 | assert_include "Issue is invalid", assigns(:time_entry).errors.full_messages | |||
|
312 | end | |||
|
313 | ||||
292 | def test_get_bulk_edit |
|
314 | def test_get_bulk_edit | |
293 | @request.session[:user_id] = 2 |
|
315 | @request.session[:user_id] = 2 | |
294 | get :bulk_edit, :ids => [1, 2] |
|
316 | get :bulk_edit, :ids => [1, 2] | |
295 | assert_response :success |
|
317 | assert_response :success | |
296 | assert_template 'bulk_edit' |
|
318 | assert_template 'bulk_edit' | |
297 |
|
319 | |||
298 | assert_select 'ul#bulk-selection' do |
|
320 | assert_select 'ul#bulk-selection' do | |
299 | assert_select 'li', 2 |
|
321 | assert_select 'li', 2 | |
300 | assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' |
|
322 | assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' | |
301 | end |
|
323 | end | |
302 |
|
324 | |||
303 | assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do |
|
325 | assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do | |
304 | # System wide custom field |
|
326 | # System wide custom field | |
305 | assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' |
|
327 | assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' | |
306 |
|
328 | |||
307 | # Activities |
|
329 | # Activities | |
308 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
330 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
309 | assert_select 'option[value=]', :text => '(No change)' |
|
331 | assert_select 'option[value=]', :text => '(No change)' | |
310 | assert_select 'option[value=9]', :text => 'Design' |
|
332 | assert_select 'option[value=9]', :text => 'Design' | |
311 | end |
|
333 | end | |
312 | end |
|
334 | end | |
313 | end |
|
335 | end | |
314 |
|
336 | |||
315 | def test_get_bulk_edit_on_different_projects |
|
337 | def test_get_bulk_edit_on_different_projects | |
316 | @request.session[:user_id] = 2 |
|
338 | @request.session[:user_id] = 2 | |
317 | get :bulk_edit, :ids => [1, 2, 6] |
|
339 | get :bulk_edit, :ids => [1, 2, 6] | |
318 | assert_response :success |
|
340 | assert_response :success | |
319 | assert_template 'bulk_edit' |
|
341 | assert_template 'bulk_edit' | |
320 | end |
|
342 | end | |
321 |
|
343 | |||
322 | def test_bulk_update |
|
344 | def test_bulk_update | |
323 | @request.session[:user_id] = 2 |
|
345 | @request.session[:user_id] = 2 | |
324 | # update time entry activity |
|
346 | # update time entry activity | |
325 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} |
|
347 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} | |
326 |
|
348 | |||
327 | assert_response 302 |
|
349 | assert_response 302 | |
328 | # check that the issues were updated |
|
350 | # check that the issues were updated | |
329 | assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id} |
|
351 | assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id} | |
330 | end |
|
352 | end | |
331 |
|
353 | |||
332 | def test_bulk_update_with_failure |
|
354 | def test_bulk_update_with_failure | |
333 | @request.session[:user_id] = 2 |
|
355 | @request.session[:user_id] = 2 | |
334 | post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'} |
|
356 | post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'} | |
335 |
|
357 | |||
336 | assert_response 302 |
|
358 | assert_response 302 | |
337 | assert_match /Failed to save 2 time entrie/, flash[:error] |
|
359 | assert_match /Failed to save 2 time entrie/, flash[:error] | |
338 | end |
|
360 | end | |
339 |
|
361 | |||
340 | def test_bulk_update_on_different_projects |
|
362 | def test_bulk_update_on_different_projects | |
341 | @request.session[:user_id] = 2 |
|
363 | @request.session[:user_id] = 2 | |
342 | # makes user a manager on the other project |
|
364 | # makes user a manager on the other project | |
343 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) |
|
365 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) | |
344 |
|
366 | |||
345 | # update time entry activity |
|
367 | # update time entry activity | |
346 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } |
|
368 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } | |
347 |
|
369 | |||
348 | assert_response 302 |
|
370 | assert_response 302 | |
349 | # check that the issues were updated |
|
371 | # check that the issues were updated | |
350 | assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id} |
|
372 | assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id} | |
351 | end |
|
373 | end | |
352 |
|
374 | |||
353 | def test_bulk_update_on_different_projects_without_rights |
|
375 | def test_bulk_update_on_different_projects_without_rights | |
354 | @request.session[:user_id] = 3 |
|
376 | @request.session[:user_id] = 3 | |
355 | user = User.find(3) |
|
377 | user = User.find(3) | |
356 | action = { :controller => "timelog", :action => "bulk_update" } |
|
378 | action = { :controller => "timelog", :action => "bulk_update" } | |
357 | assert user.allowed_to?(action, TimeEntry.find(1).project) |
|
379 | assert user.allowed_to?(action, TimeEntry.find(1).project) | |
358 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) |
|
380 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) | |
359 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } |
|
381 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } | |
360 | assert_response 403 |
|
382 | assert_response 403 | |
361 | end |
|
383 | end | |
362 |
|
384 | |||
363 | def test_bulk_update_custom_field |
|
385 | def test_bulk_update_custom_field | |
364 | @request.session[:user_id] = 2 |
|
386 | @request.session[:user_id] = 2 | |
365 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } |
|
387 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } | |
366 |
|
388 | |||
367 | assert_response 302 |
|
389 | assert_response 302 | |
368 | assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value} |
|
390 | assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value} | |
369 | end |
|
391 | end | |
370 |
|
392 | |||
371 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
393 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
372 | @request.session[:user_id] = 2 |
|
394 | @request.session[:user_id] = 2 | |
373 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' |
|
395 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' | |
374 |
|
396 | |||
375 | assert_response :redirect |
|
397 | assert_response :redirect | |
376 | assert_redirected_to '/time_entries' |
|
398 | assert_redirected_to '/time_entries' | |
377 | end |
|
399 | end | |
378 |
|
400 | |||
379 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
401 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
380 | @request.session[:user_id] = 2 |
|
402 | @request.session[:user_id] = 2 | |
381 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
403 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
382 |
|
404 | |||
383 | assert_response :redirect |
|
405 | assert_response :redirect | |
384 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier |
|
406 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier | |
385 | end |
|
407 | end | |
386 |
|
408 | |||
387 | def test_post_bulk_update_without_edit_permission_should_be_denied |
|
409 | def test_post_bulk_update_without_edit_permission_should_be_denied | |
388 | @request.session[:user_id] = 2 |
|
410 | @request.session[:user_id] = 2 | |
389 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
411 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
390 | post :bulk_update, :ids => [1,2] |
|
412 | post :bulk_update, :ids => [1,2] | |
391 |
|
413 | |||
392 | assert_response 403 |
|
414 | assert_response 403 | |
393 | end |
|
415 | end | |
394 |
|
416 | |||
395 | def test_destroy |
|
417 | def test_destroy | |
396 | @request.session[:user_id] = 2 |
|
418 | @request.session[:user_id] = 2 | |
397 | delete :destroy, :id => 1 |
|
419 | delete :destroy, :id => 1 | |
398 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
420 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
399 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
|
421 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] | |
400 | assert_nil TimeEntry.find_by_id(1) |
|
422 | assert_nil TimeEntry.find_by_id(1) | |
401 | end |
|
423 | end | |
402 |
|
424 | |||
403 | def test_destroy_should_fail |
|
425 | def test_destroy_should_fail | |
404 | # simulate that this fails (e.g. due to a plugin), see #5700 |
|
426 | # simulate that this fails (e.g. due to a plugin), see #5700 | |
405 | TimeEntry.any_instance.expects(:destroy).returns(false) |
|
427 | TimeEntry.any_instance.expects(:destroy).returns(false) | |
406 |
|
428 | |||
407 | @request.session[:user_id] = 2 |
|
429 | @request.session[:user_id] = 2 | |
408 | delete :destroy, :id => 1 |
|
430 | delete :destroy, :id => 1 | |
409 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
431 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
410 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] |
|
432 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] | |
411 | assert_not_nil TimeEntry.find_by_id(1) |
|
433 | assert_not_nil TimeEntry.find_by_id(1) | |
412 | end |
|
434 | end | |
413 |
|
435 | |||
414 | def test_index_all_projects |
|
436 | def test_index_all_projects | |
415 | get :index |
|
437 | get :index | |
416 | assert_response :success |
|
438 | assert_response :success | |
417 | assert_template 'index' |
|
439 | assert_template 'index' | |
418 | assert_not_nil assigns(:total_hours) |
|
440 | assert_not_nil assigns(:total_hours) | |
419 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
441 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
420 | assert_tag :form, |
|
442 | assert_tag :form, | |
421 | :attributes => {:action => "/time_entries", :id => 'query_form'} |
|
443 | :attributes => {:action => "/time_entries", :id => 'query_form'} | |
422 | end |
|
444 | end | |
423 |
|
445 | |||
424 | def test_index_all_projects_should_show_log_time_link |
|
446 | def test_index_all_projects_should_show_log_time_link | |
425 | @request.session[:user_id] = 2 |
|
447 | @request.session[:user_id] = 2 | |
426 | get :index |
|
448 | get :index | |
427 | assert_response :success |
|
449 | assert_response :success | |
428 | assert_template 'index' |
|
450 | assert_template 'index' | |
429 | assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/ |
|
451 | assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/ | |
430 | end |
|
452 | end | |
431 |
|
453 | |||
432 | def test_index_my_spent_time |
|
454 | def test_index_my_spent_time | |
433 | @request.session[:user_id] = 2 |
|
455 | @request.session[:user_id] = 2 | |
434 | get :index, :user_id => 'me' |
|
456 | get :index, :user_id => 'me' | |
435 | assert_response :success |
|
457 | assert_response :success | |
436 | assert_template 'index' |
|
458 | assert_template 'index' | |
437 | assert assigns(:entries).all? {|entry| entry.user_id == 2} |
|
459 | assert assigns(:entries).all? {|entry| entry.user_id == 2} | |
438 | end |
|
460 | end | |
439 |
|
461 | |||
440 | def test_index_at_project_level |
|
462 | def test_index_at_project_level | |
441 | get :index, :project_id => 'ecookbook' |
|
463 | get :index, :project_id => 'ecookbook' | |
442 | assert_response :success |
|
464 | assert_response :success | |
443 | assert_template 'index' |
|
465 | assert_template 'index' | |
444 | assert_not_nil assigns(:entries) |
|
466 | assert_not_nil assigns(:entries) | |
445 | assert_equal 4, assigns(:entries).size |
|
467 | assert_equal 4, assigns(:entries).size | |
446 | # project and subproject |
|
468 | # project and subproject | |
447 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
469 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort | |
448 | assert_not_nil assigns(:total_hours) |
|
470 | assert_not_nil assigns(:total_hours) | |
449 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
471 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
450 | assert_tag :form, |
|
472 | assert_tag :form, | |
451 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
473 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
452 | end |
|
474 | end | |
453 |
|
475 | |||
454 | def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries |
|
476 | def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries | |
455 | entry = TimeEntry.generate!(:project => Project.find(3)) |
|
477 | entry = TimeEntry.generate!(:project => Project.find(3)) | |
456 |
|
478 | |||
457 | with_settings :display_subprojects_issues => '0' do |
|
479 | with_settings :display_subprojects_issues => '0' do | |
458 | get :index, :project_id => 'ecookbook' |
|
480 | get :index, :project_id => 'ecookbook' | |
459 | assert_response :success |
|
481 | assert_response :success | |
460 | assert_template 'index' |
|
482 | assert_template 'index' | |
461 | assert_not_include entry, assigns(:entries) |
|
483 | assert_not_include entry, assigns(:entries) | |
462 | end |
|
484 | end | |
463 | end |
|
485 | end | |
464 |
|
486 | |||
465 | def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries |
|
487 | def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries | |
466 | entry = TimeEntry.generate!(:project => Project.find(3)) |
|
488 | entry = TimeEntry.generate!(:project => Project.find(3)) | |
467 |
|
489 | |||
468 | with_settings :display_subprojects_issues => '0' do |
|
490 | with_settings :display_subprojects_issues => '0' do | |
469 | get :index, :project_id => 'ecookbook', :subproject_id => 3 |
|
491 | get :index, :project_id => 'ecookbook', :subproject_id => 3 | |
470 | assert_response :success |
|
492 | assert_response :success | |
471 | assert_template 'index' |
|
493 | assert_template 'index' | |
472 | assert_include entry, assigns(:entries) |
|
494 | assert_include entry, assigns(:entries) | |
473 | end |
|
495 | end | |
474 | end |
|
496 | end | |
475 |
|
497 | |||
476 | def test_index_at_project_level_with_date_range |
|
498 | def test_index_at_project_level_with_date_range | |
477 | get :index, :project_id => 'ecookbook', |
|
499 | get :index, :project_id => 'ecookbook', | |
478 | :f => ['spent_on'], |
|
500 | :f => ['spent_on'], | |
479 | :op => {'spent_on' => '><'}, |
|
501 | :op => {'spent_on' => '><'}, | |
480 | :v => {'spent_on' => ['2007-03-20', '2007-04-30']} |
|
502 | :v => {'spent_on' => ['2007-03-20', '2007-04-30']} | |
481 | assert_response :success |
|
503 | assert_response :success | |
482 | assert_template 'index' |
|
504 | assert_template 'index' | |
483 | assert_not_nil assigns(:entries) |
|
505 | assert_not_nil assigns(:entries) | |
484 | assert_equal 3, assigns(:entries).size |
|
506 | assert_equal 3, assigns(:entries).size | |
485 | assert_not_nil assigns(:total_hours) |
|
507 | assert_not_nil assigns(:total_hours) | |
486 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
508 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
487 | assert_tag :form, |
|
509 | assert_tag :form, | |
488 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
510 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
489 | end |
|
511 | end | |
490 |
|
512 | |||
491 | def test_index_at_project_level_with_date_range_using_from_and_to_params |
|
513 | def test_index_at_project_level_with_date_range_using_from_and_to_params | |
492 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' |
|
514 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' | |
493 | assert_response :success |
|
515 | assert_response :success | |
494 | assert_template 'index' |
|
516 | assert_template 'index' | |
495 | assert_not_nil assigns(:entries) |
|
517 | assert_not_nil assigns(:entries) | |
496 | assert_equal 3, assigns(:entries).size |
|
518 | assert_equal 3, assigns(:entries).size | |
497 | assert_not_nil assigns(:total_hours) |
|
519 | assert_not_nil assigns(:total_hours) | |
498 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
520 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
499 | assert_tag :form, |
|
521 | assert_tag :form, | |
500 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
522 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
501 | end |
|
523 | end | |
502 |
|
524 | |||
503 | def test_index_at_project_level_with_period |
|
525 | def test_index_at_project_level_with_period | |
504 | get :index, :project_id => 'ecookbook', |
|
526 | get :index, :project_id => 'ecookbook', | |
505 | :f => ['spent_on'], |
|
527 | :f => ['spent_on'], | |
506 | :op => {'spent_on' => '>t-'}, |
|
528 | :op => {'spent_on' => '>t-'}, | |
507 | :v => {'spent_on' => ['7']} |
|
529 | :v => {'spent_on' => ['7']} | |
508 | assert_response :success |
|
530 | assert_response :success | |
509 | assert_template 'index' |
|
531 | assert_template 'index' | |
510 | assert_not_nil assigns(:entries) |
|
532 | assert_not_nil assigns(:entries) | |
511 | assert_not_nil assigns(:total_hours) |
|
533 | assert_not_nil assigns(:total_hours) | |
512 | assert_tag :form, |
|
534 | assert_tag :form, | |
513 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
535 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
514 | end |
|
536 | end | |
515 |
|
537 | |||
516 | def test_index_at_issue_level |
|
538 | def test_index_at_issue_level | |
517 | get :index, :issue_id => 1 |
|
539 | get :index, :issue_id => 1 | |
518 | assert_response :success |
|
540 | assert_response :success | |
519 | assert_template 'index' |
|
541 | assert_template 'index' | |
520 | assert_not_nil assigns(:entries) |
|
542 | assert_not_nil assigns(:entries) | |
521 | assert_equal 2, assigns(:entries).size |
|
543 | assert_equal 2, assigns(:entries).size | |
522 | assert_not_nil assigns(:total_hours) |
|
544 | assert_not_nil assigns(:total_hours) | |
523 | assert_equal 154.25, assigns(:total_hours) |
|
545 | assert_equal 154.25, assigns(:total_hours) | |
524 | # display all time |
|
546 | # display all time | |
525 | assert_nil assigns(:from) |
|
547 | assert_nil assigns(:from) | |
526 | assert_nil assigns(:to) |
|
548 | assert_nil assigns(:to) | |
527 | # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes |
|
549 | # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes | |
528 | # to use /issues/:issue_id/time_entries |
|
550 | # to use /issues/:issue_id/time_entries | |
529 | assert_tag :form, |
|
551 | assert_tag :form, | |
530 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} |
|
552 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} | |
531 | end |
|
553 | end | |
532 |
|
554 | |||
533 | def test_index_should_sort_by_spent_on_and_created_on |
|
555 | def test_index_should_sort_by_spent_on_and_created_on | |
534 | t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10) |
|
556 | t1 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:00:00', :activity_id => 10) | |
535 | t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10) |
|
557 | t2 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-16', :created_on => '2012-06-16 20:05:00', :activity_id => 10) | |
536 | t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10) |
|
558 | t3 = TimeEntry.create!(:user => User.find(1), :project => Project.find(1), :hours => 1, :spent_on => '2012-06-15', :created_on => '2012-06-16 20:10:00', :activity_id => 10) | |
537 |
|
559 | |||
538 | get :index, :project_id => 1, |
|
560 | get :index, :project_id => 1, | |
539 | :f => ['spent_on'], |
|
561 | :f => ['spent_on'], | |
540 | :op => {'spent_on' => '><'}, |
|
562 | :op => {'spent_on' => '><'}, | |
541 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']} |
|
563 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']} | |
542 | assert_response :success |
|
564 | assert_response :success | |
543 | assert_equal [t2, t1, t3], assigns(:entries) |
|
565 | assert_equal [t2, t1, t3], assigns(:entries) | |
544 |
|
566 | |||
545 | get :index, :project_id => 1, |
|
567 | get :index, :project_id => 1, | |
546 | :f => ['spent_on'], |
|
568 | :f => ['spent_on'], | |
547 | :op => {'spent_on' => '><'}, |
|
569 | :op => {'spent_on' => '><'}, | |
548 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, |
|
570 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, | |
549 | :sort => 'spent_on' |
|
571 | :sort => 'spent_on' | |
550 | assert_response :success |
|
572 | assert_response :success | |
551 | assert_equal [t3, t1, t2], assigns(:entries) |
|
573 | assert_equal [t3, t1, t2], assigns(:entries) | |
552 | end |
|
574 | end | |
553 |
|
575 | |||
554 | def test_index_with_filter_on_issue_custom_field |
|
576 | def test_index_with_filter_on_issue_custom_field | |
555 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) |
|
577 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
556 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) |
|
578 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
557 |
|
579 | |||
558 | get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} |
|
580 | get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} | |
559 | assert_response :success |
|
581 | assert_response :success | |
560 | assert_equal [entry], assigns(:entries) |
|
582 | assert_equal [entry], assigns(:entries) | |
561 | end |
|
583 | end | |
562 |
|
584 | |||
563 | def test_index_with_issue_custom_field_column |
|
585 | def test_index_with_issue_custom_field_column | |
564 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) |
|
586 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
565 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) |
|
587 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
566 |
|
588 | |||
567 | get :index, :c => %w(project spent_on issue comments hours issue.cf_2) |
|
589 | get :index, :c => %w(project spent_on issue comments hours issue.cf_2) | |
568 | assert_response :success |
|
590 | assert_response :success | |
569 | assert_include :'issue.cf_2', assigns(:query).column_names |
|
591 | assert_include :'issue.cf_2', assigns(:query).column_names | |
570 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' |
|
592 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' | |
571 | end |
|
593 | end | |
572 |
|
594 | |||
573 | def test_index_with_time_entry_custom_field_column |
|
595 | def test_index_with_time_entry_custom_field_column | |
574 | field = TimeEntryCustomField.generate!(:field_format => 'string') |
|
596 | field = TimeEntryCustomField.generate!(:field_format => 'string') | |
575 | entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'}) |
|
597 | entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'}) | |
576 | field_name = "cf_#{field.id}" |
|
598 | field_name = "cf_#{field.id}" | |
577 |
|
599 | |||
578 | get :index, :c => ["hours", field_name] |
|
600 | get :index, :c => ["hours", field_name] | |
579 | assert_response :success |
|
601 | assert_response :success | |
580 | assert_include field_name.to_sym, assigns(:query).column_names |
|
602 | assert_include field_name.to_sym, assigns(:query).column_names | |
581 | assert_select "td.#{field_name}", :text => 'CF Value' |
|
603 | assert_select "td.#{field_name}", :text => 'CF Value' | |
582 | end |
|
604 | end | |
583 |
|
605 | |||
584 | def test_index_with_time_entry_custom_field_sorting |
|
606 | def test_index_with_time_entry_custom_field_sorting | |
585 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') |
|
607 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') | |
586 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) |
|
608 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) | |
587 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) |
|
609 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) | |
588 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) |
|
610 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) | |
589 | field_name = "cf_#{field.id}" |
|
611 | field_name = "cf_#{field.id}" | |
590 |
|
612 | |||
591 | get :index, :c => ["hours", field_name], :sort => field_name |
|
613 | get :index, :c => ["hours", field_name], :sort => field_name | |
592 | assert_response :success |
|
614 | assert_response :success | |
593 | assert_include field_name.to_sym, assigns(:query).column_names |
|
615 | assert_include field_name.to_sym, assigns(:query).column_names | |
594 | assert_select "th a.sort", :text => 'String Field' |
|
616 | assert_select "th a.sort", :text => 'String Field' | |
595 |
|
617 | |||
596 | # Make sure that values are properly sorted |
|
618 | # Make sure that values are properly sorted | |
597 | values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact |
|
619 | values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact | |
598 | assert_equal 3, values.size |
|
620 | assert_equal 3, values.size | |
599 | assert_equal values.sort, values |
|
621 | assert_equal values.sort, values | |
600 | end |
|
622 | end | |
601 |
|
623 | |||
602 | def test_index_atom_feed |
|
624 | def test_index_atom_feed | |
603 | get :index, :project_id => 1, :format => 'atom' |
|
625 | get :index, :project_id => 1, :format => 'atom' | |
604 | assert_response :success |
|
626 | assert_response :success | |
605 | assert_equal 'application/atom+xml', @response.content_type |
|
627 | assert_equal 'application/atom+xml', @response.content_type | |
606 | assert_not_nil assigns(:items) |
|
628 | assert_not_nil assigns(:items) | |
607 | assert assigns(:items).first.is_a?(TimeEntry) |
|
629 | assert assigns(:items).first.is_a?(TimeEntry) | |
608 | end |
|
630 | end | |
609 |
|
631 | |||
610 | def test_index_at_project_level_should_include_csv_export_dialog |
|
632 | def test_index_at_project_level_should_include_csv_export_dialog | |
611 | get :index, :project_id => 'ecookbook', |
|
633 | get :index, :project_id => 'ecookbook', | |
612 | :f => ['spent_on'], |
|
634 | :f => ['spent_on'], | |
613 | :op => {'spent_on' => '>='}, |
|
635 | :op => {'spent_on' => '>='}, | |
614 | :v => {'spent_on' => ['2007-04-01']}, |
|
636 | :v => {'spent_on' => ['2007-04-01']}, | |
615 | :c => ['spent_on', 'user'] |
|
637 | :c => ['spent_on', 'user'] | |
616 | assert_response :success |
|
638 | assert_response :success | |
617 |
|
639 | |||
618 | assert_select '#csv-export-options' do |
|
640 | assert_select '#csv-export-options' do | |
619 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do |
|
641 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do | |
620 | # filter |
|
642 | # filter | |
621 | assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' |
|
643 | assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' | |
622 | assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' |
|
644 | assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' | |
623 | assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' |
|
645 | assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' | |
624 | # columns |
|
646 | # columns | |
625 | assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' |
|
647 | assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' | |
626 | assert_select 'input[name=?][value=?]', 'c[]', 'user' |
|
648 | assert_select 'input[name=?][value=?]', 'c[]', 'user' | |
627 | assert_select 'input[name=?]', 'c[]', 2 |
|
649 | assert_select 'input[name=?]', 'c[]', 2 | |
628 | end |
|
650 | end | |
629 | end |
|
651 | end | |
630 | end |
|
652 | end | |
631 |
|
653 | |||
632 | def test_index_cross_project_should_include_csv_export_dialog |
|
654 | def test_index_cross_project_should_include_csv_export_dialog | |
633 | get :index |
|
655 | get :index | |
634 | assert_response :success |
|
656 | assert_response :success | |
635 |
|
657 | |||
636 | assert_select '#csv-export-options' do |
|
658 | assert_select '#csv-export-options' do | |
637 | assert_select 'form[action=?][method=get]', '/time_entries.csv' |
|
659 | assert_select 'form[action=?][method=get]', '/time_entries.csv' | |
638 | end |
|
660 | end | |
639 | end |
|
661 | end | |
640 |
|
662 | |||
641 | def test_index_at_issue_level_should_include_csv_export_dialog |
|
663 | def test_index_at_issue_level_should_include_csv_export_dialog | |
642 | get :index, :project_id => 'ecookbook', :issue_id => 3 |
|
664 | get :index, :project_id => 'ecookbook', :issue_id => 3 | |
643 | assert_response :success |
|
665 | assert_response :success | |
644 |
|
666 | |||
645 | assert_select '#csv-export-options' do |
|
667 | assert_select '#csv-export-options' do | |
646 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv' |
|
668 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv' | |
647 | end |
|
669 | end | |
648 | end |
|
670 | end | |
649 |
|
671 | |||
650 | def test_index_csv_all_projects |
|
672 | def test_index_csv_all_projects | |
651 | Setting.date_format = '%m/%d/%Y' |
|
673 | Setting.date_format = '%m/%d/%Y' | |
652 | get :index, :format => 'csv' |
|
674 | get :index, :format => 'csv' | |
653 | assert_response :success |
|
675 | assert_response :success | |
654 | assert_equal 'text/csv; header=present', response.content_type |
|
676 | assert_equal 'text/csv; header=present', response.content_type | |
655 | end |
|
677 | end | |
656 |
|
678 | |||
657 | def test_index_csv |
|
679 | def test_index_csv | |
658 | Setting.date_format = '%m/%d/%Y' |
|
680 | Setting.date_format = '%m/%d/%Y' | |
659 | get :index, :project_id => 1, :format => 'csv' |
|
681 | get :index, :project_id => 1, :format => 'csv' | |
660 | assert_response :success |
|
682 | assert_response :success | |
661 | assert_equal 'text/csv; header=present', response.content_type |
|
683 | assert_equal 'text/csv; header=present', response.content_type | |
662 | end |
|
684 | end | |
663 | end |
|
685 | end |
General Comments 0
You need to be logged in to leave comments.
Login now