bulk_time_entry_plugin 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/COPYRIGHT.txt ADDED
@@ -0,0 +1,17 @@
1
+ Redmine Bulk Time Entry is a Redmine plugin to enter multiple time
2
+ entries in bulk.
3
+ Copyright (C) 2007 Eric Davis, Little Stream Software
4
+
5
+ This program is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU General Public License
7
+ as published by the Free Software Foundation; either version 2
8
+ of the License, or (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
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
17
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
data/CREDITS.txt ADDED
@@ -0,0 +1,11 @@
1
+ Thanks go to the following people for patches and contributions:
2
+
3
+ Eric Davis <edavis[AT]littlestreamsoftware[DOT]com>
4
+ - Project Maintainer
5
+
6
+ Michele Franzin
7
+ - added Italian translation
8
+ - view localization
9
+
10
+ Antono Vasiljev <antono.vasiljev[AT]gmail[DOT]com>
11
+ - ajax issues selector
data/GPL.txt ADDED
@@ -0,0 +1,339 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Lesser General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License along
307
+ with this program; if not, write to the Free Software Foundation, Inc.,
308
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309
+
310
+ Also add information on how to contact you by electronic and paper mail.
311
+
312
+ If the program is interactive, make it output a short notice like this
313
+ when it starts in an interactive mode:
314
+
315
+ Gnomovision version 69, Copyright (C) year name of author
316
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
+ This is free software, and you are welcome to redistribute it
318
+ under certain conditions; type `show c' for details.
319
+
320
+ The hypothetical commands `show w' and `show c' should show the appropriate
321
+ parts of the General Public License. Of course, the commands you use may
322
+ be called something other than `show w' and `show c'; they could even be
323
+ mouse-clicks or menu items--whatever suits your program.
324
+
325
+ You should also get your employer (if you work as a programmer) or your
326
+ school, if any, to sign a "copyright disclaimer" for the program, if
327
+ necessary. Here is a sample; alter the names:
328
+
329
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
331
+
332
+ <signature of Ty Coon>, 1 April 1989
333
+ Ty Coon, President of Vice
334
+
335
+ This General Public License does not permit incorporating your program into
336
+ proprietary programs. If your program is a subroutine library, you may
337
+ consider it more useful to permit linking proprietary applications with the
338
+ library. If this is what you want to do, use the GNU Lesser General
339
+ Public License instead of this License.
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = Bulk Time Entry Plugin
2
+
3
+ This is a plugin to enter multiple time entries at one time.
4
+
5
+ == Features
6
+
7
+ * Enter multiple time entries from a single page
8
+ * Auto fills the issue id based on the selected project
9
+
10
+ == Getting the plugin
11
+
12
+ A copy of the plugin can be found in the {downloads}[https://projects.littlestreamsoftware.com/projects/list_files/redmine-bte] at Little Stream Software and also on {GitHub}[http://github.com/edavis10/redmine-bulk_time_entry_plugin/tree/master].
13
+
14
+ == Install
15
+
16
+ 1. Follow the Redmine plugin installation steps at: http://www.redmine.org/wiki/redmine/Plugins Make sure the plugin is installed to <tt>vendor/plugins/bulk_time_entry_plugin</tt>
17
+ 2. The link to the plugin should appear on the top left of your menu, called "Bulk Time Entries"
18
+
19
+ == Usage
20
+
21
+ 1. Enter the time entry details
22
+ 2. Click "Add Another" or use the accesskey of Alt + A to add another time entry form
23
+ 3. Click "Save" to save all the time entries
24
+
25
+ === CSV Import
26
+
27
+ A Rake task is included to allow importing Time Entries in bulk. The CSV file should be in the following format:
28
+
29
+ * No header
30
+ * Column 1 - Issue id
31
+ * Column 2 - Time Entry comment (optional)
32
+ * Column 3 - Date spent on. e.g. YYYY-MM-DD
33
+ * Column 4 - Activity name. e.g. Development
34
+ * Column 5 - Number of hours
35
+ * Column 6 - User login. e.g. edavis
36
+
37
+ The rake task should be run in your Redmine root like:
38
+
39
+ rake bulk_time_entry:import:csv RAILS_ENV=production CSV_FILE=/path/to/time_entries.csv
40
+
41
+ == License
42
+
43
+ This plugin is licensed under the GNU GPL v2. See COPYRIGHT.txt and GPL.txt for details.
44
+
45
+ == Project help
46
+
47
+ If you need help you can contact the maintainer at the Bug Tracker. The bug tracker is located at https://projects.littlestreamsoftware.com
48
+
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require 'redmine_plugin_support'
3
+
4
+ Dir[File.expand_path(File.dirname(__FILE__)) + "/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
5
+
6
+ RedminePluginSupport::Base.setup do |plugin|
7
+ plugin.project_name = 'bulk_time_entry_plugin'
8
+ plugin.default_task = [:test]
9
+ plugin.tasks = [:doc, :release, :clean, :test, :db]
10
+ # TODO: gem not getting this automaticly
11
+ plugin.redmine_root = File.expand_path(File.dirname(__FILE__) + '/../../../')
12
+ end
13
+ begin
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |s|
16
+ s.name = "bulk_time_entry_plugin"
17
+ s.summary = "This is a plugin to enter multiple time entries at one time."
18
+ s.email = "edavis@littlestreamsoftware.com"
19
+ s.homepage = "https://projects.littlestreamsoftware.com/projects/redmine-bte"
20
+ s.description = "This is a plugin to enter multiple time entries at one time."
21
+ s.authors = ["Eric Davis"]
22
+ s.rubyforge_project = "littlestream"
23
+ s.files = FileList[
24
+ "[A-Z]*",
25
+ "init.rb",
26
+ "rails/init.rb",
27
+ "{bin,generators,lib,test,app,assets,config,lang}/**/*",
28
+ 'lib/jeweler/templates/.gitignore'
29
+ ]
30
+ end
31
+ Jeweler::GemcutterTasks.new
32
+ Jeweler::RubyforgeTasks.new do |rubyforge|
33
+ rubyforge.doc_task = "rdoc"
34
+ end
35
+ rescue LoadError
36
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
37
+ end
data/TAGS ADDED
@@ -0,0 +1,28 @@
1
+
2
+ /home/edavis/dev/redmine/plugins/bulk_time_entry_plugin/app/helpers/bulk_time_entries_helper.rb,277
3
+ module BulkTimeEntriesHelperBulkTimeEntriesHelper1,0
4
+ def label_for_field(field, rnd_id, options = { })label_for_field3,88
5
+ def group_by_root_for_select(projects)group_by_root_for_select13,590
6
+ def grouped_options_for_issues(issues)grouped_options_for_issues27,1053
7
+
8
+ /home/edavis/dev/redmine/plugins/bulk_time_entry_plugin/app/controllers/bulk_time_entries_controller.rb,438
9
+ class BulkTimeEntriesController < ApplicationControllerBulkTimeEntriesController1,0
10
+ def indexindex10,186
11
+ def get_issues(project_id)get_issues18,342
12
+ def load_assigned_issuesload_assigned_issues22,457
13
+ def savesave30,729
14
+ def add_entryadd_entry51,1656
15
+ def load_activitiesload_activities71,2098
16
+ def load_allowed_projectsload_allowed_projects75,2199
17
+ def self.allowed_project?(project_id)allowed_project80,2344
18
+
19
+ /home/edavis/dev/redmine/plugins/bulk_time_entry_plugin/lib/bulk_time_entry_compatibility.rb,144
20
+ module BulkTimeEntryCompatibilityBulkTimeEntryCompatibility2,64
21
+ class EnumerationEnumeration3,98
22
+ def self.activitiesactivities6,236
23
+
24
+ /home/edavis/dev/redmine/plugins/bulk_time_entry_plugin/init.rb,0
25
+
26
+ /home/edavis/dev/redmine/plugins/bulk_time_entry_plugin/spec/spec_helper.rb,0
27
+
28
+ /home/edavis/dev/redmine/plugins/bulk_time_entry_plugin/spec/controllers/bulk_time_entries_controller_spec.rb,0
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -0,0 +1,111 @@
1
+ # -*- coding: utf-8 -*-
2
+ class BulkTimeEntriesController < ApplicationController
3
+ unloadable
4
+ layout 'base'
5
+ before_filter :load_activities
6
+ before_filter :load_allowed_projects
7
+
8
+ helper :custom_fields
9
+
10
+ protect_from_forgery :only => [:index, :save]
11
+
12
+ def index
13
+ @time_entries = [TimeEntry.new(:spent_on => Date.today.to_s)]
14
+
15
+ if @projects.empty?
16
+ render :action => 'no_projects'
17
+ end
18
+ end
19
+
20
+ def get_issues(project_id)
21
+ @issues = Issue.find(:all, :conditions => { :project_id => project_id })
22
+ end
23
+
24
+ def load_assigned_issues
25
+ get_issues params[:project_id]
26
+ render(:update) do |page|
27
+ page.replace_html params[:entry_id]+'_issues', :partial => 'issues_selector', :locals => { :issues => @issues, :rnd => params[:entry_id].split('_')[1] }
28
+ end
29
+ end
30
+
31
+
32
+ def save
33
+ if request.post?
34
+ @time_entries = params[:time_entries]
35
+
36
+ render :update do |page|
37
+ @time_entries.each_pair do |html_id, entry|
38
+ next unless BulkTimeEntriesController.allowed_project?(entry[:project_id])
39
+ @time_entry = TimeEntry.new(entry)
40
+ @time_entry.hours = nil if @time_entry.hours.blank? or @time_entry.hours <= 0
41
+ @time_entry.project_id = entry[:project_id] # project_id is protected from mass assignment
42
+ @time_entry.user = User.current
43
+ unless @time_entry.save
44
+ page.replace "entry_#{html_id}", :partial => 'time_entry', :object => @time_entry
45
+ else
46
+ time_entry_target = if @time_entry.issue
47
+ "#{h(@time_entry.project.name)} - #{h(@time_entry.issue.subject)}"
48
+ else
49
+ "#{h(@time_entry.project.name)}"
50
+ end
51
+ page.replace_html "entry_#{html_id}", "<div class='flash notice'>#{l(:text_time_added_to_project, :count => @time_entry.hours, :target => time_entry_target)}#{" (#{@time_entry.comments})" unless @time_entry.comments.blank?}.</div>"
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ def add_entry
59
+ begin
60
+ spent_on = Date.parse(params[:date])
61
+ rescue ArgumentError
62
+ # Fall through
63
+ end
64
+ spent_on ||= Date.today
65
+
66
+ @time_entry = TimeEntry.new(:spent_on => spent_on.to_s)
67
+ respond_to do |format|
68
+ format.js do
69
+ render :update do |page|
70
+ page.insert_html :bottom, 'entries', :partial => 'time_entry', :object => @time_entry
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def load_activities
79
+ @activities = BulkTimeEntryCompatibility::Enumeration::activities
80
+ end
81
+
82
+ def load_allowed_projects
83
+ @projects = User.current.projects.find(:all,
84
+ Project.allowed_to_condition(User.current, :log_time))
85
+ end
86
+
87
+ def self.allowed_project?(project_id)
88
+ return User.current.projects.find_by_id(project_id, Project.allowed_to_condition(User.current, :log_time))
89
+ end
90
+
91
+ # Redmine 0.8 compatibility fix
92
+ if Redmine::VERSION::MAJOR <= 0 && Redmine::VERSION::MINOR < 9
93
+ include ERB::Util
94
+
95
+ def project_tree_options_for_select(projects)
96
+ result = []
97
+ user_projects_by_root = projects.group_by(&:root)
98
+ user_projects_by_root.keys.sort.each do |root|
99
+ result << [h(root.name), root.id]
100
+ user_projects_by_root[root].sort.each do |project|
101
+ next if project == root
102
+ result << ["» #{h(project.name)}", project.id]
103
+ end
104
+ end
105
+ return result
106
+ end
107
+ helper_method :project_tree_options_for_select
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,38 @@
1
+ module BulkTimeEntriesHelper
2
+ # Cheap knock off of the tabular form builder's labeling
3
+ def label_for_field(field, rnd_id, options = { })
4
+ label_text = l(options[:label]) if options[:label]
5
+ label_text ||= l(("field_"+field.to_s.gsub(/\_id$/, "")).to_sym)
6
+ label_text += @template.content_tag("span", " *", :class => "required") if options.delete(:required)
7
+ label = @template.content_tag("label", label_text,
8
+ :class => (@object && @object.errors.on(field) ? "error" : nil),
9
+ :for => (@object_name.to_s + "_" + rnd_id.to_s + "_" + field.to_s))
10
+ label
11
+ end
12
+
13
+ def grouped_options_for_issues(issues)
14
+ open_issues = []
15
+ closed_issues = []
16
+ issues.each do |issue|
17
+ if issue.closed?
18
+ closed_issues << issue
19
+ else
20
+ open_issues << issue
21
+ end
22
+ end
23
+
24
+ html = '<option></option>'
25
+ unless open_issues.empty?
26
+ html << "<optgroup label='#{l(:label_open_issues)}'>"
27
+ html << options_from_collection_for_select(open_issues, :id, :to_s)
28
+ html << "</optgroup>"
29
+ end
30
+
31
+ unless closed_issues.empty?
32
+ html << "<optgroup label='#{l(:label_closed_issues)}'>"
33
+ html << options_from_collection_for_select(closed_issues, :id, :to_s)
34
+ html << "</optgroup>"
35
+ end
36
+ html
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ require 'fastercsv'
2
+
3
+ class BulkTimeEntry
4
+ def self.import_from_csv(file)
5
+ csv_file = File.read(file)
6
+ row_counter = 0
7
+ failed_counter = 0
8
+
9
+ begin
10
+ ActiveRecord::Base.transaction do
11
+ FasterCSV.parse(csv_file) do |row|
12
+ if row[0].blank? ||
13
+ row[2].blank? ||
14
+ row[3].blank? ||
15
+ row[4].blank? ||
16
+ row[5].blank?
17
+
18
+ failed_counter += 1
19
+ next
20
+
21
+ end
22
+ @time = TimeEntry.new(:issue_id => row[0],
23
+ :spent_on => row[2],
24
+ :activity => TimeEntryActivity.find_by_name(row[3].strip),
25
+ :hours => row[4])
26
+ # Truncate comments to 255 chars
27
+ @time.comments = row[1].mb_chars[0..255].strip.to_s if row[1].present?
28
+ @time.user = User.find_by_login(row[5].strip)
29
+
30
+ @time.save!
31
+ row_counter += 1
32
+ end
33
+ end
34
+ rescue ActiveRecord::StatementInvalid, ActiveRecord::RecordNotSaved, ActiveRecord::RecordInvalid => ex
35
+ return "ERROR: #{ex.message} on:\n\n#{@time.inspect}"
36
+ end
37
+ failed_message = failed_counter == 0 ? '' : "#{failed_counter} records failed to import."
38
+ return "Imported #{row_counter} records. #{failed_message}"
39
+ end
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ <%= label_for_field :issue_id, rnd %>
2
+ <% if @issues.nil? || @issues.empty? %>
3
+ <em><%= l(:label_no_data) %></em>
4
+ <% else %>
5
+ <%= select_tag "time_entries[#{rnd}][issue_id]", grouped_options_for_issues(@issues), :style => 'max-width: 95%;' %>&nbsp;
6
+ <% end %>
@@ -0,0 +1,40 @@
1
+ <% fields_for('time_entries[]', time_entry) do |f| %>
2
+ <%# trick to have automatically populated html id/names of fields %>
3
+ <% time_entry.id = rnd = rand(9999)
4
+ @object = time_entry
5
+ @object_name = 'time_entry' -%>
6
+ <div class="box" id="entry_<%= rnd %>">
7
+ <%= error_messages_for 'time_entry' %>
8
+ <p>
9
+ <%= label_for_field :project_id, rnd, :required => true %>
10
+ <% projects = project_tree_options_for_select(Project.has_module(:time_tracking)) %>
11
+ <%= f.select :project_id, projects, {},
12
+ { :onchange => "new Ajax.Request('#{url_for :action => 'load_assigned_issues'}', { parameters: { project_id: $F(this), entry_id: $(this).up(1).id } } )" } %>&nbsp;
13
+ </p>
14
+ <p id="entry_<%= rnd %>_issues">
15
+ <% @issues = controller.get_issues projects.first.id %>
16
+ <%= render :partial => 'issues_selector', :locals => { :issues => @issues, :f => f, :rnd => rnd } %>
17
+ </p>
18
+ <p>
19
+ <%= label_for_field :spent_on, rnd, :required => true %>
20
+ <%= f.text_field :spent_on, :size => 10, :name => "time_entries[#{rnd}][spent_on]", :id => "time_entries_#{rnd}_spent_on", :class => 'spent_on' %><%= calendar_for("time_entries_#{rnd}_spent_on") %>
21
+ </p>
22
+ <p>
23
+ <%= label_for_field :hours, rnd, :required => true %>
24
+ <%= f.text_field :hours, :size => 6, :maxlength => 6 %>
25
+ </p>
26
+ <p>
27
+ <%= label_for_field :comments, rnd %>
28
+ <%= f.text_field :comments, :size => 100, :maxlength => 255 %>
29
+ </p>
30
+ <p>
31
+ <%= label_for_field :activity_id, rnd, :required => true %>
32
+ <%= f.select :activity_id, (@activities.collect {|p| [p.name, p.id]}) %>
33
+ </p>
34
+ <% time_entry.custom_field_values.each do |value| %>
35
+ <p><%= custom_field_tag_with_label "time_entries[#{rnd}]", value %></p>
36
+ <% end if time_entry.respond_to?(:custom_field_values) %>
37
+ </div>
38
+ <% end %>
39
+
40
+ <%= javascript_tag("Form.Element.focus('time_entries_#{time_entry.id}_project_id')") %>
@@ -0,0 +1,24 @@
1
+ <h2><%= l(:label_bulk_time_entries) %></h2>
2
+
3
+ <% remote_form_for :bulk_time_entry_title, @bulk_time_entry, :url => {:action => 'save'}, :html => {:class => 'tabular'} do |f| %>
4
+ <div id="entries">
5
+ <%= render :partial => 'time_entry', :collection => @time_entries %>
6
+ </div>
7
+ <div id="add-entry">
8
+ <%= link_to_remote l(:label_bulk_time_add_another), :url => {:action => 'add_entry'}, :html => {:accesskey => 'a'}, :with => "'date='+ getLastTimeEntryDate()" %>
9
+ </div>
10
+ <br/>
11
+ <%= submit_tag l(:button_save) %>
12
+ <% end %>
13
+
14
+ <% html_title l(:label_bulk_time_entries) %>
15
+
16
+ <script type="text/javascript">
17
+ function getLastTimeEntryDate() {
18
+ if ($$('.spent_on').size() > 0) {
19
+ return $$('.spent_on').last().value;
20
+ } else {
21
+ return null;
22
+ }
23
+ }
24
+ </script>
@@ -0,0 +1,3 @@
1
+ <h2><%= l(:label_bulk_time_entries) %></h2>
2
+
3
+ <p><%= l(:text_bulk_time_entry_permission) %>.</p>
@@ -0,0 +1,6 @@
1
+ en:
2
+ bulk_time_entry_title: Bulk time entries
3
+ label_bulk_time_entries: Bulk Time Entries
4
+ label_bulk_time_add_another: Add Another
5
+ text_bulk_time_entry_permission: You do not have permission to log time on any projects
6
+ text_time_added_to_project: "{{count}} hours added to {{target}}"
@@ -0,0 +1,6 @@
1
+ fr:
2
+ bulk_time_entry_title: Saisie de temps
3
+ label_bulk_time_entries: Saisie de temps
4
+ label_bulk_time_add_another: Saisir un nouveau temps
5
+ text_bulk_time_entry_permission: Aucun projet ne vous permet de saisir des temps
6
+ text_time_added_to_project: "{{count}} heures ajoutees au {{target}}"
@@ -0,0 +1,6 @@
1
+ "hu":
2
+ bulk_time_entry_title: Idő mennyiség bejegyzések
3
+ label_bulk_time_entries: Idő mennyiség bejegyzések
4
+ label_bulk_time_add_another: További hozzáadása
5
+ text_bulk_time_entry_permission: Nincs jogosultságod a projektek idejét naplózni
6
+ text_time_added_to_project: "{{count}} óra hozzáadva a {{target}}"
@@ -0,0 +1,6 @@
1
+ it:
2
+ bulk_time_entry_title: Carica tempi
3
+ label_bulk_time_entries: Registrazione multipla tempi
4
+ label_bulk_time_add_another: aggiungine un'altro
5
+ text_bulk_time_entry_permission: Non hai i permessi per aggiungere tempi a nessun progetto
6
+ text_time_added_to_project: "Aggiunte {{count}} ore al {{target}}"
@@ -0,0 +1,6 @@
1
+ ko:
2
+ bulk_time_entry_title: 다중 시간 입력
3
+ label_bulk_time_entries: 다중 시간 입력
4
+ label_bulk_time_add_another: 다른 항목 추가
5
+ text_bulk_time_entry_permission: 시간을 기록할 권한이 없습니다.
6
+ text_time_added_to_project: "프로젝트에 {{count}} 시간을 기록했습니다 {{target}}."
@@ -0,0 +1,7 @@
1
+ pl:
2
+ bulk_time_entry_title: Grupowe wpisanie godzin pracy
3
+ label_bulk_time_entries: Grupowe Uzupełnianie Godzin Pracy
4
+ label_bulk_time_add_another: Dodaj Kolejny
5
+ text_bulk_time_entry_permission: Nie masz uprawnień do wpisywania godzin w żadnym projekcie
6
+ text_time_added_to_project: "{{count}} godzin dodano do {{target}}"
7
+
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/rails/init"
data/lang/en.yml ADDED
@@ -0,0 +1,5 @@
1
+ bulk_time_entry_title: Bulk time entries
2
+ label_bulk_time_entries: Bulk Time Entries
3
+ label_bulk_time_add_another: Add Another
4
+ text_bulk_time_entry_permission: You do not have permission to log time on any projects
5
+ text_time_added_to_project: %s hours added to project
data/lang/fr.yml ADDED
@@ -0,0 +1,5 @@
1
+ bulk_time_entry_title: Saisie de temps
2
+ label_bulk_time_entries: Saisie de temps
3
+ label_bulk_time_add_another: Saisir un nouveau temps
4
+ text_bulk_time_entry_permission: Aucun projet ne vous permet de saisir des temps
5
+ text_time_added_to_project: %s heures ajoutees au projet
data/lang/hu.yml ADDED
@@ -0,0 +1,5 @@
1
+ bulk_time_entry_title: Idő mennyiség bejegyzések
2
+ label_bulk_time_entries: Idő mennyiség bejegyzések
3
+ label_bulk_time_add_another: További hozzáadása
4
+ text_bulk_time_entry_permission: Nincs jogosultságod a projektek idejét naplózni
5
+ text_time_added_to_project: %s óra hozzáadva a projekthez
data/lang/it.yml ADDED
@@ -0,0 +1,5 @@
1
+ bulk_time_entry_title: Carica tempi
2
+ label_bulk_time_entries: Registrazione multipla tempi
3
+ label_bulk_time_add_another: aggiungine un'altro
4
+ text_bulk_time_entry_permission: Non hai i permessi per aggiungere tempi a nessun progetto
5
+ text_time_added_to_project: Aggiunte %d ore al progetto
data/lang/ko.yml ADDED
@@ -0,0 +1,5 @@
1
+ bulk_time_entry_title: 다중 시간 입력
2
+ label_bulk_time_entries: 다중 시간 입력
3
+ label_bulk_time_add_another: 다른 항목 추가
4
+ text_bulk_time_entry_permission: 시간을 기록할 권한이 없습니다.
5
+ text_time_added_to_project: 프로젝트에 %s 시간을 기록했습니다.
data/lang/pl.yml ADDED
@@ -0,0 +1,5 @@
1
+ bulk_time_entry_title: Grupowe wpisanie godzin pracy
2
+ label_bulk_time_entries: Grupowe Uzupełnianie Godzin Pracy
3
+ label_bulk_time_add_another: Dodaj Kolejny
4
+ text_bulk_time_entry_permission: Nie masz uprawnień do wpisywania godzin w żadnym projekcie
5
+ text_time_added_to_project: "{{count}} godzin dodano do projektu"
@@ -0,0 +1,22 @@
1
+ begin
2
+ require 'time_entry_activity'
3
+ rescue LoadError
4
+ # TimeEntryActivity is not available
5
+ end
6
+
7
+ # Wrappers around the Redmine core API changes between versions
8
+ module BulkTimeEntryCompatibility
9
+ class Enumeration
10
+ # Wrapper around Redmine's API since Enumerations changed in r2472
11
+ # This can be removed once 0.9.0 is stable
12
+ def self.activities
13
+ if Object.const_defined?('TimeEntryActivity')
14
+ return ::TimeEntryActivity.all
15
+ elsif ::Enumeration.respond_to?(:activities)
16
+ return ::Enumeration.activities
17
+ else
18
+ return ::Enumeration::get_values('ACTI')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ namespace :bulk_time_entry do
2
+ namespace :import do
3
+
4
+ desc "Import mutiple time entries from a CSV file"
5
+ task :csv => [:environment] do
6
+ csv_file = ENV['CSV_FILE'] || File.join(RAILS_ROOT, 'time_entries.csv')
7
+
8
+ puts BulkTimeEntry.import_from_csv(csv_file)
9
+ end
10
+
11
+ end
12
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'redmine'
2
+
3
+ config.gem 'fastercsv' if respond_to? :config
4
+
5
+ Redmine::Plugin.register :bulk_time_entry_plugin do
6
+ name 'Bulk Time Entry'
7
+ author 'Eric Davis'
8
+ description 'This is a plugin to enter multiple time entries at one time.'
9
+ version '0.4.0'
10
+
11
+ menu :top_menu, :bulk_time_entry, {:controller => "bulk_time_entries", :action => 'index'},
12
+ :caption => :bulk_time_entry_title, :if => Proc.new{User.current.allowed_to?(:log_time, nil, :global => true)}
13
+ end
@@ -0,0 +1,44 @@
1
+ require 'test_helper'
2
+
3
+ class BulkTimeEntriesControllerTest < ActionController::TestCase
4
+ context "routing" do
5
+ should_route :get, "/bulk_time_entries", { :action => :index }
6
+ should_route :post, "/bulk_time_entries/save", { :action => :save }
7
+ should_route :post, "/bulk_time_entries/load_assigned_issues", { :action => :load_assigned_issues }
8
+ should_route :post, "/bulk_time_entries/add_entry", { :action => :add_entry }
9
+ end
10
+
11
+ should_have_before_filter :load_activities
12
+ should_have_before_filter :load_allowed_projects
13
+
14
+ context "GET to :index" do
15
+ context "as a user without any projects" do
16
+ setup do
17
+ @user = User.generate_with_protected!
18
+ @request.session[:user_id] = @user.id
19
+
20
+ get :index
21
+ end
22
+
23
+ should_respond_with :success
24
+ should_assign_to :time_entries
25
+ should_assign_to :projects
26
+ should_render_template :no_projects
27
+
28
+ end
29
+
30
+ context "as a user with projects" do
31
+ setup do
32
+ @project = Project.generate!
33
+ generate_user_and_login_for_project(@project)
34
+
35
+ get :index
36
+ end
37
+
38
+ should_respond_with :success
39
+ should_assign_to :time_entries
40
+ should_assign_to :projects
41
+ should_render_template :index
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,50 @@
1
+ # Load the normal Rails helper
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper')
3
+
4
+ # Ensure that we are using the temporary fixture path
5
+ Engines::Testing.set_fixture_path
6
+
7
+ # Helpers
8
+ class ActiveSupport::TestCase
9
+ def setup
10
+ User.anonymous
11
+ non_member = Role.generate!
12
+ non_member.builtin = Role::BUILTIN_NON_MEMBER
13
+ non_member.save!
14
+ end
15
+ end
16
+
17
+ module BulkTimeEntryTestHelper
18
+ def mock_csv_file(name, data='')
19
+ file = mock
20
+ file.stubs(:name).returns(name)
21
+ File.stubs(:read).with(name).returns(data)
22
+ file
23
+ end
24
+
25
+ def generate_csv_data(count=5)
26
+ @activity ||= TimeEntryActivity.generate!
27
+ @user ||= User.generate_with_protected!
28
+
29
+ @project ||= Project.generate!
30
+ @tracker ||= Tracker.generate!
31
+ @project.trackers << @tracker unless @project.trackers.include? @tracker
32
+
33
+ csv_data = []
34
+ 5.times {
35
+ issue = Issue.generate!(:tracker => @tracker, :project => @project)
36
+ csv_data << [issue.id.to_s, 'A comment', Date.today.to_s, @activity.name, (rand * 10).round(2).to_s, @user.login]
37
+ }
38
+ csv_data
39
+ end
40
+ end
41
+
42
+ # Shoulda
43
+ class ActiveSupport::TestCase
44
+ def generate_user_and_login_for_project(project, user_attributes={})
45
+ @user = User.generate_with_protected!(user_attributes)
46
+ @role = Role.generate!(:permissions => Redmine::AccessControl.permissions.collect(&:name))
47
+ @member = Member.create(:project => @project, :user => @user, :roles => [@role])
48
+ @request.session[:user_id] = @user.id
49
+ end
50
+ end
@@ -0,0 +1,118 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ require 'fastercsv'
4
+
5
+ # Failing records are tested in BulkTimeEntryTransaction since Rails
6
+ # can't turn fixture transactions off for a single test case.
7
+ class BulkTimeEntryTest < ActiveSupport::TestCase
8
+ include BulkTimeEntryTestHelper
9
+
10
+ context "#import_from_csv" do
11
+ context "non-readable file" do
12
+ setup do
13
+ @file = '/a/test_file.csv'
14
+ end
15
+
16
+ should 'raise an exception' do
17
+ assert_no_difference 'TimeEntry.count' do
18
+ assert_raises Errno::ENOENT do
19
+ BulkTimeEntry.import_from_csv(@file)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ context "unparsable file" do
26
+ setup do
27
+ @file = mock_csv_file('/csv/invalid.csv',
28
+ 'This is not a csv file. "Nope"')
29
+
30
+ end
31
+
32
+ should 'raise an exception' do
33
+ assert_no_difference 'TimeEntry.count' do
34
+ assert_raises FasterCSV::MalformedCSVError do
35
+ BulkTimeEntry.import_from_csv(@file.name)
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ context "valid file" do
42
+
43
+ should "skip empty lines" do
44
+ @csv_data = generate_csv_data
45
+ @csv_data << ['','','','','','']
46
+ @file = mock_csv_file('/csv/valid.csv',
47
+ @csv_data.collect {|row| row.join(', ')}.join("\n"))
48
+
49
+ assert_difference 'TimeEntry.count', 5 do
50
+ BulkTimeEntry.import_from_csv(@file.name)
51
+ end
52
+
53
+ end
54
+
55
+ should "skip invalid lines" do
56
+ @csv_data = generate_csv_data
57
+ @csv_data << ['','']
58
+ @file = mock_csv_file('/csv/valid.csv',
59
+ @csv_data.collect {|row| row.join(', ')}.join("\n"))
60
+
61
+ @response = ''
62
+ assert_difference 'TimeEntry.count', 5 do
63
+ @response = BulkTimeEntry.import_from_csv(@file.name)
64
+ end
65
+ assert_match /1 records failed to import/, @response
66
+
67
+ end
68
+
69
+ context "with valid imports" do
70
+ setup do
71
+ @csv_data = generate_csv_data
72
+ @file = mock_csv_file('/csv/valid.csv',
73
+ @csv_data.collect {|row| row.join(', ')}.join("\n"))
74
+ end
75
+
76
+ should "import one record per line" do
77
+ assert_difference 'TimeEntry.count', 5 do
78
+ BulkTimeEntry.import_from_csv(@file.name)
79
+ end
80
+ end
81
+
82
+
83
+ should 'create a TimeEntry record' do
84
+ BulkTimeEntry.import_from_csv(@file.name)
85
+ time_entry = TimeEntry.last
86
+ last_csv_entry = @csv_data[-1]
87
+
88
+ assert_equal last_csv_entry[0], time_entry.issue_id.to_s
89
+ assert_equal last_csv_entry[1], time_entry.comments
90
+ assert_equal last_csv_entry[2], time_entry.spent_on.to_s
91
+ assert_equal last_csv_entry[3], time_entry.activity.name
92
+ assert_equal last_csv_entry[4], time_entry.hours.to_s
93
+ assert_equal last_csv_entry[5], time_entry.user.login
94
+ end
95
+
96
+ should 'truncate comments over 255 characters' do
97
+ @csv_data << [
98
+ Issue.last.id.to_s,
99
+ 'A' * 300,
100
+ Date.today.to_s,
101
+ @activity.name,
102
+ 5,
103
+ @user.login
104
+ ]
105
+ @file = mock_csv_file('/csv/valid.csv',
106
+ @csv_data.collect {|row| row.join(', ')}.join("\n"))
107
+
108
+ BulkTimeEntry.import_from_csv(@file.name)
109
+ time_entry = TimeEntry.last
110
+
111
+ assert_match /AAA/, time_entry.comments
112
+ assert_equal 255, time_entry.comments.length
113
+
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ require 'fastercsv'
4
+
5
+ class BulkTimeEntryTransactionTest < ActiveSupport::TestCase
6
+ include BulkTimeEntryTestHelper
7
+ self.use_transactional_fixtures = false # using transactions in code
8
+
9
+ # Need to purge data since it's not in a test transaction
10
+ def self.purge_data
11
+ User.delete_all
12
+ Project.delete_all
13
+ Tracker.delete_all
14
+ Issue.delete_all
15
+ IssueStatus.delete_all
16
+ IssuePriority.delete_all
17
+ TimeEntry.delete_all
18
+ TimeEntryActivity.delete_all
19
+ end
20
+
21
+ setup do
22
+ purge_data
23
+ end
24
+
25
+ context "#import_from_csv" do
26
+ context "with a failing record" do
27
+ setup do
28
+ @csv_data = generate_csv_data
29
+ @csv_data << ['1500','No issue',Date.today.to_s, @activity.name, 4.5, @user.login]
30
+
31
+ @file = mock_csv_file('/csv/missing_issue_id.csv',
32
+ @csv_data.collect {|row| row.join(', ')}.join("\n"))
33
+ end
34
+
35
+ should "rollback the import if any record fails" do
36
+ assert_no_difference 'TimeEntry.count' do
37
+ BulkTimeEntry.import_from_csv(@file.name)
38
+ end
39
+ end
40
+
41
+ should "return the exception's message" do
42
+ message = BulkTimeEntry.import_from_csv(@file.name)
43
+ assert_match /validation failed/i, message
44
+ end
45
+
46
+ should "include ERROR in the exception's message" do
47
+ message = BulkTimeEntry.import_from_csv(@file.name)
48
+ assert_match /ERROR/i, message
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class SanityTest < ActiveSupport::TestCase
4
+ def test_is_sane
5
+ assert true
6
+ end
7
+
8
+ should "be true" do
9
+ assert true
10
+ end
11
+
12
+ should "mixin ObjectDaddy" do
13
+ assert User.included_modules.include?(ObjectDaddy)
14
+ end
15
+
16
+ should "connect to database" do
17
+ User.generate_with_protected!(:firstname => 'Testing connection')
18
+ assert_equal 1, User.count(:all, :conditions => {:firstname => 'Testing connection'})
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulk_time_entry_plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-30 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This is a plugin to enter multiple time entries at one time.
17
+ email: edavis@littlestreamsoftware.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ files:
25
+ - COPYRIGHT.txt
26
+ - CREDITS.txt
27
+ - GPL.txt
28
+ - README.rdoc
29
+ - Rakefile
30
+ - TAGS
31
+ - VERSION
32
+ - app/controllers/bulk_time_entries_controller.rb
33
+ - app/helpers/bulk_time_entries_helper.rb
34
+ - app/models/bulk_time_entry.rb
35
+ - app/views/bulk_time_entries/_issues_selector.html.erb
36
+ - app/views/bulk_time_entries/_time_entry.html.erb
37
+ - app/views/bulk_time_entries/index.html.erb
38
+ - app/views/bulk_time_entries/no_projects.html.erb
39
+ - config/locales/en.yml
40
+ - config/locales/fr.yml
41
+ - config/locales/hu.yml
42
+ - config/locales/it.yml
43
+ - config/locales/ko.yml
44
+ - config/locales/pl.yml
45
+ - init.rb
46
+ - lang/en.yml
47
+ - lang/fr.yml
48
+ - lang/hu.yml
49
+ - lang/it.yml
50
+ - lang/ko.yml
51
+ - lang/pl.yml
52
+ - lib/bulk_time_entry_compatibility.rb
53
+ - lib/tasks/import_from_csv.rake
54
+ - rails/init.rb
55
+ - test/functional/bulk_time_entries_controller_test.rb
56
+ - test/test_helper.rb
57
+ - test/unit/bulk_time_entry_test.rb
58
+ - test/unit/bulk_time_entry_transaction_test.rb
59
+ - test/unit/sanity_test.rb
60
+ has_rdoc: true
61
+ homepage: https://projects.littlestreamsoftware.com/projects/redmine-bte
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project: littlestream
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: This is a plugin to enter multiple time entries at one time.
88
+ test_files:
89
+ - test/test_helper.rb
90
+ - test/unit/bulk_time_entry_transaction_test.rb
91
+ - test/unit/bulk_time_entry_test.rb
92
+ - test/unit/sanity_test.rb
93
+ - test/functional/bulk_time_entries_controller_test.rb