diff options
-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") |