diff --git a/app/controllers/rates_controller.rb b/app/controllers/rates_controller.rb
index 2b6e953..13ebeff 100644
--- a/app/controllers/rates_controller.rb
+++ b/app/controllers/rates_controller.rb
@@ -73,7 +73,13 @@ class RatesController < ApplicationController
respond_to do |format|
if @rate.update_attributes(params[:rate])
flash[:notice] = 'Rate was successfully updated.'
- format.html { redirect_to(@rate) }
+ format.html {
+ if params[:back_url] && !params[:back_url].blank?
+ redirect_to(params[:back_url])
+ else
+ redirect_to(rates_url(:user_id => @rate.user_id))
+ end
+ }
format.xml { head :ok }
else
format.html { render :action => "edit" }
diff --git a/app/views/rates/_list.html.erb b/app/views/rates/_list.html.erb
index 3c96520..46153e7 100644
--- a/app/views/rates/_list.html.erb
+++ b/app/views/rates/_list.html.erb
@@ -15,7 +15,7 @@
<%= h rate.amount %> |
<% if rate.unlocked? %>
- <%= link_to image_tag('edit.png'), edit_rate_path(rate) %>
+ <%= link_to image_tag('edit.png'), edit_rate_path(rate, :back_url => @back_url) %>
<%= link_to image_tag('delete.png'),
{:action => 'not_implemented', :id => @user, :rate_id => rate },
{:method => :post, :confirm => l(:text_are_you_sure) } %>
diff --git a/spec/controllers/rates_controller_spec.rb b/spec/controllers/rates_controller_spec.rb
index 8761599..423c9b3 100644
--- a/spec/controllers/rates_controller_spec.rb
+++ b/spec/controllers/rates_controller_spec.rb
@@ -315,10 +315,17 @@ describe RatesController, "as an administrator" do
assigns(:rate).should equal(mock_rate)
end
- it "should redirect to the rate" do
+ it "should redirect to the rate list" do
Rate.stub!(:find).and_return(mock_rate(:update_attributes => true))
put :update, :id => "1"
- response.should redirect_to(rate_url(mock_rate))
+ response.should redirect_to(rates_url(:user_id => @user.id))
+ end
+
+ it 'should redirect to the back_url if set' do
+ back_url = '/back_to_this_url'
+ Rate.stub!(:find).and_return(mock_rate(:update_attributes => true))
+ put :update, :id => "1", :back_url => back_url
+ response.should redirect_to(back_url)
end
end
|