annotate .svn/pristine/83/83a6c1abeba887b79e2fd9c64a9251e777da8dcb.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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