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