Mercurial > hg > soundsoftware-site
comparison .svn/pristine/c6/c620273a13fb0c5f40f2c943a9b0b5bb40f34369.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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 context "GET /time_entries.xml" do | |
35 should "return time entries" do | |
36 get '/time_entries.xml', {}, credentials('jsmith') | |
37 assert_response :success | |
38 assert_equal 'application/xml', @response.content_type | |
39 assert_tag :tag => 'time_entries', | |
40 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} | |
41 end | |
42 | |
43 context "with limit" do | |
44 should "return limited results" do | |
45 get '/time_entries.xml?limit=2', {}, credentials('jsmith') | |
46 assert_response :success | |
47 assert_equal 'application/xml', @response.content_type | |
48 assert_tag :tag => 'time_entries', | |
49 :children => {:count => 2} | |
50 end | |
51 end | |
52 end | |
53 | |
54 context "GET /time_entries/2.xml" do | |
55 should "return requested time entry" do | |
56 get '/time_entries/2.xml', {}, credentials('jsmith') | |
57 assert_response :success | |
58 assert_equal 'application/xml', @response.content_type | |
59 assert_tag :tag => 'time_entry', | |
60 :child => {:tag => 'id', :content => '2'} | |
61 end | |
62 end | |
63 | |
64 context "POST /time_entries.xml" do | |
65 context "with issue_id" do | |
66 should "return create time entry" do | |
67 assert_difference 'TimeEntry.count' do | |
68 post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') | |
69 end | |
70 assert_response :created | |
71 assert_equal 'application/xml', @response.content_type | |
72 | |
73 entry = TimeEntry.first(:order => 'id DESC') | |
74 assert_equal 'jsmith', entry.user.login | |
75 assert_equal Issue.find(1), entry.issue | |
76 assert_equal Project.find(1), entry.project | |
77 assert_equal Date.parse('2010-12-02'), entry.spent_on | |
78 assert_equal 3.5, entry.hours | |
79 assert_equal TimeEntryActivity.find(11), entry.activity | |
80 end | |
81 | |
82 should "accept custom fields" do | |
83 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') | |
84 | |
85 assert_difference 'TimeEntry.count' do | |
86 post '/time_entries.xml', {:time_entry => { | |
87 :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}] | |
88 }}, credentials('jsmith') | |
89 end | |
90 assert_response :created | |
91 assert_equal 'application/xml', @response.content_type | |
92 | |
93 entry = TimeEntry.first(:order => 'id DESC') | |
94 assert_equal 'accepted', entry.custom_field_value(field) | |
95 end | |
96 end | |
97 | |
98 context "with project_id" do | |
99 should "return create time entry" do | |
100 assert_difference 'TimeEntry.count' do | |
101 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith') | |
102 end | |
103 assert_response :created | |
104 assert_equal 'application/xml', @response.content_type | |
105 | |
106 entry = TimeEntry.first(:order => 'id DESC') | |
107 assert_equal 'jsmith', entry.user.login | |
108 assert_nil entry.issue | |
109 assert_equal Project.find(1), entry.project | |
110 assert_equal Date.parse('2010-12-02'), entry.spent_on | |
111 assert_equal 3.5, entry.hours | |
112 assert_equal TimeEntryActivity.find(11), entry.activity | |
113 end | |
114 end | |
115 | |
116 context "with invalid parameters" do | |
117 should "return errors" do | |
118 assert_no_difference 'TimeEntry.count' do | |
119 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith') | |
120 end | |
121 assert_response :unprocessable_entity | |
122 assert_equal 'application/xml', @response.content_type | |
123 | |
124 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | |
125 end | |
126 end | |
127 end | |
128 | |
129 context "PUT /time_entries/2.xml" do | |
130 context "with valid parameters" do | |
131 should "update time entry" do | |
132 assert_no_difference 'TimeEntry.count' do | |
133 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith') | |
134 end | |
135 assert_response :ok | |
136 assert_equal '', @response.body | |
137 assert_equal 'API Update', TimeEntry.find(2).comments | |
138 end | |
139 end | |
140 | |
141 context "with invalid parameters" do | |
142 should "return errors" do | |
143 assert_no_difference 'TimeEntry.count' do | |
144 put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith') | |
145 end | |
146 assert_response :unprocessable_entity | |
147 assert_equal 'application/xml', @response.content_type | |
148 | |
149 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | |
150 end | |
151 end | |
152 end | |
153 | |
154 context "DELETE /time_entries/2.xml" do | |
155 should "destroy time entry" do | |
156 assert_difference 'TimeEntry.count', -1 do | |
157 delete '/time_entries/2.xml', {}, credentials('jsmith') | |
158 end | |
159 assert_response :ok | |
160 assert_equal '', @response.body | |
161 assert_nil TimeEntry.find_by_id(2) | |
162 end | |
163 end | |
164 end |