<commit_before># coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe PublicBodyController, "when showing a body" do
    integrate_views

    before(:each) do
        load_raw_emails_data
        get_fixtures_xapian_index
    end

    it "should be successful" do
        get :show, :url_name => "dfh", :view => 'all'
        response.should be_success
    end

    it "should render with 'show' template" do
        get :show, :url_name => "dfh", :view => 'all'
        response.should render_template('show')
    end

    it "should assign the body" do
        get :show, :url_name => "dfh", :view => 'all'
        assigns[:public_body].should == public_bodies(:humpadink_public_body)
    end

    it "should assign the requests (1)" do
        get :show, :url_name => "tgq", :view => 'all'
        assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
            :conditions => ["public_body_id = ?", public_bodies(:geraldine_public_body).id])
    end

    it "should assign the requests (2)" do
        get :show, :url_name => "tgq", :view => 'successful'
        assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
            :conditions => ["described_state = ? and public_body_id = ?",
                "successful", public_bodies(:geraldine_public_body).id])
    end

    it "should assign the requests (3)" do
        get :show, :url_name => "dfh", :view => 'all'
        assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
            :conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id])
    end

    it "should redirect to the canonical name in the chosen locale" do
        get :show, {:url_name => "dfh", :view => 'all', :show_locale => "es"}
        response.should redirect_to "http://test.host/es/body/edfh"
    end

    it "should assign the body using same locale as that used in url_name" do
        get :show, {:url_name => "edfh", :view => 'all', :show_locale => "es"}
        response.should include_text("Baguette")
    end

    it "should redirect use to the relevant locale even when url_name is for a different locale" do
        old_filters = ActionController::Routing::Routes.filters
        ActionController::Routing::Routes.filters = RoutingFilter::Chain.new

        get :show, {:url_name => "edfh", :view => 'all'}
        response.should redirect_to "http://test.host/body/dfh"

        ActionController::Routing::Routes.filters = old_filters
    end

    it "should remember the filter (view) setting on redirecting" do
        get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful'
        response.should redirect_to show_public_body_successful_url(:url_name => "etgq")
    end

    it "should redirect to newest name if you use historic name of public body in URL" do
        get :show, :url_name => "hdink", :view => 'all'<commit_msg>Use full url in test for redirect to ensure in correct locale<commit_after># coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe PublicBodyController, "when showing a body" do
    integrate_views

    before(:each) do
        load_raw_emails_data
        get_fixtures_xapian_index
    end

    it "should be successful" do
        get :show, :url_name => "dfh", :view => 'all'
        response.should be_success
    end

    it "should render with 'show' template" do
        get :show, :url_name => "dfh", :view => 'all'
        response.should render_template('show')
    end

    it "should assign the body" do
        get :show, :url_name => "dfh", :view => 'all'
        assigns[:public_body].should == public_bodies(:humpadink_public_body)
    end

    it "should assign the requests (1)" do
        get :show, :url_name => "tgq", :view => 'all'
        assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
            :conditions => ["public_body_id = ?", public_bodies(:geraldine_public_body).id])
    end

    it "should assign the requests (2)" do
        get :show, :url_name => "tgq", :view => 'successful'
        assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
            :conditions => ["described_state = ? and public_body_id = ?",
                "successful", public_bodies(:geraldine_public_body).id])
    end

    it "should assign the requests (3)" do
        get :show, :url_name => "dfh", :view => 'all'
        assigns[:xapian_requests].results.map{|x|x[:model].info_request}.should =~ InfoRequest.all(
            :conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id])
    end

    it "should redirect to the canonical name in the chosen locale" do
        get :show, {:url_name => "dfh", :view => 'all', :show_locale => "es"}
        response.should redirect_to "http://test.host/es/body/edfh"
    end

    it "should assign the body using same locale as that used in url_name" do
        get :show, {:url_name => "edfh", :view => 'all', :show_locale => "es"}
        response.should include_text("Baguette")
    end

    it "should redirect use to the relevant locale even when url_name is for a different locale" do
        old_filters = ActionController::Routing::Routes.filters
        ActionController::Routing::Routes.filters = RoutingFilter::Chain.new

        get :show, {:url_name => "edfh", :view => 'all'}
        response.should redirect_to "http://test.host/body/dfh"

        ActionController::Routing::Routes.filters = old_filters
    end

    it "should remember the filter (view) setting on redirecting" do
        get :show, :show_locale => "es", :url_name => "tgq", :view => 'successful'
        response.should redirect_to 'http://test.host/es/body/etgq/successful'
    end

    it "should redirect to newest name if you use historic name of public body in URL" do
        get :show, :url_name => "hdink", :view => 'all'
{'fraction_non_alphanumeric': 0.13258839226150768, 'fraction_numerical': 0.00133422281521014, 'mean_word_length': 3.1501730103806227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2972267', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1839, 'n_words': 513}