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

require 'json'

# XXX Use route_for or params_from to check /c/ links better
# http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html

describe UserController, "when showing a user" do
    integrate_views
    fixtures :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
    before(:each) do
        load_raw_emails_data(raw_emails)
    end
   
    it "should be successful" do
        get :show, :url_name => "bob_smith"
        response.should be_success
    end

    it "should redirect to lower case name if given one with capital letters" do
        get :show, :url_name => "Bob_Smith"
        response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith")
    end

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

    it "should distinguish between 'my profile' and 'my requests' for logged in users" do
        session[:user_id] = users(:bob_smith_user).id
        get :show, :url_name => "bob_smith", :view => 'requests'
        response.body.should_not include("Change your password")
        response.body.should include("Freedom of Information requests")
        get :show, :url_name => "bob_smith", :view => 'profile'
        response.body.should include("Change your password")
        response.body.should_not include("Freedom of Information requests")
    end

    it "should assign the user" do
        get :show, :url_name => "bob_smith"
        assigns[:display_user].should == users(:bob_smith_user)
    end

    it "should search the user's contributions" do
        get :show, :url_name => "bob_smith"
        assigns[:xapian_requests].results.count.should == 2
        get :show, :url_name => "bob_smith", :user_query => "money"
        assigns[:xapian_requests].results.count.should == 1
    end

# Error handling not quite good enough for this yet
#    it "should not show unconfirmed users" do
#        get :show, :url_name => "silly_emnameem"
#        assigns[:display_users].should == [ users(:silly_name_user) ]
#    end

end

describe UserController, "when signing in" do
    integrate_views
    fixtures :users

    def get_last_postredirect
        post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1")<commit_msg>Make test less brittle<commit_after># coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

require 'json'

# XXX Use route_for or params_from to check /c/ links better
# http://rspec.rubyforge.org/rspec-rails/1.1.12/classes/Spec/Rails/Example/ControllerExampleGroup.html

describe UserController, "when showing a user" do
    integrate_views
    fixtures :users, :public_bodies, :public_body_translations, :public_body_versions, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events, :track_things
    before(:each) do
        load_raw_emails_data(raw_emails)
    end
   
    it "should be successful" do
        get :show, :url_name => "bob_smith"
        response.should be_success
    end

    it "should redirect to lower case name if given one with capital letters" do
        get :show, :url_name => "Bob_Smith"
        response.should redirect_to(:controller => 'user', :action => 'show', :url_name => "bob_smith")
    end

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

    it "should distinguish between 'my profile' and 'my requests' for logged in users" do
        session[:user_id] = users(:bob_smith_user).id
        get :show, :url_name => "bob_smith", :view => 'requests'
        response.body.should_not include("Change your password")
        response.body.should match(/Your [0-9]+ Freedom of Information requests/)
        get :show, :url_name => "bob_smith", :view => 'profile'
        response.body.should include("Change your password")
        response.body.should_not match(/Your [0-9]+ Freedom of Information requests/)
    end

    it "should assign the user" do
        get :show, :url_name => "bob_smith"
        assigns[:display_user].should == users(:bob_smith_user)
    end

    it "should search the user's contributions" do
        get :show, :url_name => "bob_smith"
        assigns[:xapian_requests].results.count.should == 2
        get :show, :url_name => "bob_smith", :user_query => "money"
        assigns[:xapian_requests].results.count.should == 1
    end

# Error handling not quite good enough for this yet
#    it "should not show unconfirmed users" do
#        get :show, :url_name => "silly_emnameem"
#        assigns[:display_users].should == [ users(:silly_name_user) ]
#    end

end

describe UserController, "when signing in" do
    integrate_views
    fixtures :users

    def get_last_postredirect
        post_redirects = PostRedirect.find_by_sql("select * from post_redirects order by id desc limit 1")
{'fraction_non_alphanumeric': 0.10913947719900782, 'fraction_numerical': 0.003816065636328945, 'mean_word_length': 3.4803418803418804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '5887439', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1572, 'n_words': 450}