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