diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-25 20:38:29 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-10-25 20:38:29 +0000 |
commit | eff874b29a908e85e80d8bcd6a20fd85165e59cd (patch) | |
tree | 914366bfb252d98ef35bde6e738e880e98e9483d /test/integration | |
parent | 9e313087205721ed3c6239be7cde55598d29f9e6 (diff) | |
download | redmine-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')
-rw-r--r-- | test/integration/api_test/wiki_pages_test.rb | 89 | ||||
-rw-r--r-- | test/integration/routing/wiki_test.rb | 69 |
2 files changed, 127 insertions, 31 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 diff --git a/test/integration/routing/wiki_test.rb b/test/integration/routing/wiki_test.rb index 29b305cd6..2c85a62ee 100644 --- a/test/integration/routing/wiki_test.rb +++ b/test/integration/routing/wiki_test.rb @@ -34,16 +34,6 @@ class RoutingWikiTest < ActionController::IntegrationTest :id => 'lalala', :format => 'pdf' } ) assert_routing( - { :method => 'get', :path => "/projects/567/wiki/lalala.xml" }, - { :controller => 'wiki', :action => 'show', :project_id => '567', - :id => 'lalala', :format => 'xml' } - ) - assert_routing( - { :method => 'get', :path => "/projects/567/wiki/lalala.json" }, - { :controller => 'wiki', :action => 'show', :project_id => '567', - :id => 'lalala', :format => 'json' } - ) - assert_routing( { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/diff" }, { :controller => 'wiki', :action => 'diff', :project_id => '1', :id => 'CookBook_documentation' } @@ -54,16 +44,6 @@ class RoutingWikiTest < ActionController::IntegrationTest :id => 'CookBook_documentation', :version => '2' } ) assert_routing( - { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.xml" }, - { :controller => 'wiki', :action => 'show', :project_id => '1', - :id => 'CookBook_documentation', :version => '2', :format => 'xml' } - ) - assert_routing( - { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.json" }, - { :controller => 'wiki', :action => 'show', :project_id => '1', - :id => 'CookBook_documentation', :version => '2', :format => 'json' } - ) - assert_routing( { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2/diff" }, { :controller => 'wiki', :action => 'diff', :project_id => '1', :id => 'CookBook_documentation', :version => '2' } @@ -92,14 +72,6 @@ class RoutingWikiTest < ActionController::IntegrationTest { :method => 'get', :path => "/projects/567/wiki/index" }, { :controller => 'wiki', :action => 'index', :project_id => '567' } ) - assert_routing( - { :method => 'get', :path => "/projects/567/wiki/index.xml" }, - { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'xml' } - ) - assert_routing( - { :method => 'get', :path => "/projects/567/wiki/index.json" }, - { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'json' } - ) end def test_wiki_resources @@ -156,4 +128,45 @@ class RoutingWikiTest < ActionController::IntegrationTest :id => 'ladida', :version => '3' } ) end + + def test_api + assert_routing( + { :method => 'get', :path => "/projects/567/wiki/my_page.xml" }, + { :controller => 'wiki', :action => 'show', :project_id => '567', + :id => 'my_page', :format => 'xml' } + ) + assert_routing( + { :method => 'get', :path => "/projects/567/wiki/my_page.json" }, + { :controller => 'wiki', :action => 'show', :project_id => '567', + :id => 'my_page', :format => 'json' } + ) + assert_routing( + { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.xml" }, + { :controller => 'wiki', :action => 'show', :project_id => '1', + :id => 'CookBook_documentation', :version => '2', :format => 'xml' } + ) + assert_routing( + { :method => 'get', :path => "/projects/1/wiki/CookBook_documentation/2.json" }, + { :controller => 'wiki', :action => 'show', :project_id => '1', + :id => 'CookBook_documentation', :version => '2', :format => 'json' } + ) + assert_routing( + { :method => 'get', :path => "/projects/567/wiki/index.xml" }, + { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'xml' } + ) + assert_routing( + { :method => 'get', :path => "/projects/567/wiki/index.json" }, + { :controller => 'wiki', :action => 'index', :project_id => '567', :format => 'json' } + ) + assert_routing( + { :method => 'put', :path => "/projects/567/wiki/my_page.xml" }, + { :controller => 'wiki', :action => 'update', :project_id => '567', + :id => 'my_page', :format => 'xml' } + ) + assert_routing( + { :method => 'put', :path => "/projects/567/wiki/my_page.json" }, + { :controller => 'wiki', :action => 'update', :project_id => '567', + :id => 'my_page', :format => 'json' } + ) + end end |