Skip to content

Commit

Permalink
Add Spring and make it work for our configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Altmann committed Apr 2, 2016
1 parent 0cbaa24 commit 49b40ee
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ group :development do

# I18n Tools
gem 'i18n-tasks', '~> 0.8.3'

# Rails application preloader
gem 'spring'
end

group :test do
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ GEM
railties (>= 3.1, < 5.0)
slim (~> 3.0)
slop (3.6.0)
spring (1.6.4)
sprite-factory (1.6.1)
sprockets (2.12.3)
hike (~> 1.2)
Expand Down Expand Up @@ -786,6 +787,7 @@ DEPENDENCIES
simplecov-json
sinatra (>= 1.3.0)
slim-rails (>= 2.1.5)
spring
sprite-factory
sprockets
sqlite3
Expand All @@ -801,4 +803,4 @@ DEPENDENCIES
wiselinks

BUNDLED WITH
1.10.6
1.11.2
5 changes: 5 additions & 0 deletions bin/rails
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'
5 changes: 5 additions & 0 deletions bin/rake
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
15 changes: 15 additions & 0 deletions bin/spring
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
14 changes: 14 additions & 0 deletions config/initializers/in_memory_db.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Taken from https://gist.github.com/nmeylan/60aa53566d87d39ee6b0

def in_memory_database?
Rails.env == 'test' and
ActiveRecord::Base.connection.adapter_name.downcase.include?('sqlite') and
Rails.configuration.database_configuration['test']['database'] == ':memory:'
end

if in_memory_database?
require 'active_record/migration'
ActiveRecord::Migration.verbose = false
puts 'creating sqlite in memory database'
load "#{Rails.root}/db/schema.rb"
end
7 changes: 7 additions & 0 deletions config/spring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Taken from https://gist.github.com/nmeylan/60aa53566d87d39ee6b0

if defined?(Spring)
Spring.after_fork do
load "#{Rails.root}/config/initializers/in_memory_db.rb"
end
end
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
savon.mock!

Minitest.after_run do
if $suite_passing
if $suite_passing &&
# Don't run these if individual tests are run (TEST=tests/models/xxx_test.rb)
ENV['TEST'].blank?
rails_best_practices
brakeman
rubocop # TODO: uncomment and fix rubocop violations
Expand Down

0 comments on commit 49b40ee

Please sign in to comment.