forked from ATIX-AG/foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #15751 - replace spork with spring in development
To make use of it, run bin/rails and bin/rake rather than plain rails or rake commands, and run `spring status` or `spring stop` to check and stop current background processes. Test log removal has moved to the logging framework as the file would not be recreated after being deleted in the test helper, since the Rails environment and logger are not reloaded on each `rake test`.
- Loading branch information
Showing
11 changed files
with
95 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,4 @@ custom_plan.rb | |
pkg/ | ||
config/hooks | ||
*.csv | ||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
begin | ||
load File.expand_path('../spring', __FILE__) | ||
rescue LoadError => e | ||
raise unless e.message.include?('spring') | ||
end | ||
APP_PATH = File.expand_path('../../config/application', __FILE__) | ||
require_relative '../config/boot' | ||
require 'rails/commands' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
#!/usr/bin/env ruby | ||
begin | ||
load File.expand_path('../spring', __FILE__) | ||
rescue LoadError => e | ||
raise unless e.message.include?('spring') | ||
end | ||
require_relative '../config/boot' | ||
require 'rake' | ||
Rake.application.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# This file loads spring without using Bundler, in order to be fast. | ||
# It gets overwritten when you run the `spring binstub` command. | ||
|
||
unless defined?(Spring) | ||
require 'rubygems' | ||
require 'bundler' | ||
|
||
if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) | ||
Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) } | ||
gem 'spring', match[1] | ||
require 'spring/binstub' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ | |
|
||
gem 'bullet' | ||
gem "parallel_tests" | ||
gem 'spring', '~> 1.0' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%w( | ||
.ruby-version | ||
.rbenv-vars | ||
config/email.yaml | ||
config/ignored_environments.yml | ||
config/logging.yaml | ||
config/settings.yaml | ||
tmp/restart.txt | ||
tmp/caching-dev.txt | ||
) + Dir["config/settings.plugins.d/*.yaml"].each { |path| Spring.watch(path) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,12 @@ | ||
Spork.prefork do | ||
unless ActiveRecord::Base.connection.table_exists?(:test_facets) | ||
ActiveRecord::Base.connection.create_table :test_facets do |t| | ||
# :id is created automatically | ||
t.integer :host_id | ||
end | ||
unless ActiveRecord::Base.connection.table_exists?(:test_facets) | ||
ActiveRecord::Base.connection.create_table :test_facets do |t| | ||
# :id is created automatically | ||
t.integer :host_id | ||
end | ||
unless ActiveRecord::Base.connection.table_exists?(:module_test_facets) | ||
ActiveRecord::Base.connection.create_table :module_test_facets do |t| | ||
# :id is created automatically | ||
t.integer :host_id | ||
end | ||
end | ||
unless ActiveRecord::Base.connection.table_exists?(:module_test_facets) | ||
ActiveRecord::Base.connection.create_table :module_test_facets do |t| | ||
# :id is created automatically | ||
t.integer :host_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,57 @@ | ||
require 'rubygems' | ||
require 'fileutils' | ||
require 'spork' | ||
|
||
Spork.prefork do | ||
# Loading more in this block will cause your tests to run faster. However, | ||
# if you change any configuration or code from libraries loaded here, you'll | ||
# need to restart spork for it take effect. | ||
ENV["RAILS_ENV"] = "test" | ||
require File.expand_path('../../config/environment', __FILE__) | ||
require 'rails/test_help' | ||
require 'mocha/mini_test' | ||
require 'factory_girl_rails' | ||
require 'functional/shared/basic_rest_response_test' | ||
require 'facet_test_helper' | ||
require 'active_support_test_case_helper' | ||
|
||
# Use our custom test runner, and register a fake plugin to skip a specific test | ||
Foreman::Plugin.register :skip_test do | ||
tests_to_skip "CustomRunnerTest" => [ "custom runner is working" ] | ||
end | ||
|
||
# Remove previous test log to speed tests up | ||
# Comment out these lines to enable test logging | ||
test_log = File.expand_path('../../log/test.log', __FILE__) | ||
FileUtils.rm(test_log) if File.exist?(test_log) | ||
# Turn of Apipie validation for tests | ||
Apipie.configuration.validate = false | ||
|
||
ENV["RAILS_ENV"] = "test" | ||
require File.expand_path('../../config/environment', __FILE__) | ||
require 'rails/test_help' | ||
require 'mocha/mini_test' | ||
require 'factory_girl_rails' | ||
require 'functional/shared/basic_rest_response_test' | ||
require 'facet_test_helper' | ||
require 'active_support_test_case_helper' | ||
# To prevent Postgres' errors "permission denied: "RI_ConstraintTrigger" | ||
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' | ||
ActiveRecord::Migration.execute "SET CONSTRAINTS ALL DEFERRED;" | ||
end | ||
|
||
# Use our custom test runner, and register a fake plugin to skip a specific test | ||
Foreman::Plugin.register :skip_test do | ||
tests_to_skip "CustomRunnerTest" => [ "custom runner is working" ] | ||
end | ||
class ActionView::TestCase | ||
helper Rails.application.routes.url_helpers | ||
end | ||
|
||
# Turn of Apipie validation for tests | ||
Apipie.configuration.validate = false | ||
::Rails::Engine.subclasses.map(&:instance).each do |engine| | ||
support_file = "#{engine.root}/test/support/foreman_test_helper_additions.rb" | ||
require support_file if File.exist?(support_file) | ||
end | ||
|
||
# To prevent Postgres' errors "permission denied: "RI_ConstraintTrigger" | ||
if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' | ||
ActiveRecord::Migration.execute "SET CONSTRAINTS ALL DEFERRED;" | ||
end | ||
class ActionController::TestCase | ||
include ::BasicRestResponseTest | ||
setup :setup_set_script_name, :set_api_user, :turn_of_login | ||
|
||
class ActionView::TestCase | ||
helper Rails.application.routes.url_helpers | ||
def turn_of_login | ||
SETTINGS[:require_ssl] = false | ||
end | ||
|
||
::Rails::Engine.subclasses.map(&:instance).each do |engine| | ||
support_file = "#{engine.root}/test/support/foreman_test_helper_additions.rb" | ||
require support_file if File.exist?(support_file) | ||
def setup_set_script_name | ||
@request.env["SCRIPT_NAME"] = @controller.config.relative_url_root | ||
end | ||
end | ||
|
||
Spork.each_run do | ||
# This code will be run each time you run your specs. | ||
class ActionController::TestCase | ||
include ::BasicRestResponseTest | ||
setup :setup_set_script_name, :set_api_user, :turn_of_login | ||
|
||
def turn_of_login | ||
SETTINGS[:require_ssl] = false | ||
end | ||
|
||
def setup_set_script_name | ||
@request.env["SCRIPT_NAME"] = @controller.config.relative_url_root | ||
end | ||
|
||
def set_api_user | ||
return unless self.class.to_s[/api/i] | ||
set_basic_auth(users(:apiadmin), "secret") | ||
end | ||
def set_api_user | ||
return unless self.class.to_s[/api/i] | ||
set_basic_auth(users(:apiadmin), "secret") | ||
end | ||
|
||
def set_basic_auth(user, password) | ||
login = user.is_a?(User) ? user.login : user | ||
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(login, password) | ||
@request.env['CONTENT_TYPE'] = 'application/json' | ||
@request.env['HTTP_ACCEPT'] = 'application/json' | ||
end | ||
def set_basic_auth(user, password) | ||
login = user.is_a?(User) ? user.login : user | ||
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(login, password) | ||
@request.env['CONTENT_TYPE'] = 'application/json' | ||
@request.env['HTTP_ACCEPT'] = 'application/json' | ||
end | ||
end |