Commit c63abafb13893050b36de8345ec3d92e36d5b010
1 parent
43ebde83
Exists in
master
and in
29 other branches
Fix author assignment for uploaded files
authorship started being idenfitied by created_by instead of last_changed_by, but #upload_files was not updated to reflect that and there were no automated tests for it.
Showing
2 changed files
with
20 additions
and
1 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -188,7 +188,18 @@ class CmsController < MyProfileController |
188 | 188 | end |
189 | 189 | if request.post? && params[:uploaded_files] |
190 | 190 | params[:uploaded_files].each do |file| |
191 | - @uploaded_files << UploadedFile.create({:uploaded_data => file, :profile => profile, :parent => @parent, :last_changed_by => user}, :without_protection => true) unless file == '' | |
191 | + unless file == '' | |
192 | + @uploaded_files << UploadedFile.create( | |
193 | + { | |
194 | + :uploaded_data => file, | |
195 | + :profile => profile, | |
196 | + :parent => @parent, | |
197 | + :last_changed_by => user, | |
198 | + :created_by => user, | |
199 | + }, | |
200 | + :without_protection => true | |
201 | + ) | |
202 | + end | |
192 | 203 | end |
193 | 204 | @errors = @uploaded_files.select { |f| f.errors.any? } |
194 | 205 | if @errors.any? | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -321,6 +321,14 @@ class CmsControllerTest < ActionController::TestCase |
321 | 321 | assert_equal 'test.txt', f.children[0].name |
322 | 322 | end |
323 | 323 | |
324 | + should 'set author of uploaded files' do | |
325 | + f = Folder.new(:name => 'f'); profile.articles << f; f.save! | |
326 | + post :upload_files, :profile => profile.identifier, :parent_id => f.id, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')] | |
327 | + | |
328 | + uf = profile.articles.find_by_name('test.txt') | |
329 | + assert_equal profile, uf.author | |
330 | + end | |
331 | + | |
324 | 332 | should 'display destination folder of files when uploading file in root folder' do |
325 | 333 | get :upload_files, :profile => profile.identifier |
326 | 334 | ... | ... |