Commit b5c403b000e8429257a4a3ab150b62683e713e77

Authored by AntonioTerceiro
1 parent e14a246f

ActionItem593: coming back to public view when creating new article

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2352 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/cms_controller.rb
... ... @@ -84,6 +84,8 @@ class CmsController < MyProfileController
84 84 @parent_id = parent.id
85 85 end
86 86  
  87 + record_creating_from_public_view
  88 +
87 89 @article.profile = profile
88 90 @article.last_changed_by = user
89 91 if request.post?
... ... @@ -147,5 +149,13 @@ class CmsController < MyProfileController
147 149 end
148 150 end
149 151  
  152 + def record_creating_from_public_view
  153 + referer = request.referer
  154 + if (referer =~ Regexp.new("^#{url_for(profile.url)}"))
  155 + @back_to = 'public_view'
  156 + @back_url = referer
  157 + end
  158 + end
  159 +
150 160 end
151 161  
... ...
test/functional/cms_controller_test.rb
... ... @@ -529,4 +529,17 @@ class CmsControllerTest < Test::Unit::TestCase
529 529 assert_redirected_to article.url
530 530 end
531 531  
  532 + should 'record as coming from public view when creating article' do
  533 + @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page')
  534 + get :new, :profile => 'testinguser', :type => 'TextileArticle'
  535 + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' }
  536 + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' }
  537 + end
  538 +
  539 + should 'go to public view after creating article coming from there' do
  540 + post :new, :profile => 'testinguser', :type => 'TextileArticle', :back_to => 'public_view', :article => { :name => 'new-article-from-public-view' }
  541 + assert_response :redirect
  542 + assert_redirected_to @profile.articles.find_by_name('new-article-from-public-view').url
  543 + end
  544 +
532 545 end
... ...