##// END OF EJS Templates
remove trailing white-spaces from test/integration/api_test/time_entries_test.rb....
Toshi MARUYAMA -
r6814:ca7804bcb43c
parent child
Show More
@@ -1,144 +1,144
1 1 # Redmine - project management software
2 # Copyright (C) 2006-2010 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 ApiTest::TimeEntriesTest < ActionController::IntegrationTest
21 21 fixtures :all
22
22
23 23 def setup
24 24 Setting.rest_api_enabled = '1'
25 25 end
26
26
27 27 context "GET /time_entries.xml" do
28 28 should "return time entries" do
29 29 get '/time_entries.xml', {}, :authorization => credentials('jsmith')
30 30 assert_response :success
31 31 assert_equal 'application/xml', @response.content_type
32 32 assert_tag :tag => 'time_entries',
33 33 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
34 34 end
35
35
36 36 context "with limit" do
37 37 should "return limited results" do
38 38 get '/time_entries.xml?limit=2', {}, :authorization => credentials('jsmith')
39 39 assert_response :success
40 40 assert_equal 'application/xml', @response.content_type
41 41 assert_tag :tag => 'time_entries',
42 42 :children => {:count => 2}
43 43 end
44 44 end
45 45 end
46
46
47 47 context "GET /time_entries/2.xml" do
48 48 should "return requested time entry" do
49 49 get '/time_entries/2.xml', {}, :authorization => credentials('jsmith')
50 50 assert_response :success
51 51 assert_equal 'application/xml', @response.content_type
52 52 assert_tag :tag => 'time_entry',
53 53 :child => {:tag => 'id', :content => '2'}
54 54 end
55 55 end
56
56
57 57 context "POST /time_entries.xml" do
58 58 context "with issue_id" do
59 59 should "return create time entry" do
60 60 assert_difference 'TimeEntry.count' do
61 61 post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, :authorization => credentials('jsmith')
62 62 end
63 63 assert_response :created
64 64 assert_equal 'application/xml', @response.content_type
65
65
66 66 entry = TimeEntry.first(:order => 'id DESC')
67 67 assert_equal 'jsmith', entry.user.login
68 68 assert_equal Issue.find(1), entry.issue
69 69 assert_equal Project.find(1), entry.project
70 70 assert_equal Date.parse('2010-12-02'), entry.spent_on
71 71 assert_equal 3.5, entry.hours
72 72 assert_equal TimeEntryActivity.find(11), entry.activity
73 73 end
74 74 end
75
75
76 76 context "with project_id" do
77 77 should "return create time entry" do
78 78 assert_difference 'TimeEntry.count' do
79 79 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, :authorization => credentials('jsmith')
80 80 end
81 81 assert_response :created
82 82 assert_equal 'application/xml', @response.content_type
83
83
84 84 entry = TimeEntry.first(:order => 'id DESC')
85 85 assert_equal 'jsmith', entry.user.login
86 86 assert_nil entry.issue
87 87 assert_equal Project.find(1), entry.project
88 88 assert_equal Date.parse('2010-12-02'), entry.spent_on
89 89 assert_equal 3.5, entry.hours
90 90 assert_equal TimeEntryActivity.find(11), entry.activity
91 91 end
92 92 end
93
93
94 94 context "with invalid parameters" do
95 95 should "return errors" do
96 96 assert_no_difference 'TimeEntry.count' do
97 97 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, :authorization => credentials('jsmith')
98 98 end
99 99 assert_response :unprocessable_entity
100 100 assert_equal 'application/xml', @response.content_type
101 101
102 102 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
103 103 end
104 104 end
105 105 end
106
106
107 107 context "PUT /time_entries/2.xml" do
108 108 context "with valid parameters" do
109 109 should "update time entry" do
110 110 assert_no_difference 'TimeEntry.count' do
111 111 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, :authorization => credentials('jsmith')
112 112 end
113 113 assert_response :ok
114 114 assert_equal 'API Update', TimeEntry.find(2).comments
115 115 end
116 116 end
117 117
118 118 context "with invalid parameters" do
119 119 should "return errors" do
120 120 assert_no_difference 'TimeEntry.count' do
121 121 put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, :authorization => credentials('jsmith')
122 122 end
123 123 assert_response :unprocessable_entity
124 124 assert_equal 'application/xml', @response.content_type
125 125
126 126 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
127 127 end
128 128 end
129 129 end
130
130
131 131 context "DELETE /time_entries/2.xml" do
132 132 should "destroy time entry" do
133 133 assert_difference 'TimeEntry.count', -1 do
134 134 delete '/time_entries/2.xml', {}, :authorization => credentials('jsmith')
135 135 end
136 136 assert_response :ok
137 137 assert_nil TimeEntry.find_by_id(2)
138 138 end
139 139 end
140
140
141 141 def credentials(user, password=nil)
142 142 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
143 143 end
144 144 end
General Comments 0
You need to be logged in to leave comments. Login now