summaryrefslogtreecommitdiffstats
path: root/test/functional/wiki_controller_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-18 16:25:00 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-11-18 16:25:00 +0000
commit6fc245327ce5bb4bb75f1378424635e347dfcd02 (patch)
treefd9d00eab0e444da2f6ecb58842cb973c37540a5 /test/functional/wiki_controller_test.rb
parentb38dc9a301c3ab0fafc5dd824ad57059ec58fc91 (diff)
downloadredmine-6fc245327ce5bb4bb75f1378424635e347dfcd02.tar.gz
redmine-6fc245327ce5bb4bb75f1378424635e347dfcd02.zip
Wiki: allows single section edit (#2222).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7829 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/functional/wiki_controller_test.rb')
-rw-r--r--test/functional/wiki_controller_test.rb115
1 files changed, 115 insertions, 0 deletions
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 48db9e650..1274e676b 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -118,6 +118,44 @@ class WikiControllerTest < ActionController::TestCase
assert_equal 'testfile.txt', page.attachments.first.filename
end
+ def test_edit_page
+ @request.session[:user_id] = 2
+ get :edit, :project_id => 'ecookbook', :id => 'Another_page'
+
+ assert_response :success
+ assert_template 'edit'
+
+ assert_tag 'textarea',
+ :attributes => { :name => 'content[text]' },
+ :content => WikiPage.find_by_title('Another_page').content.text
+ end
+
+ def test_edit_section
+ @request.session[:user_id] = 2
+ get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 2
+
+ assert_response :success
+ assert_template 'edit'
+
+ page = WikiPage.find_by_title('Page_with_sections')
+ section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
+
+ assert_tag 'textarea',
+ :attributes => { :name => 'content[text]' },
+ :content => section
+ assert_tag 'input',
+ :attributes => { :name => 'section', :type => 'hidden', :value => '2' }
+ assert_tag 'input',
+ :attributes => { :name => 'section_hash', :type => 'hidden', :value => hash }
+ end
+
+ def test_edit_invalid_section_should_respond_with_404
+ @request.session[:user_id] = 2
+ get :edit, :project_id => 'ecookbook', :id => 'Page_with_sections', :section => 10
+
+ assert_response 404
+ end
+
def test_update_page
@request.session[:user_id] = 2
assert_no_difference 'WikiPage.count' do
@@ -200,6 +238,83 @@ class WikiControllerTest < ActionController::TestCase
assert_equal 2, c.version
end
+ def test_update_section
+ @request.session[:user_id] = 2
+ page = WikiPage.find_by_title('Page_with_sections')
+ section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
+ text = page.content.text
+
+ assert_no_difference 'WikiPage.count' do
+ assert_no_difference 'WikiContent.count' do
+ assert_difference 'WikiContent::Version.count' do
+ put :update, :project_id => 1, :id => 'Page_with_sections',
+ :content => {
+ :text => "New section content",
+ :version => 3
+ },
+ :section => 2,
+ :section_hash => hash
+ end
+ end
+ end
+ assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
+ assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.reload.content.text
+ end
+
+ def test_update_section_should_allow_stale_page_update
+ @request.session[:user_id] = 2
+ page = WikiPage.find_by_title('Page_with_sections')
+ section, hash = Redmine::WikiFormatting::Textile::Formatter.new(page.content.text).get_section(2)
+ text = page.content.text
+
+ assert_no_difference 'WikiPage.count' do
+ assert_no_difference 'WikiContent.count' do
+ assert_difference 'WikiContent::Version.count' do
+ put :update, :project_id => 1, :id => 'Page_with_sections',
+ :content => {
+ :text => "New section content",
+ :version => 2 # Current version is 3
+ },
+ :section => 2,
+ :section_hash => hash
+ end
+ end
+ end
+ assert_redirected_to '/projects/ecookbook/wiki/Page_with_sections'
+ page.reload
+ assert_equal Redmine::WikiFormatting::Textile::Formatter.new(text).update_section(2, "New section content"), page.content.text
+ assert_equal 4, page.content.version
+ end
+
+ def test_update_section_should_not_allow_stale_section_update
+ @request.session[:user_id] = 2
+
+ assert_no_difference 'WikiPage.count' do
+ assert_no_difference 'WikiContent.count' do
+ assert_no_difference 'WikiContent::Version.count' do
+ put :update, :project_id => 1, :id => 'Page_with_sections',
+ :content => {
+ :comments => 'My comments',
+ :text => "Text should not be lost",
+ :version => 3
+ },
+ :section => 2,
+ :section_hash => Digest::MD5.hexdigest("wrong hash")
+ end
+ end
+ end
+ assert_response :success
+ assert_template 'edit'
+ assert_tag :div,
+ :attributes => { :class => /error/ },
+ :content => /Data has been updated by another user/
+ assert_tag 'textarea',
+ :attributes => { :name => 'content[text]' },
+ :content => /Text should not be lost/
+ assert_tag 'input',
+ :attributes => { :name => 'content[comments]', :value => 'My comments' }
+ end
+
def test_preview
@request.session[:user_id] = 2
xhr :post, :preview, :project_id => 1, :id => 'CookBook_documentation',