Commit d860b2838c678b0dc72e612d05a3cfe587a3f369

Authored by Rodrigo Souto
Committed by Daniela Feitosa
1 parent 17dbf46c

Fixing redirection after setting homepage

(ActionItem1938)
app/controllers/my_profile/cms_controller.rb
@@ -169,7 +169,7 @@ class CmsController < MyProfileController @@ -169,7 +169,7 @@ class CmsController < MyProfileController
169 profile.home_page = @article 169 profile.home_page = @article
170 profile.save(false) 170 profile.save(false)
171 session[:notice] = _('"%s" configured as home page.') % @article.name 171 session[:notice] = _('"%s" configured as home page.') % @article.name
172 - redirect_to :action => 'view', :id => @article.id 172 + redirect_to (request.referer || profile.url)
173 end 173 end
174 174
175 def upload_files 175 def upload_files
test/functional/cms_controller_test.rb
@@ -115,9 +115,7 @@ class CmsControllerTest < Test::Unit::TestCase @@ -115,9 +115,7 @@ class CmsControllerTest < Test::Unit::TestCase
115 115
116 post :set_home_page, :profile => profile.identifier, :id => a.id 116 post :set_home_page, :profile => profile.identifier, :id => a.id
117 117
118 - assert_redirected_to :action => 'view', :id => a.id  
119 -  
120 - profile = Profile.find(@profile.id) 118 + profile.reload
121 assert_equal a, profile.home_page 119 assert_equal a, profile.home_page
122 end 120 end
123 121
@@ -133,12 +131,18 @@ class CmsControllerTest < Test::Unit::TestCase @@ -133,12 +131,18 @@ class CmsControllerTest < Test::Unit::TestCase
133 131
134 post :set_home_page, :profile => profile.identifier, :id => a.id 132 post :set_home_page, :profile => profile.identifier, :id => a.id
135 133
136 - assert_redirected_to :action => 'view', :id => a.id  
137 -  
138 - profile = Profile.find(@profile.id) 134 + profile.reload
139 assert_equal a, profile.home_page 135 assert_equal a, profile.home_page
140 end 136 end
141 137
  138 + should 'redirect to previous page after setting home page' do
  139 + a = profile.articles.build(:name => 'my new home page')
  140 + a.save!
  141 +
  142 + @request.env['HTTP_REFERER'] = '/random_page'
  143 + post :set_home_page, :profile => profile.identifier, :id => a.id
  144 + assert_redirected_to '/random_page'
  145 + end
142 146
143 should 'set last_changed_by when creating article' do 147 should 'set last_changed_by when creating article' do
144 login_as(profile.identifier) 148 login_as(profile.identifier)