Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/.svn/text-base/time_entries_test.rb.svn-base @ 119:8661b858af72
* Update to Redmine trunk rev 4705
author | Chris Cannam |
---|---|
date | Thu, 13 Jan 2011 14:12:06 +0000 |
parents | |
children | cbce1fd3b1b7 |
comparison
equal
deleted
inserted
replaced
39:150ceac17a8d | 119:8661b858af72 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2010 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 ApiTest::TimeEntriesTest < ActionController::IntegrationTest | |
21 fixtures :all | |
22 | |
23 def setup | |
24 Setting.rest_api_enabled = '1' | |
25 end | |
26 | |
27 context "GET /time_entries.xml" do | |
28 should "return time entries" do | |
29 get '/time_entries.xml', {}, :authorization => credentials('jsmith') | |
30 assert_response :success | |
31 assert_equal 'application/xml', @response.content_type | |
32 assert_tag :tag => 'time_entries', | |
33 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} | |
34 end | |
35 end | |
36 | |
37 context "GET /time_entries/2.xml" do | |
38 should "return requested time entry" do | |
39 get '/time_entries/2.xml', {}, :authorization => credentials('jsmith') | |
40 assert_response :success | |
41 assert_equal 'application/xml', @response.content_type | |
42 assert_tag :tag => 'time_entry', | |
43 :child => {:tag => 'id', :content => '2'} | |
44 end | |
45 end | |
46 | |
47 context "POST /time_entries.xml" do | |
48 context "with issue_id" do | |
49 should "return create time entry" do | |
50 assert_difference 'TimeEntry.count' do | |
51 post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, :authorization => credentials('jsmith') | |
52 end | |
53 assert_response :created | |
54 assert_equal 'application/xml', @response.content_type | |
55 | |
56 entry = TimeEntry.first(:order => 'id DESC') | |
57 assert_equal 'jsmith', entry.user.login | |
58 assert_equal Issue.find(1), entry.issue | |
59 assert_equal Project.find(1), entry.project | |
60 assert_equal Date.parse('2010-12-02'), entry.spent_on | |
61 assert_equal 3.5, entry.hours | |
62 assert_equal TimeEntryActivity.find(11), entry.activity | |
63 end | |
64 end | |
65 | |
66 context "with project_id" do | |
67 should "return create time entry" do | |
68 assert_difference 'TimeEntry.count' do | |
69 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, :authorization => credentials('jsmith') | |
70 end | |
71 assert_response :created | |
72 assert_equal 'application/xml', @response.content_type | |
73 | |
74 entry = TimeEntry.first(:order => 'id DESC') | |
75 assert_equal 'jsmith', entry.user.login | |
76 assert_nil entry.issue | |
77 assert_equal Project.find(1), entry.project | |
78 assert_equal Date.parse('2010-12-02'), entry.spent_on | |
79 assert_equal 3.5, entry.hours | |
80 assert_equal TimeEntryActivity.find(11), entry.activity | |
81 end | |
82 end | |
83 | |
84 context "with invalid parameters" do | |
85 should "return errors" do | |
86 assert_no_difference 'TimeEntry.count' do | |
87 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, :authorization => credentials('jsmith') | |
88 end | |
89 assert_response :unprocessable_entity | |
90 assert_equal 'application/xml', @response.content_type | |
91 | |
92 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | |
93 end | |
94 end | |
95 end | |
96 | |
97 context "PUT /time_entries/2.xml" do | |
98 context "with valid parameters" do | |
99 should "update time entry" do | |
100 assert_no_difference 'TimeEntry.count' do | |
101 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, :authorization => credentials('jsmith') | |
102 end | |
103 assert_response :ok | |
104 assert_equal 'API Update', TimeEntry.find(2).comments | |
105 end | |
106 end | |
107 | |
108 context "with invalid parameters" do | |
109 should "return errors" do | |
110 assert_no_difference 'TimeEntry.count' do | |
111 put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, :authorization => credentials('jsmith') | |
112 end | |
113 assert_response :unprocessable_entity | |
114 assert_equal 'application/xml', @response.content_type | |
115 | |
116 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | |
117 end | |
118 end | |
119 end | |
120 | |
121 context "DELETE /time_entries/2.xml" do | |
122 should "destroy time entry" do | |
123 assert_difference 'TimeEntry.count', -1 do | |
124 delete '/time_entries/2.xml', {}, :authorization => credentials('jsmith') | |
125 end | |
126 assert_response :ok | |
127 assert_nil TimeEntry.find_by_id(2) | |
128 end | |
129 end | |
130 | |
131 def credentials(user, password=nil) | |
132 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
133 end | |
134 end |