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 / 36 / 367408f1f75021a71b939b14007872b6740672f3.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (4.32 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::VersionsTest < 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 | :versions |
||
| 30 | |||
| 31 | def setup |
||
| 32 | Setting.rest_api_enabled = '1' |
||
| 33 | end |
||
| 34 | |||
| 35 | context "/projects/:project_id/versions" do |
||
| 36 | context "GET" do |
||
| 37 | should "return project versions" do |
||
| 38 | get '/projects/1/versions.xml' |
||
| 39 | |||
| 40 | assert_response :success |
||
| 41 | assert_equal 'application/xml', @response.content_type |
||
| 42 | assert_tag :tag => 'versions', |
||
| 43 | :attributes => {:type => 'array'},
|
||
| 44 | :child => {
|
||
| 45 | :tag => 'version', |
||
| 46 | :child => {
|
||
| 47 | :tag => 'id', |
||
| 48 | :content => '2', |
||
| 49 | :sibling => {
|
||
| 50 | :tag => 'name', |
||
| 51 | :content => '1.0' |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | end |
||
| 56 | end |
||
| 57 | |||
| 58 | context "POST" do |
||
| 59 | should "create the version" do |
||
| 60 | assert_difference 'Version.count' do |
||
| 61 | post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
|
||
| 62 | end |
||
| 63 | |||
| 64 | version = Version.first(:order => 'id DESC') |
||
| 65 | assert_equal 'API test', version.name |
||
| 66 | |||
| 67 | assert_response :created |
||
| 68 | assert_equal 'application/xml', @response.content_type |
||
| 69 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
|
||
| 70 | end |
||
| 71 | |||
| 72 | should "create the version with due date" do |
||
| 73 | assert_difference 'Version.count' do |
||
| 74 | post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
|
||
| 75 | end |
||
| 76 | |||
| 77 | version = Version.first(:order => 'id DESC') |
||
| 78 | assert_equal 'API test', version.name |
||
| 79 | assert_equal Date.parse('2012-01-24'), version.due_date
|
||
| 80 | |||
| 81 | assert_response :created |
||
| 82 | assert_equal 'application/xml', @response.content_type |
||
| 83 | assert_tag 'version', :child => {:tag => 'id', :content => version.id.to_s}
|
||
| 84 | end |
||
| 85 | |||
| 86 | context "with failure" do |
||
| 87 | should "return the errors" do |
||
| 88 | assert_no_difference('Version.count') do
|
||
| 89 | post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
|
||
| 90 | end |
||
| 91 | |||
| 92 | assert_response :unprocessable_entity |
||
| 93 | assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
|
||
| 94 | end |
||
| 95 | end |
||
| 96 | end |
||
| 97 | end |
||
| 98 | |||
| 99 | context "/versions/:id" do |
||
| 100 | context "GET" do |
||
| 101 | should "return the version" do |
||
| 102 | get '/versions/2.xml' |
||
| 103 | |||
| 104 | assert_response :success |
||
| 105 | assert_equal 'application/xml', @response.content_type |
||
| 106 | assert_select 'version' do |
||
| 107 | assert_select 'id', :text => '2' |
||
| 108 | assert_select 'name', :text => '1.0' |
||
| 109 | assert_select 'sharing', :text => 'none' |
||
| 110 | end |
||
| 111 | end |
||
| 112 | end |
||
| 113 | |||
| 114 | context "PUT" do |
||
| 115 | should "update the version" do |
||
| 116 | put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
|
||
| 117 | |||
| 118 | assert_response :ok |
||
| 119 | assert_equal '', @response.body |
||
| 120 | assert_equal 'API update', Version.find(2).name |
||
| 121 | end |
||
| 122 | end |
||
| 123 | |||
| 124 | context "DELETE" do |
||
| 125 | should "destroy the version" do |
||
| 126 | assert_difference 'Version.count', -1 do |
||
| 127 | delete '/versions/3.xml', {}, credentials('jsmith')
|
||
| 128 | end |
||
| 129 | |||
| 130 | assert_response :ok |
||
| 131 | assert_equal '', @response.body |
||
| 132 | assert_nil Version.find_by_id(3) |
||
| 133 | end |
||
| 134 | end |
||
| 135 | end |
||
| 136 | end |