You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cartodb/spec/spec_helper.rb

138 lines
4.0 KiB

require 'mocha'
require 'mocha/api'
require 'helpers/spec_helper_helpers'
require 'helpers/named_maps_helper'
require 'helpers/unique_names_helper'
require 'database_cleaner/active_record'
require 'support/database_cleaner'
require 'support/message_broker_stubs'
require 'support/shared_entities_spec_helper'
9 years ago
# This file is copied to spec/ when you run 'rails generate rspec:install'
raise %(Cannot run tests in an env other than 'test', RAILS_ENV=#{Rails.env}) unless Rails.env.test?
require File.expand_path('../../config/environment', __FILE__)
# Needed because load order changes in Ruby 2.3+, related to https://github.com/rspec/rspec-rails/pull/1372
# We can remove this if we upgrade to rspec 3+
ActiveRecord.send(:remove_const, :TestFixtures) if ActiveRecord.const_defined?(:TestFixtures)
require 'rspec/rails'
require 'spec_helper_common'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
9 years ago
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Inline Resque for queue handling
Resque.inline = true
# host_validation is set to support `example.com` emails in specs
# in production we do check for the existance of mx records associated to the domain
EmailAddress::Config.configure(local_format: :conventional, host_validation: :syntax)
RSpec.configure do |config|
config.include SpecHelperHelpers
config.include CartoDB::Factories
config.include HelperMethods
config.include NamedMapsHelper
5 years ago
config.include Capybara::DSL
config.include FactoryBot::Syntax::Methods
config.include SharedEntitiesSpecHelper
config.mock_with :mocha
config.after(:each) do
Delorean.back_to_the_present
end
unless ENV['PARALLEL']
config.before(:suite) do
CartoDB::RedisTest.up
end
end
config.before(:all) do
purgue_databases
clean_redis_databases unless ENV['PARALLEL']
CartoDB::UserModule::DBService.any_instance.stubs(:create_ghost_tables_event_trigger)
end
config.after(:all) do
purgue_databases
end
ci tests (#15378) * add google cloud build files for ci * add github workflow for NEWS.md check * update gitignore to ignore docker files and related files * adapt tests for the new ci environment on GCB * update config and ci script to run on the new ci environment * changing python requirements to work with pg11 * Commenting federated tables local commands * split big tests into smaller parts * remove disabled tests * adjust cloud build timeouts * Divide user tests by common concept(ish) * remove useless redis test code * add slack notification on master build failure * add cloudbuild file for postgres 12 tests * add new tests to makefile * split user migration tests * extract common logic to a module * refactor user specs * fix user migration tests * remove some silent errors and warnings in specs * update invalidation parameters for tests and development * reduce noise in logs * deleted spec that has been pending for ages * moar trash messages * avoid some race conditions * reorder tests * extract refactored behavior to a different spec file * remove likes specs * regroup tests * reorder tests * reset order from last run in CI * avoid repeat ports for file server * avoid race condition * avoid tests to fail due to dependent users * Remove .git from cartodb before starting compose * we don't need to start builder for the tests * reorganize test * no need to destroy account types * increase statement timeout for carto_db_test * Fix redirection and define TRASH_MESSAGES once * improve test tear down * avoid global tear down in CI * update cloudbuild for pg12 Co-authored-by: Alberto Hernández <albertoh@cartodb.com> Co-authored-by: Esther Lozano <esloho@gmail.com> Co-authored-by: Alberto Romeu <alrocar@users.noreply.github.com>
5 years ago
unless ENV['PARALLEL'] || ENV['BUILD_ID']
config.after(:suite) do
CartoDB::RedisTest.down
end
14 years ago
end
module Rack
module Test
module Methods
def build_rack_mock_session
Rack::MockSession.new(app, host)
end
def with_host(temp_host)
old_host = host
host! temp_host
yield
ensure
host! old_host
end
end
end
end
end
def superadmin_headers
5 years ago
http_json_authorization_headers(Cartodb.get_config(:superadmin, 'username'),
Cartodb.get_config(:superadmin, 'password'))
end
def org_metadata_api_headers
5 years ago
http_json_authorization_headers(Cartodb.get_config(:org_metadata_api, 'username'),
Cartodb.get_config(:org_metadata_api, 'password'))
end
def http_json_authorization_headers(user, password)
http_json_headers.merge(
"HTTP_AUTHORIZATION" => ActionController::HttpAuthentication::Basic.encode_credentials(user, password),
"HTTP_ACCEPT" => "application/json")
end
def http_json_headers
9 years ago
{ "CONTENT_TYPE" => "application/json", :format => "json" }
end
def fake_data_path(filename)
Rails.root.join("db/fake_data/#{filename}").to_s
end
def login_page_response?(response)
response.status == 200 && response.body.include?("title=\"Email or username\"")
end
def post_session(params = {})
host! "#{params[:user].username}.localhost.lan"
request_params = { email: params[:user].email, password: params[:password] }
request_params[:user_domain] = params[:organization].name if params[:organization]
post(create_session_url(request_params))
end
def parse_set_cookie_header(header)
kv_pairs = header.split(/\s*;\s*/).map do |attr|
k, v = attr.split '='
[ k, v || nil ]
end
Hash[ kv_pairs ]
end
def set_cookies_for_next_request(previous_response)
received_cookies = parse_set_cookie_header(previous_response.headers["Set-Cookie"])
received_cookies.each { |key, value| cookies[key] = value }
4 years ago
end