annotate .svn/pristine/e1/e13988310e901a19cc8571a0b64f670e6e88c02b.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents 038ba2d95de8
children
rev   line source
Chris@1296 1 # Redmine - project management software
Chris@1296 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1296 3 #
Chris@1296 4 # This program is free software; you can redistribute it and/or
Chris@1296 5 # modify it under the terms of the GNU General Public License
Chris@1296 6 # as published by the Free Software Foundation; either version 2
Chris@1296 7 # of the License, or (at your option) any later version.
Chris@1296 8 #
Chris@1296 9 # This program is distributed in the hope that it will be useful,
Chris@1296 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1296 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1296 12 # GNU General Public License for more details.
Chris@1296 13 #
Chris@1296 14 # You should have received a copy of the GNU General Public License
Chris@1296 15 # along with this program; if not, write to the Free Software
Chris@1296 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1296 17
Chris@1296 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@1296 19
Chris@1296 20 class ApiTest::TimeEntriesTest < ActionController::IntegrationTest
Chris@1296 21 fixtures :projects, :trackers, :issue_statuses, :issues,
Chris@1296 22 :enumerations, :users, :issue_categories,
Chris@1296 23 :projects_trackers,
Chris@1296 24 :roles,
Chris@1296 25 :member_roles,
Chris@1296 26 :members,
Chris@1296 27 :enabled_modules,
Chris@1296 28 :workflows,
Chris@1296 29 :time_entries
Chris@1296 30
Chris@1296 31 def setup
Chris@1296 32 Setting.rest_api_enabled = '1'
Chris@1296 33 end
Chris@1296 34
Chris@1296 35 context "GET /time_entries.xml" do
Chris@1296 36 should "return time entries" do
Chris@1296 37 get '/time_entries.xml', {}, credentials('jsmith')
Chris@1296 38 assert_response :success
Chris@1296 39 assert_equal 'application/xml', @response.content_type
Chris@1296 40 assert_tag :tag => 'time_entries',
Chris@1296 41 :child => {:tag => 'time_entry', :child => {:tag => 'id', :content => '2'}}
Chris@1296 42 end
Chris@1296 43
Chris@1296 44 context "with limit" do
Chris@1296 45 should "return limited results" do
Chris@1296 46 get '/time_entries.xml?limit=2', {}, credentials('jsmith')
Chris@1296 47 assert_response :success
Chris@1296 48 assert_equal 'application/xml', @response.content_type
Chris@1296 49 assert_tag :tag => 'time_entries',
Chris@1296 50 :children => {:count => 2}
Chris@1296 51 end
Chris@1296 52 end
Chris@1296 53 end
Chris@1296 54
Chris@1296 55 context "GET /time_entries/2.xml" do
Chris@1296 56 should "return requested time entry" do
Chris@1296 57 get '/time_entries/2.xml', {}, credentials('jsmith')
Chris@1296 58 assert_response :success
Chris@1296 59 assert_equal 'application/xml', @response.content_type
Chris@1296 60 assert_tag :tag => 'time_entry',
Chris@1296 61 :child => {:tag => 'id', :content => '2'}
Chris@1296 62 end
Chris@1296 63 end
Chris@1296 64
Chris@1296 65 context "POST /time_entries.xml" do
Chris@1296 66 context "with issue_id" do
Chris@1296 67 should "return create time entry" do
Chris@1296 68 assert_difference 'TimeEntry.count' do
Chris@1296 69 post '/time_entries.xml', {:time_entry => {:issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
Chris@1296 70 end
Chris@1296 71 assert_response :created
Chris@1296 72 assert_equal 'application/xml', @response.content_type
Chris@1296 73
Chris@1296 74 entry = TimeEntry.first(:order => 'id DESC')
Chris@1296 75 assert_equal 'jsmith', entry.user.login
Chris@1296 76 assert_equal Issue.find(1), entry.issue
Chris@1296 77 assert_equal Project.find(1), entry.project
Chris@1296 78 assert_equal Date.parse('2010-12-02'), entry.spent_on
Chris@1296 79 assert_equal 3.5, entry.hours
Chris@1296 80 assert_equal TimeEntryActivity.find(11), entry.activity
Chris@1296 81 end
Chris@1296 82
Chris@1296 83 should "accept custom fields" do
Chris@1296 84 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'string')
Chris@1296 85
Chris@1296 86 assert_difference 'TimeEntry.count' do
Chris@1296 87 post '/time_entries.xml', {:time_entry => {
Chris@1296 88 :issue_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11', :custom_fields => [{:id => field.id.to_s, :value => 'accepted'}]
Chris@1296 89 }}, credentials('jsmith')
Chris@1296 90 end
Chris@1296 91 assert_response :created
Chris@1296 92 assert_equal 'application/xml', @response.content_type
Chris@1296 93
Chris@1296 94 entry = TimeEntry.first(:order => 'id DESC')
Chris@1296 95 assert_equal 'accepted', entry.custom_field_value(field)
Chris@1296 96 end
Chris@1296 97 end
Chris@1296 98
Chris@1296 99 context "with project_id" do
Chris@1296 100 should "return create time entry" do
Chris@1296 101 assert_difference 'TimeEntry.count' do
Chris@1296 102 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :hours => '3.5', :activity_id => '11'}}, credentials('jsmith')
Chris@1296 103 end
Chris@1296 104 assert_response :created
Chris@1296 105 assert_equal 'application/xml', @response.content_type
Chris@1296 106
Chris@1296 107 entry = TimeEntry.first(:order => 'id DESC')
Chris@1296 108 assert_equal 'jsmith', entry.user.login
Chris@1296 109 assert_nil entry.issue
Chris@1296 110 assert_equal Project.find(1), entry.project
Chris@1296 111 assert_equal Date.parse('2010-12-02'), entry.spent_on
Chris@1296 112 assert_equal 3.5, entry.hours
Chris@1296 113 assert_equal TimeEntryActivity.find(11), entry.activity
Chris@1296 114 end
Chris@1296 115 end
Chris@1296 116
Chris@1296 117 context "with invalid parameters" do
Chris@1296 118 should "return errors" do
Chris@1296 119 assert_no_difference 'TimeEntry.count' do
Chris@1296 120 post '/time_entries.xml', {:time_entry => {:project_id => '1', :spent_on => '2010-12-02', :activity_id => '11'}}, credentials('jsmith')
Chris@1296 121 end
Chris@1296 122 assert_response :unprocessable_entity
Chris@1296 123 assert_equal 'application/xml', @response.content_type
Chris@1296 124
Chris@1296 125 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
Chris@1296 126 end
Chris@1296 127 end
Chris@1296 128 end
Chris@1296 129
Chris@1296 130 context "PUT /time_entries/2.xml" do
Chris@1296 131 context "with valid parameters" do
Chris@1296 132 should "update time entry" do
Chris@1296 133 assert_no_difference 'TimeEntry.count' do
Chris@1296 134 put '/time_entries/2.xml', {:time_entry => {:comments => 'API Update'}}, credentials('jsmith')
Chris@1296 135 end
Chris@1296 136 assert_response :ok
Chris@1296 137 assert_equal '', @response.body
Chris@1296 138 assert_equal 'API Update', TimeEntry.find(2).comments
Chris@1296 139 end
Chris@1296 140 end
Chris@1296 141
Chris@1296 142 context "with invalid parameters" do
Chris@1296 143 should "return errors" do
Chris@1296 144 assert_no_difference 'TimeEntry.count' do
Chris@1296 145 put '/time_entries/2.xml', {:time_entry => {:hours => '', :comments => 'API Update'}}, credentials('jsmith')
Chris@1296 146 end
Chris@1296 147 assert_response :unprocessable_entity
Chris@1296 148 assert_equal 'application/xml', @response.content_type
Chris@1296 149
Chris@1296 150 assert_tag 'errors', :child => {:tag => 'error', :content => "Hours can't be blank"}
Chris@1296 151 end
Chris@1296 152 end
Chris@1296 153 end
Chris@1296 154
Chris@1296 155 context "DELETE /time_entries/2.xml" do
Chris@1296 156 should "destroy time entry" do
Chris@1296 157 assert_difference 'TimeEntry.count', -1 do
Chris@1296 158 delete '/time_entries/2.xml', {}, credentials('jsmith')
Chris@1296 159 end
Chris@1296 160 assert_response :ok
Chris@1296 161 assert_equal '', @response.body
Chris@1296 162 assert_nil TimeEntry.find_by_id(2)
Chris@1296 163 end
Chris@1296 164 end
Chris@1296 165 end