Mercurial > hg > soundsoftware-site
comparison test/integration/api_test/time_entries_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2010 Jean-Philippe Lang | 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 :projects, :trackers, :issue_statuses, :issues, |
22 | 22 :enumerations, :users, :issue_categories, |
23 :projects_trackers, | |
24 :roles, | |
25 :member_roles, | |
26 :members, | |
27 :enabled_modules, | |
28 :workflows, | |
29 :time_entries | |
30 | |
23 def setup | 31 def setup |
24 Setting.rest_api_enabled = '1' | 32 Setting.rest_api_enabled = '1' |
25 end | 33 end |
26 | 34 |
27 context "GET /time_entries.xml" do | 35 context "GET /time_entries.xml" do |
28 should "return time entries" do | 36 should "return time entries" do |
29 get '/time_entries.xml', {}, :authorization => credentials('jsmith') | 37 get '/time_entries.xml', {}, :authorization => credentials('jsmith') |
30 assert_response :success | 38 assert_response :success |
31 assert_equal 'application/xml', @response.content_type | 39 assert_equal 'application/xml', @response.content_type |
32 assert_tag :tag => 'time_entries', | 40 assert_tag :tag => 'time_entries', |
33 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} | 41 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}} |
34 end | 42 end |
35 | 43 |
36 context "with limit" do | 44 context "with limit" do |
37 should "return limited results" do | 45 should "return limited results" do |
38 get '/time_entries.xml?limit=2', {}, :authorization => credentials('jsmith') | 46 get '/time_entries.xml?limit=2', {}, :authorization => credentials('jsmith') |
39 assert_response :success | 47 assert_response :success |
40 assert_equal 'application/xml', @response.content_type | 48 assert_equal 'application/xml', @response.content_type |
41 assert_tag :tag => 'time_entries', | 49 assert_tag :tag => 'time_entries', |
42 :children => {:count => 2} | 50 :children => {:count => 2} |
43 end | 51 end |
44 end | 52 end |
45 end | 53 end |
46 | 54 |
47 context "GET /time_entries/2.xml" do | 55 context "GET /time_entries/2.xml" do |
48 should "return requested time entry" do | 56 should "return requested time entry" do |
49 get '/time_entries/2.xml', {}, :authorization => credentials('jsmith') | 57 get '/time_entries/2.xml', {}, :authorization => credentials('jsmith') |
50 assert_response :success | 58 assert_response :success |
51 assert_equal 'application/xml', @response.content_type | 59 assert_equal 'application/xml', @response.content_type |
52 assert_tag :tag => 'time_entry', | 60 assert_tag :tag => 'time_entry', |
53 :child => {:tag => 'id', :content => '2'} | 61 :child => {:tag => 'id', :content => '2'} |
54 end | 62 end |
55 end | 63 end |
56 | 64 |
57 context "POST /time_entries.xml" do | 65 context "POST /time_entries.xml" do |
58 context "with issue_id" do | 66 context "with issue_id" do |
59 should "return create time entry" do | 67 should "return create time entry" do |
60 assert_difference 'TimeEntry.count' do | 68 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') | 69 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 | 70 end |
63 assert_response :created | 71 assert_response :created |
64 assert_equal 'application/xml', @response.content_type | 72 assert_equal 'application/xml', @response.content_type |
65 | 73 |
66 entry = TimeEntry.first(:order => 'id DESC') | 74 entry = TimeEntry.first(:order => 'id DESC') |
67 assert_equal 'jsmith', entry.user.login | 75 assert_equal 'jsmith', entry.user.login |
68 assert_equal Issue.find(1), entry.issue | 76 assert_equal Issue.find(1), entry.issue |
69 assert_equal Project.find(1), entry.project | 77 assert_equal Project.find(1), entry.project |
70 assert_equal Date.parse('2010-12-02'), entry.spent_on | 78 assert_equal Date.parse('2010-12-02'), entry.spent_on |
71 assert_equal 3.5, entry.hours | 79 assert_equal 3.5, entry.hours |
72 assert_equal TimeEntryActivity.find(11), entry.activity | 80 assert_equal TimeEntryActivity.find(11), entry.activity |
73 end | 81 end |
74 end | 82 end |
75 | 83 |
76 context "with project_id" do | 84 context "with project_id" do |
77 should "return create time entry" do | 85 should "return create time entry" do |
78 assert_difference 'TimeEntry.count' do | 86 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') | 87 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 | 88 end |
81 assert_response :created | 89 assert_response :created |
82 assert_equal 'application/xml', @response.content_type | 90 assert_equal 'application/xml', @response.content_type |
83 | 91 |
84 entry = TimeEntry.first(:order => 'id DESC') | 92 entry = TimeEntry.first(:order => 'id DESC') |
85 assert_equal 'jsmith', entry.user.login | 93 assert_equal 'jsmith', entry.user.login |
86 assert_nil entry.issue | 94 assert_nil entry.issue |
87 assert_equal Project.find(1), entry.project | 95 assert_equal Project.find(1), entry.project |
88 assert_equal Date.parse('2010-12-02'), entry.spent_on | 96 assert_equal Date.parse('2010-12-02'), entry.spent_on |
89 assert_equal 3.5, entry.hours | 97 assert_equal 3.5, entry.hours |
90 assert_equal TimeEntryActivity.find(11), entry.activity | 98 assert_equal TimeEntryActivity.find(11), entry.activity |
91 end | 99 end |
92 end | 100 end |
93 | 101 |
94 context "with invalid parameters" do | 102 context "with invalid parameters" do |
95 should "return errors" do | 103 should "return errors" do |
96 assert_no_difference 'TimeEntry.count' do | 104 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') | 105 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, :authorization => credentials('jsmith') |
98 end | 106 end |
101 | 109 |
102 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | 110 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
103 end | 111 end |
104 end | 112 end |
105 end | 113 end |
106 | 114 |
107 context "PUT /time_entries/2.xml" do | 115 context "PUT /time_entries/2.xml" do |
108 context "with valid parameters" do | 116 context "with valid parameters" do |
109 should "update time entry" do | 117 should "update time entry" do |
110 assert_no_difference 'TimeEntry.count' do | 118 assert_no_difference 'TimeEntry.count' do |
111 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, :authorization => credentials('jsmith') | 119 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, :authorization => credentials('jsmith') |
125 | 133 |
126 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} | 134 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"} |
127 end | 135 end |
128 end | 136 end |
129 end | 137 end |
130 | 138 |
131 context "DELETE /time_entries/2.xml" do | 139 context "DELETE /time_entries/2.xml" do |
132 should "destroy time entry" do | 140 should "destroy time entry" do |
133 assert_difference 'TimeEntry.count', -1 do | 141 assert_difference 'TimeEntry.count', -1 do |
134 delete '/time_entries/2.xml', {}, :authorization => credentials('jsmith') | 142 delete '/time_entries/2.xml', {}, :authorization => credentials('jsmith') |
135 end | 143 end |
136 assert_response :ok | 144 assert_response :ok |
137 assert_nil TimeEntry.find_by_id(2) | 145 assert_nil TimeEntry.find_by_id(2) |
138 end | 146 end |
139 end | 147 end |
140 | 148 |
141 def credentials(user, password=nil) | 149 def credentials(user, password=nil) |
142 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | 150 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
143 end | 151 end |
144 end | 152 end |