@@ -125,6 +125,8 class WikiController < ApplicationController | |||||
125 | render_attachment_warning_if_needed(@page) |
|
125 | render_attachment_warning_if_needed(@page) | |
126 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) |
|
126 | call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page}) | |
127 | redirect_to :action => 'show', :project_id => @project, :id => @page.title |
|
127 | redirect_to :action => 'show', :project_id => @project, :id => @page.title | |
|
128 | else | |||
|
129 | render :action => 'edit' | |||
128 | end |
|
130 | end | |
129 |
|
131 | |||
130 | rescue ActiveRecord::StaleObjectError |
|
132 | rescue ActiveRecord::StaleObjectError |
@@ -108,6 +108,52 class WikiControllerTest < ActionController::TestCase | |||||
108 | assert_equal 1, page.attachments.count |
|
108 | assert_equal 1, page.attachments.count | |
109 | assert_equal 'testfile.txt', page.attachments.first.filename |
|
109 | assert_equal 'testfile.txt', page.attachments.first.filename | |
110 | end |
|
110 | end | |
|
111 | ||||
|
112 | def test_update_page | |||
|
113 | @request.session[:user_id] = 2 | |||
|
114 | assert_no_difference 'WikiPage.count' do | |||
|
115 | assert_no_difference 'WikiContent.count' do | |||
|
116 | assert_difference 'WikiContent::Version.count' do | |||
|
117 | put :update, :project_id => 1, | |||
|
118 | :id => 'Another_page', | |||
|
119 | :content => { | |||
|
120 | :comments => "my comments", | |||
|
121 | :text => "edited", | |||
|
122 | :version => 1 | |||
|
123 | } | |||
|
124 | end | |||
|
125 | end | |||
|
126 | end | |||
|
127 | assert_redirected_to '/projects/ecookbook/wiki/Another_page' | |||
|
128 | ||||
|
129 | page = Wiki.find(1).pages.find_by_title('Another_page') | |||
|
130 | assert_equal "edited", page.content.text | |||
|
131 | assert_equal 2, page.content.version | |||
|
132 | assert_equal "my comments", page.content.comments | |||
|
133 | end | |||
|
134 | ||||
|
135 | def test_update_page_with_failure | |||
|
136 | @request.session[:user_id] = 2 | |||
|
137 | assert_no_difference 'WikiPage.count' do | |||
|
138 | assert_no_difference 'WikiContent.count' do | |||
|
139 | assert_no_difference 'WikiContent::Version.count' do | |||
|
140 | put :update, :project_id => 1, | |||
|
141 | :id => 'Another_page', | |||
|
142 | :content => { | |||
|
143 | :comments => 'a' * 300, # failure here, comment is too long | |||
|
144 | :text => 'edited', | |||
|
145 | :version => 1 | |||
|
146 | } | |||
|
147 | end | |||
|
148 | end | |||
|
149 | end | |||
|
150 | assert_response :success | |||
|
151 | assert_template 'edit' | |||
|
152 | ||||
|
153 | assert_error_tag :descendant => {:content => /Comment is too long/} | |||
|
154 | assert_tag :tag => 'textarea', :attributes => {:id => 'content_text'}, :content => 'edited' | |||
|
155 | assert_tag :tag => 'input', :attributes => {:id => 'content_version', :value => '1'} | |||
|
156 | end | |||
111 |
|
157 | |||
112 | def test_preview |
|
158 | def test_preview | |
113 | @request.session[:user_id] = 2 |
|
159 | @request.session[:user_id] = 2 |
@@ -115,7 +115,7 class ActiveSupport::TestCase | |||||
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def assert_error_tag(options={}) |
|
117 | def assert_error_tag(options={}) | |
118 |
assert_tag({ |
|
118 | assert_tag({:attributes => { :id => 'errorExplanation' }}.merge(options)) | |
119 | end |
|
119 | end | |
120 |
|
120 | |||
121 | # Shoulda macros |
|
121 | # Shoulda macros |
General Comments 0
You need to be logged in to leave comments.
Login now