Commit d860b2838c678b0dc72e612d05a3cfe587a3f369
Committed by
Daniela Feitosa
1 parent
17dbf46c
Exists in
master
and in
28 other branches
Fixing redirection after setting homepage
(ActionItem1938)
Showing
2 changed files
with
11 additions
and
7 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -169,7 +169,7 @@ class CmsController < MyProfileController |
169 | 169 | profile.home_page = @article |
170 | 170 | profile.save(false) |
171 | 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 | 173 | end |
174 | 174 | |
175 | 175 | def upload_files | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -115,9 +115,7 @@ class CmsControllerTest < Test::Unit::TestCase |
115 | 115 | |
116 | 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 | 119 | assert_equal a, profile.home_page |
122 | 120 | end |
123 | 121 | |
... | ... | @@ -133,12 +131,18 @@ class CmsControllerTest < Test::Unit::TestCase |
133 | 131 | |
134 | 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 | 135 | assert_equal a, profile.home_page |
140 | 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 | 147 | should 'set last_changed_by when creating article' do |
144 | 148 | login_as(profile.identifier) | ... | ... |