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