diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-06-13 13:13:52 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-06-13 13:13:52 +0100 |
commit | 0eb9ef894e8c3353074caf4d39c81830e1ce2dc0 (patch) | |
tree | 4dde8a6df4053ff5fd56445da14d19ffdba837c4 | |
parent | 7d98112cc8394b3b9656f9ac5ec6da02f1c08723 (diff) |
Make sure the template rendering happens within the scope of
with_locale, so it's rendered using the correct locale.
(+ test for this)
-rw-r--r-- | app/controllers/public_body_controller.rb | 13 | ||||
-rw-r--r-- | spec/controllers/public_body_controller_spec.rb | 7 |
2 files changed, 15 insertions, 5 deletions
diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index cf64046ea..688cfab3d 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -21,10 +21,12 @@ class PublicBodyController < ApplicationController @public_body = PublicBody.find_by_url_name_with_historic(params[:url_name]) raise "None found" if @public_body.nil? # XXX proper 404 - # If found by historic name, redirect to new name - redirect_to show_public_body_url(:url_name => @public_body.url_name) if - @public_body.url_name != params[:url_name] - + # If found by historic name, or alternate locale name, redirect to new name + if @public_body.url_name != params[:url_name] + redirect_to show_public_body_url(:url_name => @public_body.url_name) + return + end + set_last_body(@public_body) top_url = main_url("/") @@ -51,9 +53,10 @@ class PublicBodyController < ApplicationController @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ] respond_to do |format| - format.html { @has_json = true } + format.html { @has_json = true; render :template => "public_body/show"} format.json { render :json => @public_body.json_for_api } end + end end diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb index d43ebdcdd..8b84b89ec 100644 --- a/spec/controllers/public_body_controller_spec.rb +++ b/spec/controllers/public_body_controller_spec.rb @@ -31,6 +31,13 @@ describe PublicBodyController, "when showing a body" do assigns[:public_body].notes.should == "Baguette" end + it "should assign the body using same locale as that used in url_name even with wrongly set locale" do + PublicBody.with_locale(:en) do + get :show, {:url_name => "edfh", :locale => 'es'} + response.body.should include('Baguette') + end + end + it "should redirect to newest name if you use historic name of public body in URL" do get :show, :url_name => "hdink" response.should redirect_to(:controller => 'public_body', :action => 'show', :url_name => "dfh") |