Commit 9c58ba961a4f878c61e497ac768f4385a70d9a4b

Authored by Daniela Feitosa
1 parent aa1425d7

Allowing upload out of a folder

(ActionItem2521)
app/controllers/my_profile/cms_controller.rb
... ... @@ -18,7 +18,7 @@ class CmsController < MyProfileController
18 18  
19 19 protect_if :only => :upload_files do |c, user, profile|
20 20 article_id = c.params[:parent_id]
21   - (article_id && profile.articles.find(article_id).allow_create?(user)) ||
  21 + (!article_id.blank? && profile.articles.find(article_id).allow_create?(user)) ||
22 22 (user && (user.has_permission?('post_content', profile) || user.has_permission?('publish_content', profile)))
23 23 end
24 24  
... ...
test/functional/cms_controller_test.rb
... ... @@ -296,6 +296,13 @@ class CmsControllerTest < ActionController::TestCase
296 296 assert_not_nil profile.articles.find_by_path('test.txt')
297 297 end
298 298  
  299 + should 'not crash when parent_id is blank' do
  300 + assert_nothing_raised do
  301 + post :upload_files, :profile => profile.identifier, :parent_id => '', :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain'), '' ]
  302 + end
  303 + assert_not_nil profile.articles.find_by_path('test.txt')
  304 + end
  305 +
299 306 should 'redirect to cms after uploading files' do
300 307 post :upload_files, :profile => profile.identifier, :uploaded_files => [fixture_file_upload('/files/test.txt', 'text/plain')]
301 308 assert_redirected_to :action => 'index'
... ...