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