<commit_before>require 'simplecov'
SimpleCov.start

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'rspec/mocks'
require 'capybara/rails'
require 'capybara/rspec'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
  
  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false
  
  config.include FactoryGirl::Syntax::Methods

  config.before(:each) do
    REDIS.flushdb
    AWS.stub!

    location = stub
    location.stub(:city).and_return 'New York'
    location.stub(:metrocode).and_return '1234'
    location.stub(:state).and_return 'New York'
    location.stub(:state_code).and_return 'NY'
    location.stub(:country_code).and_return 'US'
    Geocoder.stub(:search).and_return [location]
    $statsd = FakeStatsd.new
  end

  config.after(:each) do
    ActionMailer::Base.deliveries.clear
  end

  Capybara.javascript_driver = :webkit
end

#Capybara.default_wait_time = 5
#Capybara.register_driver :webkit do |app| 
#  Capybara::Webkit::Driver.new(app, :stdout => nil) 
#end 

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil
 
  def self.connection
    @@shared_connection || retrieve_connection
  end
end
 
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

def valid_session
  user = create(:user)
  valid_session_for user
end

def valid_admin_session
  user = create(:admin_user)
  valid_session_for user
end

def valid_session_for user
  {:user_id => user.id}
end

def valid_super_user_session<commit_msg>gave up<commit_after>require 'simplecov'
SimpleCov.start

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'rspec/mocks'
require 'capybara/rails'
require 'capybara/rspec'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true
  
  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false
  
  config.include FactoryGirl::Syntax::Methods

  config.before(:each) do
    REDIS.flushdb
    AWS.stub!

    location = stub
    location.stub(:city).and_return 'New York'
    location.stub(:metrocode).and_return '1234'
    location.stub(:state).and_return 'New York'
    location.stub(:state_code).and_return 'NY'
    location.stub(:country_code).and_return 'US'
    Geocoder.stub(:search).and_return [location]
    $statsd = FakeStatsd.new
  end

  config.after(:each) do
    ActionMailer::Base.deliveries.clear
  end
end

Capybara.default_wait_time = 5
Capybara.register_driver :webkit do |app| 
  Capybara::Webkit::Driver.new(app, :stdout => nil) 
end 

class ActiveRecord::Base
  mattr_accessor :shared_connection
  @@shared_connection = nil
 
  def self.connection
    @@shared_connection || retrieve_connection
  end
end
 
# Forces all threads to share the same connection. This works on
# Capybara because it starts the web server in a thread.
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection

def valid_session
  user = create(:user)
  valid_session_for user
end

def valid_admin_session
  user = create(:admin_user)
  valid_session_for user
end

def valid_session_for user
  {:user_id => user.id}
end

def valid_super_user_session
{'fraction_non_alphanumeric': 0.09613914373088685, 'fraction_numerical': 0.00191131498470948, 'mean_word_length': 4.42279792746114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4583573', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1649, 'n_words': 478}