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