To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / e1 / e13988310e901a19cc8571a0b64f670e6e88c02b.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (6.13 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 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 :projects, :trackers, :issue_statuses, :issues, |
||
| 22 | :enumerations, :users, :issue_categories, |
||
| 23 | :projects_trackers, |
||
| 24 | :roles, |
||
| 25 | :member_roles, |
||
| 26 | :members, |
||
| 27 | :enabled_modules, |
||
| 28 | :workflows, |
||
| 29 | :time_entries |
||
| 30 | |||
| 31 | def setup |
||
| 32 | Setting.rest_api_enabled = '1' |
||
| 33 | end |
||
| 34 | |||
| 35 | context "GET /time_entries.xml" do |
||
| 36 | should "return time entries" do |
||
| 37 | get '/time_entries.xml', {}, credentials('jsmith')
|
||
| 38 | assert_response :success |
||
| 39 | assert_equal 'application/xml', @response.content_type |
||
| 40 | assert_tag :tag => 'time_entries', |
||
| 41 | :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
|
||
| 42 | end |
||
| 43 | |||
| 44 | context "with limit" do |
||
| 45 | should "return limited results" do |
||
| 46 | get '/time_entries.xml?limit=2', {}, credentials('jsmith')
|
||
| 47 | assert_response :success |
||
| 48 | assert_equal 'application/xml', @response.content_type |
||
| 49 | assert_tag :tag => 'time_entries', |
||
| 50 | :children => {:count => 2}
|
||
| 51 | end |
||
| 52 | end |
||
| 53 | end |
||
| 54 | |||
| 55 | context "GET /time_entries/2.xml" do |
||
| 56 | should "return requested time entry" do |
||
| 57 | get '/time_entries/2.xml', {}, credentials('jsmith')
|
||
| 58 | assert_response :success |
||
| 59 | assert_equal 'application/xml', @response.content_type |
||
| 60 | assert_tag :tag => 'time_entry', |
||
| 61 | :child => {:tag => 'id', :content => '2'}
|
||
| 62 | end |
||
| 63 | end |
||
| 64 | |||
| 65 | context "POST /time_entries.xml" do |
||
| 66 | context "with issue_id" do |
||
| 67 | should "return create time entry" do |
||
| 68 | assert_difference 'TimeEntry.count' do |
||
| 69 | post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, 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_equal Issue.find(1), 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 | |||
| 83 | should "accept custom fields" do |
||
| 84 | field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string') |
||
| 85 | |||
| 86 | assert_difference 'TimeEntry.count' do |
||
| 87 | post '/time_entries.xml', {:time_entry => {
|
||
| 88 | :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
|
||
| 89 | }}, credentials('jsmith')
|
||
| 90 | end |
||
| 91 | assert_response :created |
||
| 92 | assert_equal 'application/xml', @response.content_type |
||
| 93 | |||
| 94 | entry = TimeEntry.first(:order => 'id DESC') |
||
| 95 | assert_equal 'accepted', entry.custom_field_value(field) |
||
| 96 | end |
||
| 97 | end |
||
| 98 | |||
| 99 | context "with project_id" do |
||
| 100 | should "return create time entry" do |
||
| 101 | assert_difference 'TimeEntry.count' do |
||
| 102 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
|
||
| 103 | end |
||
| 104 | assert_response :created |
||
| 105 | assert_equal 'application/xml', @response.content_type |
||
| 106 | |||
| 107 | entry = TimeEntry.first(:order => 'id DESC') |
||
| 108 | assert_equal 'jsmith', entry.user.login |
||
| 109 | assert_nil entry.issue |
||
| 110 | assert_equal Project.find(1), entry.project |
||
| 111 | assert_equal Date.parse('2010-12-02'), entry.spent_on
|
||
| 112 | assert_equal 3.5, entry.hours |
||
| 113 | assert_equal TimeEntryActivity.find(11), entry.activity |
||
| 114 | end |
||
| 115 | end |
||
| 116 | |||
| 117 | context "with invalid parameters" do |
||
| 118 | should "return errors" do |
||
| 119 | assert_no_difference 'TimeEntry.count' do |
||
| 120 | post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
|
||
| 121 | end |
||
| 122 | assert_response :unprocessable_entity |
||
| 123 | assert_equal 'application/xml', @response.content_type |
||
| 124 | |||
| 125 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
|
||
| 126 | end |
||
| 127 | end |
||
| 128 | end |
||
| 129 | |||
| 130 | context "PUT /time_entries/2.xml" do |
||
| 131 | context "with valid parameters" do |
||
| 132 | should "update time entry" do |
||
| 133 | assert_no_difference 'TimeEntry.count' do |
||
| 134 | put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
|
||
| 135 | end |
||
| 136 | assert_response :ok |
||
| 137 | assert_equal '', @response.body |
||
| 138 | assert_equal 'API Update', TimeEntry.find(2).comments |
||
| 139 | end |
||
| 140 | end |
||
| 141 | |||
| 142 | context "with invalid parameters" do |
||
| 143 | should "return errors" do |
||
| 144 | assert_no_difference 'TimeEntry.count' do |
||
| 145 | put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
|
||
| 146 | end |
||
| 147 | assert_response :unprocessable_entity |
||
| 148 | assert_equal 'application/xml', @response.content_type |
||
| 149 | |||
| 150 | assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
|
||
| 151 | end |
||
| 152 | end |
||
| 153 | end |
||
| 154 | |||
| 155 | context "DELETE /time_entries/2.xml" do |
||
| 156 | should "destroy time entry" do |
||
| 157 | assert_difference 'TimeEntry.count', -1 do |
||
| 158 | delete '/time_entries/2.xml', {}, credentials('jsmith')
|
||
| 159 | end |
||
| 160 | assert_response :ok |
||
| 161 | assert_equal '', @response.body |
||
| 162 | assert_nil TimeEntry.find_by_id(2) |
||
| 163 | end |
||
| 164 | end |
||
| 165 | end |