diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index be83a72..6c22a0b 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -84,6 +84,8 @@ class CmsController < MyProfileController @parent_id = parent.id end + record_creating_from_public_view + @article.profile = profile @article.last_changed_by = user if request.post? @@ -147,5 +149,13 @@ class CmsController < MyProfileController end end + def record_creating_from_public_view + referer = request.referer + if (referer =~ Regexp.new("^#{url_for(profile.url)}")) + @back_to = 'public_view' + @back_url = referer + end + end + end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 97297d9..1510fae 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -529,4 +529,17 @@ class CmsControllerTest < Test::Unit::TestCase assert_redirected_to article.url end + should 'record as coming from public view when creating article' do + @request.expects(:referer).returns('http://colivre.net/testinguser/testingusers-home-page') + get :new, :profile => 'testinguser', :type => 'TextileArticle' + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => 'http://colivre.net/testinguser/testingusers-home-page' } + end + + should 'go to public view after creating article coming from there' do + post :new, :profile => 'testinguser', :type => 'TextileArticle', :back_to => 'public_view', :article => { :name => 'new-article-from-public-view' } + assert_response :redirect + assert_redirected_to @profile.articles.find_by_name('new-article-from-public-view').url + end + end -- libgit2 0.21.2