@@ -1,142 +1,142 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class Redmine::ApiTest::TimeEntriesTest < Redmine::ApiTest::Base |
|
21 | 21 | fixtures :projects, :trackers, :issue_statuses, :issues, |
|
22 | 22 | :enumerations, :users, :issue_categories, |
|
23 | 23 | :projects_trackers, |
|
24 | 24 | :roles, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :members, |
|
27 | 27 | :enabled_modules, |
|
28 | 28 | :time_entries |
|
29 | 29 | |
|
30 | 30 | def setup |
|
31 | 31 | Setting.rest_api_enabled = '1' |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | test "GET /time_entries.xml should return time entries" do |
|
35 | 35 | get '/time_entries.xml', {}, credentials('jsmith') |
|
36 | 36 | assert_response :success |
|
37 | 37 | assert_equal 'application/xml', @response.content_type |
|
38 | 38 | assert_tag :tag => 'time_entries', |
|
39 | 39 | :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | test "GET /time_entries.xml with limit should return limited results" do |
|
43 | 43 | get '/time_entries.xml?limit=2', {}, credentials('jsmith') |
|
44 | 44 | assert_response :success |
|
45 | 45 | assert_equal 'application/xml', @response.content_type |
|
46 | 46 | assert_tag :tag => 'time_entries', |
|
47 | 47 | :children => {:count => 2} |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | test "GET /time_entries/:id.xml should return the time entry" do |
|
51 | 51 | get '/time_entries/2.xml', {}, credentials('jsmith') |
|
52 | 52 | assert_response :success |
|
53 | 53 | assert_equal 'application/xml', @response.content_type |
|
54 | 54 | assert_tag :tag => 'time_entry', |
|
55 | 55 | :child => {:tag => 'id', :content => '2'} |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | test "POST /time_entries.xml with issue_id should create time entry" do |
|
59 | 59 | assert_difference 'TimeEntry.count' do |
|
60 | 60 | post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') |
|
61 | 61 | end |
|
62 | 62 | assert_response :created |
|
63 | 63 | assert_equal 'application/xml', @response.content_type |
|
64 | 64 | |
|
65 |
entry = TimeEntry. |
|
|
65 | entry = TimeEntry.order('id DESC').first | |
|
66 | 66 | assert_equal 'jsmith', entry.user.login |
|
67 | 67 | assert_equal Issue.find(1), entry.issue |
|
68 | 68 | assert_equal Project.find(1), entry.project |
|
69 | 69 | assert_equal Date.parse('2010-12-02'), entry.spent_on |
|
70 | 70 | assert_equal 3.5, entry.hours |
|
71 | 71 | assert_equal TimeEntryActivity.find(11), entry.activity |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | test "POST /time_entries.xml with issue_id should accept custom fields" do |
|
75 | 75 | field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') |
|
76 | 76 | |
|
77 | 77 | assert_difference 'TimeEntry.count' do |
|
78 | 78 | post '/time_entries.xml', {:time_entry => { |
|
79 | 79 | :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] |
|
80 | 80 | }}, credentials('jsmith') |
|
81 | 81 | end |
|
82 | 82 | assert_response :created |
|
83 | 83 | assert_equal 'application/xml', @response.content_type |
|
84 | 84 | |
|
85 |
entry = TimeEntry. |
|
|
85 | entry = TimeEntry.order('id DESC').first | |
|
86 | 86 | assert_equal 'accepted', entry.custom_field_value(field) |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | test "POST /time_entries.xml with project_id should create time entry" do |
|
90 | 90 | assert_difference 'TimeEntry.count' do |
|
91 | 91 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') |
|
92 | 92 | end |
|
93 | 93 | assert_response :created |
|
94 | 94 | assert_equal 'application/xml', @response.content_type |
|
95 | 95 | |
|
96 |
entry = TimeEntry. |
|
|
96 | entry = TimeEntry.order('id DESC').first | |
|
97 | 97 | assert_equal 'jsmith', entry.user.login |
|
98 | 98 | assert_nil entry.issue |
|
99 | 99 | assert_equal Project.find(1), entry.project |
|
100 | 100 | assert_equal Date.parse('2010-12-02'), entry.spent_on |
|
101 | 101 | assert_equal 3.5, entry.hours |
|
102 | 102 | assert_equal TimeEntryActivity.find(11), entry.activity |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | test "POST /time_entries.xml with invalid parameters should return errors" do |
|
106 | 106 | assert_no_difference 'TimeEntry.count' do |
|
107 | 107 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') |
|
108 | 108 | end |
|
109 | 109 | assert_response :unprocessable_entity |
|
110 | 110 | assert_equal 'application/xml', @response.content_type |
|
111 | 111 | |
|
112 | 112 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | test "PUT /time_entries/:id.xml with valid parameters should update time entry" do |
|
116 | 116 | assert_no_difference 'TimeEntry.count' do |
|
117 | 117 | put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') |
|
118 | 118 | end |
|
119 | 119 | assert_response :ok |
|
120 | 120 | assert_equal '', @response.body |
|
121 | 121 | assert_equal 'API Update', TimeEntry.find(2).comments |
|
122 | 122 | end |
|
123 | 123 | |
|
124 | 124 | test "PUT /time_entries/:id.xml with invalid parameters should return errors" do |
|
125 | 125 | assert_no_difference 'TimeEntry.count' do |
|
126 | 126 | put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') |
|
127 | 127 | end |
|
128 | 128 | assert_response :unprocessable_entity |
|
129 | 129 | assert_equal 'application/xml', @response.content_type |
|
130 | 130 | |
|
131 | 131 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
|
132 | 132 | end |
|
133 | 133 | |
|
134 | 134 | test "DELETE /time_entries/:id.xml should destroy time entry" do |
|
135 | 135 | assert_difference 'TimeEntry.count', -1 do |
|
136 | 136 | delete '/time_entries/2.xml', {}, credentials('jsmith') |
|
137 | 137 | end |
|
138 | 138 | assert_response :ok |
|
139 | 139 | assert_equal '', @response.body |
|
140 | 140 | assert_nil TimeEntry.find_by_id(2) |
|
141 | 141 | end |
|
142 | 142 | end |
General Comments 0
You need to be logged in to leave comments.
Login now