summaryrefslogtreecommitdiffstats
path: root/test/integration/api_test/wiki_pages_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-25 20:38:29 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-10-25 20:38:29 +0000
commiteff874b29a908e85e80d8bcd6a20fd85165e59cd (patch)
tree914366bfb252d98ef35bde6e738e880e98e9483d /test/integration/api_test/wiki_pages_test.rb
parent9e313087205721ed3c6239be7cde55598d29f9e6 (diff)
downloadredmine-eff874b29a908e85e80d8bcd6a20fd85165e59cd.tar.gz
redmine-eff874b29a908e85e80d8bcd6a20fd85165e59cd.zip
REST API for creating/updating wiki pages (#7082).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10717 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/integration/api_test/wiki_pages_test.rb')
-rw-r--r--test/integration/api_test/wiki_pages_test.rb89
1 files changed, 86 insertions, 3 deletions
diff --git a/test/integration/api_test/wiki_pages_test.rb b/test/integration/api_test/wiki_pages_test.rb
index 8d1ee326e..828e139ea 100644
--- a/test/integration/api_test/wiki_pages_test.rb
+++ b/test/integration/api_test/wiki_pages_test.rb
@@ -28,7 +28,7 @@ class ApiTest::WikiPagesTest < ActionController::IntegrationTest
test "GET /projects/:project_id/wiki/index.xml should return wiki pages" do
get '/projects/ecookbook/wiki/index.xml'
- assert_response :success
+ assert_response 200
assert_equal 'application/xml', response.content_type
assert_select 'wiki_pages[type=array]' do
assert_select 'wiki_page', :count => Wiki.find(1).pages.count
@@ -38,12 +38,16 @@ class ApiTest::WikiPagesTest < ActionController::IntegrationTest
assert_select 'created_on'
assert_select 'updated_on'
end
+ assert_select 'wiki_page' do
+ assert_select 'title', :text => 'Page_with_an_inline_image'
+ assert_select 'parent[title=?]', 'CookBook_documentation'
+ end
end
end
test "GET /projects/:project_id/wiki/:title.xml should return wiki page" do
get '/projects/ecookbook/wiki/CookBook_documentation.xml'
- assert_response :success
+ assert_response 200
assert_equal 'application/xml', response.content_type
assert_select 'wiki_page' do
assert_select 'title', :text => 'CookBook_documentation'
@@ -63,7 +67,7 @@ class ApiTest::WikiPagesTest < ActionController::IntegrationTest
test "GET /projects/:project_id/wiki/:title/:version.xml should return wiki page version" do
get '/projects/ecookbook/wiki/CookBook_documentation/2.xml'
- assert_response :success
+ assert_response 200
assert_equal 'application/xml', response.content_type
assert_select 'wiki_page' do
assert_select 'title', :text => 'CookBook_documentation'
@@ -82,4 +86,83 @@ class ApiTest::WikiPagesTest < ActionController::IntegrationTest
assert_response 401
assert_equal 'application/xml', response.content_type
end
+
+ test "PUT /projects/:project_id/wiki/:title.xml should update wiki page" do
+ assert_no_difference 'WikiPage.count' do
+ assert_difference 'WikiContent::Version.count' do
+ put '/projects/ecookbook/wiki/CookBook_documentation.xml',
+ {:wiki_page => {:text => 'New content from API', :comments => 'API update'}},
+ credentials('jsmith')
+ assert_response 200
+ end
+ end
+
+ page = WikiPage.find(1)
+ assert_equal 'New content from API', page.content.text
+ assert_equal 4, page.content.version
+ assert_equal 'API update', page.content.comments
+ assert_equal 'jsmith', page.content.author.login
+ end
+
+ test "PUT /projects/:project_id/wiki/:title.xml with current versino should update wiki page" do
+ assert_no_difference 'WikiPage.count' do
+ assert_difference 'WikiContent::Version.count' do
+ put '/projects/ecookbook/wiki/CookBook_documentation.xml',
+ {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '3'}},
+ credentials('jsmith')
+ assert_response 200
+ end
+ end
+
+ page = WikiPage.find(1)
+ assert_equal 'New content from API', page.content.text
+ assert_equal 4, page.content.version
+ assert_equal 'API update', page.content.comments
+ assert_equal 'jsmith', page.content.author.login
+ end
+
+ test "PUT /projects/:project_id/wiki/:title.xml with stale version should respond with 409" do
+ assert_no_difference 'WikiPage.count' do
+ assert_no_difference 'WikiContent::Version.count' do
+ put '/projects/ecookbook/wiki/CookBook_documentation.xml',
+ {:wiki_page => {:text => 'New content from API', :comments => 'API update', :version => '2'}},
+ credentials('jsmith')
+ assert_response 409
+ end
+ end
+ end
+
+ test "PUT /projects/:project_id/wiki/:title.xml should create the page if it does not exist" do
+ assert_difference 'WikiPage.count' do
+ assert_difference 'WikiContent::Version.count' do
+ put '/projects/ecookbook/wiki/New_page_from_API.xml',
+ {:wiki_page => {:text => 'New content from API', :comments => 'API create'}},
+ credentials('jsmith')
+ assert_response 201
+ end
+ end
+
+ page = WikiPage.order('id DESC').first
+ assert_equal 'New_page_from_API', page.title
+ assert_equal 'New content from API', page.content.text
+ assert_equal 1, page.content.version
+ assert_equal 'API create', page.content.comments
+ assert_equal 'jsmith', page.content.author.login
+ assert_nil page.parent
+ end
+
+ test "PUT /projects/:project_id/wiki/:title.xml with parent" do
+ assert_difference 'WikiPage.count' do
+ assert_difference 'WikiContent::Version.count' do
+ put '/projects/ecookbook/wiki/New_subpage_from_API.xml',
+ {:wiki_page => {:parent_title => 'CookBook_documentation', :text => 'New content from API', :comments => 'API create'}},
+ credentials('jsmith')
+ assert_response 201
+ end
+ end
+
+ page = WikiPage.order('id DESC').first
+ assert_equal 'New_subpage_from_API', page.title
+ assert_equal WikiPage.find(1), page.parent
+ end
end