annotate .svn/pristine/f5/f508b6320941de6eae20be7bfdf99da7b0b0462f.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::WikiPagesTest < ActionController::IntegrationTest
Chris@1296 21 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@1296 22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
Chris@1296 23 :wiki_content_versions, :attachments
Chris@1296 24
Chris@1296 25 def setup
Chris@1296 26 Setting.rest_api_enabled = '1'
Chris@1296 27 end
Chris@1296 28
Chris@1296 29 test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
Chris@1296 30 get '/projects/ecookbook/wiki/index.xml'
Chris@1296 31 assert_response 200
Chris@1296 32 assert_equal 'application/xml', response.content_type
Chris@1296 33 assert_select 'wiki_pages[type=array]' do
Chris@1296 34 assert_select 'wiki_page', :count => Wiki.find(1).pages.count
Chris@1296 35 assert_select 'wiki_page' do
Chris@1296 36 assert_select 'title', :text => 'CookBook_documentation'
Chris@1296 37 assert_select 'version', :text => '3'
Chris@1296 38 assert_select 'created_on'
Chris@1296 39 assert_select 'updated_on'
Chris@1296 40 end
Chris@1296 41 assert_select 'wiki_page' do
Chris@1296 42 assert_select 'title', :text => 'Page_with_an_inline_image'
Chris@1296 43 assert_select 'parent[title=?]', 'CookBook_documentation'
Chris@1296 44 end
Chris@1296 45 end
Chris@1296 46 end
Chris@1296 47
Chris@1296 48 test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
Chris@1296 49 get '/projects/ecookbook/wiki/CookBook_documentation.xml'
Chris@1296 50 assert_response 200
Chris@1296 51 assert_equal 'application/xml', response.content_type
Chris@1296 52 assert_select 'wiki_page' do
Chris@1296 53 assert_select 'title', :text => 'CookBook_documentation'
Chris@1296 54 assert_select 'version', :text => '3'
Chris@1296 55 assert_select 'text'
Chris@1296 56 assert_select 'author'
Chris@1296 57 assert_select 'comments'
Chris@1296 58 assert_select 'created_on'
Chris@1296 59 assert_select 'updated_on'
Chris@1296 60 end
Chris@1296 61 end
Chris@1296 62
Chris@1296 63 test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
Chris@1296 64 get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
Chris@1296 65 assert_response 200
Chris@1296 66 assert_equal 'application/xml', response.content_type
Chris@1296 67 assert_select 'wiki_page' do
Chris@1296 68 assert_select 'title', :text => 'Page_with_an_inline_image'
Chris@1296 69 assert_select 'attachments[type=array]' do
Chris@1296 70 assert_select 'attachment' do
Chris@1296 71 assert_select 'id', :text => '3'
Chris@1296 72 assert_select 'filename', :text => 'logo.gif'
Chris@1296 73 end
Chris@1296 74 end
Chris@1296 75 end
Chris@1296 76 end
Chris@1296 77
Chris@1296 78 test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
Chris@1296 79 get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
Chris@1296 80 assert_response 404
Chris@1296 81 assert_equal 'application/xml', response.content_type
Chris@1296 82 end
Chris@1296 83
Chris@1296 84 test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
Chris@1296 85 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
Chris@1296 86 assert_response 200
Chris@1296 87 assert_equal 'application/xml', response.content_type
Chris@1296 88 assert_select 'wiki_page' do
Chris@1296 89 assert_select 'title', :text => 'CookBook_documentation'
Chris@1296 90 assert_select 'version', :text => '2'
Chris@1296 91 assert_select 'text'
Chris@1296 92 assert_select 'author'
Chris@1296 93 assert_select 'created_on'
Chris@1296 94 assert_select 'updated_on'
Chris@1296 95 end
Chris@1296 96 end
Chris@1296 97
Chris@1296 98 test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
Chris@1296 99 Role.anonymous.remove_permission! :view_wiki_edits
Chris@1296 100
Chris@1296 101 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
Chris@1296 102 assert_response 401
Chris@1296 103 assert_equal 'application/xml', response.content_type
Chris@1296 104 end
Chris@1296 105
Chris@1296 106 test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
Chris@1296 107 assert_no_difference 'WikiPage.count' do
Chris@1296 108 assert_difference 'WikiContent::Version.count' do
Chris@1296 109 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
Chris@1296 110 {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
Chris@1296 111 credentials('jsmith')
Chris@1296 112 assert_response 200
Chris@1296 113 end
Chris@1296 114 end
Chris@1296 115
Chris@1296 116 page = WikiPage.find(1)
Chris@1296 117 assert_equal 'New content from API', page.content.text
Chris@1296 118 assert_equal 4, page.content.version
Chris@1296 119 assert_equal 'API update', page.content.comments
Chris@1296 120 assert_equal 'jsmith', page.content.author.login
Chris@1296 121 end
Chris@1296 122
Chris@1296 123 test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
Chris@1296 124 assert_no_difference 'WikiPage.count' do
Chris@1296 125 assert_difference 'WikiContent::Version.count' do
Chris@1296 126 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
Chris@1296 127 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
Chris@1296 128 credentials('jsmith')
Chris@1296 129 assert_response 200
Chris@1296 130 end
Chris@1296 131 end
Chris@1296 132
Chris@1296 133 page = WikiPage.find(1)
Chris@1296 134 assert_equal 'New content from API', page.content.text
Chris@1296 135 assert_equal 4, page.content.version
Chris@1296 136 assert_equal 'API update', page.content.comments
Chris@1296 137 assert_equal 'jsmith', page.content.author.login
Chris@1296 138 end
Chris@1296 139
Chris@1296 140 test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
Chris@1296 141 assert_no_difference 'WikiPage.count' do
Chris@1296 142 assert_no_difference 'WikiContent::Version.count' do
Chris@1296 143 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
Chris@1296 144 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
Chris@1296 145 credentials('jsmith')
Chris@1296 146 assert_response 409
Chris@1296 147 end
Chris@1296 148 end
Chris@1296 149 end
Chris@1296 150
Chris@1296 151 test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
Chris@1296 152 assert_difference 'WikiPage.count' do
Chris@1296 153 assert_difference 'WikiContent::Version.count' do
Chris@1296 154 put '/projects/ecookbook/wiki/New_page_from_API.xml',
Chris@1296 155 {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
Chris@1296 156 credentials('jsmith')
Chris@1296 157 assert_response 201
Chris@1296 158 end
Chris@1296 159 end
Chris@1296 160
Chris@1296 161 page = WikiPage.order('id DESC').first
Chris@1296 162 assert_equal 'New_page_from_API', page.title
Chris@1296 163 assert_equal 'New content from API', page.content.text
Chris@1296 164 assert_equal 1, page.content.version
Chris@1296 165 assert_equal 'API create', page.content.comments
Chris@1296 166 assert_equal 'jsmith', page.content.author.login
Chris@1296 167 assert_nil page.parent
Chris@1296 168 end
Chris@1296 169
Chris@1296 170 test "PUT /projects/:project_id/wiki/:title.xml with parent" do
Chris@1296 171 assert_difference 'WikiPage.count' do
Chris@1296 172 assert_difference 'WikiContent::Version.count' do
Chris@1296 173 put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
Chris@1296 174 {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
Chris@1296 175 credentials('jsmith')
Chris@1296 176 assert_response 201
Chris@1296 177 end
Chris@1296 178 end
Chris@1296 179
Chris@1296 180 page = WikiPage.order('id DESC').first
Chris@1296 181 assert_equal 'New_subpage_from_API', page.title
Chris@1296 182 assert_equal WikiPage.find(1), page.parent
Chris@1296 183 end
Chris@1296 184
Chris@1296 185 test "DELETE /projects/:project_id/wiki/:title.xml should destroy the page" do
Chris@1296 186 assert_difference 'WikiPage.count', -1 do
Chris@1296 187 delete '/projects/ecookbook/wiki/CookBook_documentation.xml', {}, credentials('jsmith')
Chris@1296 188 assert_response 200
Chris@1296 189 end
Chris@1296 190
Chris@1296 191 assert_nil WikiPage.find_by_id(1)
Chris@1296 192 end
Chris@1296 193 end