##// END OF EJS Templates
Adds ?include=attachments option when retrieving a wiki page with the REST API (#7082)....
Jean-Philippe Lang -
r10506:03062394fcad
parent child
Show More
@@ -1,11 +1,17
1 1 api.wiki_page do
2 2 api.title @page.title
3 3 if @page.parent
4 4 api.parent :title => @page.parent.title
5 5 end
6 6 api.text @content.text
7 7 api.version @content.version
8 8 api.author(:id => @content.author_id, :name => @content.author.name)
9 9 api.created_on @page.created_on
10 10 api.updated_on @content.updated_on
11
12 api.array :attachments do
13 @page.attachments.each do |attachment|
14 render_api_attachment(attachment, api)
15 end
16 end if include_in_api_response?('attachments')
11 17 end
@@ -1,168 +1,183
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../../test_helper', __FILE__)
19 19
20 20 class ApiTest::WikiPagesTest < ActionController::IntegrationTest
21 21 fixtures :projects, :users, :roles, :members, :member_roles,
22 22 :enabled_modules, :wikis, :wiki_pages, :wiki_contents,
23 23 :wiki_content_versions, :attachments
24 24
25 25 def setup
26 26 Setting.rest_api_enabled = '1'
27 27 end
28 28
29 29 test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
30 30 get '/projects/ecookbook/wiki/index.xml'
31 31 assert_response 200
32 32 assert_equal 'application/xml', response.content_type
33 33 assert_select 'wiki_pages[type=array]' do
34 34 assert_select 'wiki_page', :count => Wiki.find(1).pages.count
35 35 assert_select 'wiki_page' do
36 36 assert_select 'title', :text => 'CookBook_documentation'
37 37 assert_select 'version', :text => '3'
38 38 assert_select 'created_on'
39 39 assert_select 'updated_on'
40 40 end
41 41 assert_select 'wiki_page' do
42 42 assert_select 'title', :text => 'Page_with_an_inline_image'
43 43 assert_select 'parent[title=?]', 'CookBook_documentation'
44 44 end
45 45 end
46 46 end
47 47
48 48 test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
49 49 get '/projects/ecookbook/wiki/CookBook_documentation.xml'
50 50 assert_response 200
51 51 assert_equal 'application/xml', response.content_type
52 52 assert_select 'wiki_page' do
53 53 assert_select 'title', :text => 'CookBook_documentation'
54 54 assert_select 'version', :text => '3'
55 55 assert_select 'text'
56 56 assert_select 'author'
57 57 assert_select 'created_on'
58 58 assert_select 'updated_on'
59 59 end
60 60 end
61 61
62 test "GET /projects/:project_id/wiki/:title.xml?include=attachments should include attachments" do
63 get '/projects/ecookbook/wiki/Page_with_an_inline_image.xml?include=attachments'
64 assert_response 200
65 assert_equal 'application/xml', response.content_type
66 assert_select 'wiki_page' do
67 assert_select 'title', :text => 'Page_with_an_inline_image'
68 assert_select 'attachments[type=array]' do
69 assert_select 'attachment' do
70 assert_select 'id', :text => '3'
71 assert_select 'filename', :text => 'logo.gif'
72 end
73 end
74 end
75 end
76
62 77 test "GET /projects/:project_id/wiki/:title.xml with unknown title and edit permission should respond with 404" do
63 78 get '/projects/ecookbook/wiki/Invalid_Page.xml', {}, credentials('jsmith')
64 79 assert_response 404
65 80 assert_equal 'application/xml', response.content_type
66 81 end
67 82
68 83 test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
69 84 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
70 85 assert_response 200
71 86 assert_equal 'application/xml', response.content_type
72 87 assert_select 'wiki_page' do
73 88 assert_select 'title', :text => 'CookBook_documentation'
74 89 assert_select 'version', :text => '2'
75 90 assert_select 'text'
76 91 assert_select 'author'
77 92 assert_select 'created_on'
78 93 assert_select 'updated_on'
79 94 end
80 95 end
81 96
82 97 test "GET /projects/:project_id/wiki/:title/:version.xml without permission should be denied" do
83 98 Role.anonymous.remove_permission! :view_wiki_edits
84 99
85 100 get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
86 101 assert_response 401
87 102 assert_equal 'application/xml', response.content_type
88 103 end
89 104
90 105 test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
91 106 assert_no_difference 'WikiPage.count' do
92 107 assert_difference 'WikiContent::Version.count' do
93 108 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
94 109 {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
95 110 credentials('jsmith')
96 111 assert_response 200
97 112 end
98 113 end
99 114
100 115 page = WikiPage.find(1)
101 116 assert_equal 'New content from API', page.content.text
102 117 assert_equal 4, page.content.version
103 118 assert_equal 'API update', page.content.comments
104 119 assert_equal 'jsmith', page.content.author.login
105 120 end
106 121
107 122 test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
108 123 assert_no_difference 'WikiPage.count' do
109 124 assert_difference 'WikiContent::Version.count' do
110 125 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
111 126 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
112 127 credentials('jsmith')
113 128 assert_response 200
114 129 end
115 130 end
116 131
117 132 page = WikiPage.find(1)
118 133 assert_equal 'New content from API', page.content.text
119 134 assert_equal 4, page.content.version
120 135 assert_equal 'API update', page.content.comments
121 136 assert_equal 'jsmith', page.content.author.login
122 137 end
123 138
124 139 test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
125 140 assert_no_difference 'WikiPage.count' do
126 141 assert_no_difference 'WikiContent::Version.count' do
127 142 put '/projects/ecookbook/wiki/CookBook_documentation.xml',
128 143 {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
129 144 credentials('jsmith')
130 145 assert_response 409
131 146 end
132 147 end
133 148 end
134 149
135 150 test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
136 151 assert_difference 'WikiPage.count' do
137 152 assert_difference 'WikiContent::Version.count' do
138 153 put '/projects/ecookbook/wiki/New_page_from_API.xml',
139 154 {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
140 155 credentials('jsmith')
141 156 assert_response 201
142 157 end
143 158 end
144 159
145 160 page = WikiPage.order('id DESC').first
146 161 assert_equal 'New_page_from_API', page.title
147 162 assert_equal 'New content from API', page.content.text
148 163 assert_equal 1, page.content.version
149 164 assert_equal 'API create', page.content.comments
150 165 assert_equal 'jsmith', page.content.author.login
151 166 assert_nil page.parent
152 167 end
153 168
154 169 test "PUT /projects/:project_id/wiki/:title.xml with parent" do
155 170 assert_difference 'WikiPage.count' do
156 171 assert_difference 'WikiContent::Version.count' do
157 172 put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
158 173 {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
159 174 credentials('jsmith')
160 175 assert_response 201
161 176 end
162 177 end
163 178
164 179 page = WikiPage.order('id DESC').first
165 180 assert_equal 'New_subpage_from_API', page.title
166 181 assert_equal WikiPage.find(1), page.parent
167 182 end
168 183 end
General Comments 0
You need to be logged in to leave comments. Login now