From 08f5a54342b3633f1addc23fd91f1f8c3e530e34 Mon Sep 17 00:00:00 2001 From: Moises Machado Date: Thu, 26 Feb 2009 16:12:28 -0300 Subject: [PATCH] ActionItem929: fixed image editing back_url --- app/controllers/my_profile/cms_controller.rb | 5 +++-- test/functional/cms_controller_test.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index e101e2d..b841064 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -204,7 +204,7 @@ class CmsController < MyProfileController if params[:back_to] == 'control_panel' redirect_to :controller => 'profile_editor', :profile => @profile.identifier elsif params[:back_to] == 'public_view' - redirect_to @article.url + redirect_to @article.url.merge(:view => @article.image?) elsif @article.parent redirect_to :action => 'view', :id => @article.parent else @@ -214,9 +214,10 @@ class CmsController < MyProfileController def record_coming_from_public_view referer = request.referer + referer.gsub!(/\?.*/, '') unless referer.nil? if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer)) @back_to = 'public_view' - @back_url = @article.url + @back_url = @article.url.merge(:view => @article.image?) end end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index c33e663..29572c4 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -866,4 +866,34 @@ class CmsControllerTest < Test::Unit::TestCase assert_template nil assert_redirected_to folder.url end + + should 'record when coming from public view on edit files with view true' do + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + + @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{file.slug}?view=true").at_least_once + + get :edit, :profile => profile.identifier, :id => file.id + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{file.slug}?.*view=true/ } + end + + should 'detect when comming from home page to edit files with view true' do + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + profile.expects(:home_page).returns(file).at_least_once + + @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}?view=true").at_least_once + @controller.stubs(:profile).returns(profile) + get :edit, :profile => profile.identifier, :id => file.id + assert_tag :tag => 'input', :attributes => { :type => 'hidden', :name => 'back_to', :value => 'public_view' } + assert_tag :tag => 'a', :descendant => { :content => 'Cancel' }, :attributes => { :href => /^https?:\/\/colivre.net\/#{profile.identifier}\/#{profile.home_page.slug}?.*view=true$/ } + end + + should 'go back to public view when edit files coming from there with view true' do + file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) + @request.expects(:referer).returns("http://colivre.net/#{profile.identifier}/#{file.slug}?view=true").at_least_once + + post :edit, :profile => profile.identifier, :id => file.id, :back_to => 'public_view', :article => {:abstract => 'some description'} + assert_template nil + assert_redirected_to file.url.merge(:view => true) + end end -- libgit2 0.21.2