combustion 0.7.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +39 -0
  4. data/.travis.yml +5 -5
  5. data/Appraisals +17 -0
  6. data/Gemfile +2 -0
  7. data/HISTORY +12 -0
  8. data/README.md +2 -2
  9. data/Rakefile +11 -1
  10. data/combustion.gemspec +26 -22
  11. data/exe/combust +3 -2
  12. data/gemfiles/rails_3.1.gemfile +1 -0
  13. data/gemfiles/rails_3.2.gemfile +1 -0
  14. data/gemfiles/rails_4.0.gemfile +1 -0
  15. data/gemfiles/rails_4.1.gemfile +1 -0
  16. data/gemfiles/rails_4.2.gemfile +2 -0
  17. data/gemfiles/rails_5.0.gemfile +2 -0
  18. data/gemfiles/rails_5.1.gemfile +2 -0
  19. data/gemfiles/rails_5.2.gemfile +8 -0
  20. data/lib/combustion/application.rb +23 -28
  21. data/lib/combustion/configurations/action_controller.rb +11 -0
  22. data/lib/combustion/configurations/action_mailer.rb +10 -0
  23. data/lib/combustion/configurations/active_record.rb +13 -0
  24. data/lib/combustion/database/load_schema.rb +14 -4
  25. data/lib/combustion/database/migrate.rb +29 -12
  26. data/lib/combustion/database/reset.rb +40 -21
  27. data/lib/combustion/database.rb +23 -14
  28. data/lib/combustion/databases/base.rb +4 -2
  29. data/lib/combustion/databases/firebird.rb +3 -1
  30. data/lib/combustion/databases/mysql.rb +55 -26
  31. data/lib/combustion/databases/oracle.rb +3 -1
  32. data/lib/combustion/databases/postgresql.rb +12 -11
  33. data/lib/combustion/databases/sql_server.rb +4 -2
  34. data/lib/combustion/databases/sqlite.rb +9 -7
  35. data/lib/combustion/generator.rb +16 -14
  36. data/lib/combustion.rb +34 -22
  37. data/spec/database_spec.rb +16 -12
  38. data/spec/dummy/db/migrate/20150717075542_create_dummy_test_table.rb +3 -1
  39. data/spec/dummy/db/migrate/20150717075543_create_dummy_test_table_in_another_db.rb +3 -1
  40. data/spec/dummy/lib/engine.rb +3 -1
  41. data/spec/dummy/spec/internal/app/models/model.rb +3 -1
  42. data/spec/dummy/spec/internal/app/models/model_in_another_db.rb +3 -1
  43. data/spec/dummy/spec/internal/config/routes.rb +3 -1
  44. data/spec/dummy/spec/internal/db/schema.rb +4 -1
  45. data/spec/spec_helper.rb +7 -6
  46. data/templates/config.ru +4 -2
  47. data/templates/routes.rb +3 -1
  48. data/templates/schema.rb +4 -1
  49. metadata +22 -4
  50. data/bin/literals +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4eecc61f64900b28416b12bdf1a10732233c945a
4
- data.tar.gz: c273b82455f6e3c05d08de860ecdaa32d4302990
2
+ SHA256:
3
+ metadata.gz: 0c1a369737ff21b225eee681a7ca0258f87a6141870885bc7cf4ce29ef6fd10c
4
+ data.tar.gz: 88f61f3c7f3d7f57b71f5be4a351c1bd93c374a81c5fcf76d8f2e6eae299de77
5
5
  SHA512:
6
- metadata.gz: f2ba1f8bcd5c49c1f3424fa8107b27df888c681e13e155b16ec5b8a918752cd0da972ea9f86e960a86efff4fe67d36c2dd333f89a77a5424c98457c1e4f25327
7
- data.tar.gz: 63145f149be8fae43c84fd0c6af4f706e07a74bf8dae2e76e0cc813eaa6bfa16a479093caef8fbf58fa57f6607b42edbfa1fbfd9f024e29d0a380c007c46f30c
6
+ metadata.gz: c5133bd2a0a3359d5562e0a62cd0561d63f7ce067bcf52773a48e09c1d54e1a7bdf2186683e87f82b98524f129a3e5c29aae792ccb0d1efd2f49abdfe556773f
7
+ data.tar.gz: 59f5f629ab28a8c6578e03617cedaec720a289917d4a1a37b1b713f63e0caf826aafe6f4addd8d0f78fb213abd173a6657b57cb4a9f87c764bcfd1f8a69571be
data/.gitignore CHANGED
@@ -3,8 +3,9 @@
3
3
  Gemfile.lock
4
4
  gemfiles/*.lock
5
5
  pkg/*
6
- .rvmrc
6
+ .rubocop-*-yml
7
7
  .ruby-version
8
+ .rvmrc
8
9
  spec/dummy/spec/internal/db/*.sqlite
9
10
  spec/dummy/spec/internal/test
10
11
  spec/dummy/spec/internal/test_another
data/.rubocop.yml ADDED
@@ -0,0 +1,39 @@
1
+ inherit_from:
2
+ - https://gist.githubusercontent.com/pat/ba3b8ffb1901bfe5439b460943b6b019/raw/.rubocop.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.2
6
+
7
+ Bundler/OrderedGems:
8
+ Exclude:
9
+ - 'gemfiles/*'
10
+
11
+ Layout/DotPosition:
12
+ EnforcedStyle: trailing
13
+
14
+ Layout/CaseIndentation:
15
+ EnforcedStyle: end
16
+
17
+ Layout/EndAlignment:
18
+ EnforcedStyleAlignWith: variable
19
+
20
+ Layout/IndentHeredoc:
21
+ Enabled: false
22
+
23
+ Metrics/BlockLength:
24
+ Exclude:
25
+ - 'combustion.gemspec'
26
+
27
+ Style/ClassAndModuleChildren:
28
+ Enabled: false
29
+
30
+ Style/Documentation:
31
+ Enabled: false
32
+
33
+ Style/FrozenStringLiteralComment:
34
+ Exclude:
35
+ - 'gemfiles/*'
36
+
37
+ Style/MultilineTernaryOperator:
38
+ Exclude:
39
+ - 'spec/dummy/db/migrate/*.rb'
data/.travis.yml CHANGED
@@ -5,16 +5,16 @@ env:
5
5
  - "DB_ADAPTER=postgresql"
6
6
  - "DB_ADAPTER=mysql2"
7
7
  rvm:
8
- - 2.2.6
9
- - 2.3.4
10
- - 2.4.1
8
+ - 2.2.10
9
+ - 2.3.7
10
+ - 2.4.4
11
+ - 2.5.1
11
12
  before_install:
12
13
  - gem update --system
13
14
  - gem install bundler
14
15
  before_script:
15
- - ./bin/literals
16
16
  - bundle exec appraisal install
17
- script: 'bundle exec appraisal rspec'
17
+ script: 'bundle exec appraisal rake'
18
18
  services:
19
19
  - mysql
20
20
  - postgresql
data/Appraisals CHANGED
@@ -1,33 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if RUBY_VERSION.to_f <= 2.3
2
4
  appraise "rails-3.1" do
3
5
  gem "rails", "~> 3.1.12"
4
6
  gem "mysql2", "~> 0.3.10"
7
+ gem "pg", "< 1.0"
5
8
  end
6
9
 
7
10
  appraise "rails-3.2" do
8
11
  gem "rails", "~> 3.2.22.5"
9
12
  gem "mysql2", "~> 0.3.10"
13
+ gem "pg", "< 1.0"
10
14
  end
11
15
 
12
16
  appraise "rails-4.0" do
13
17
  gem "rails", "~> 4.0.13"
14
18
  gem "mysql2", "~> 0.3.10"
19
+ gem "pg", "< 1.0"
15
20
  end
16
21
 
17
22
  appraise "rails-4.1" do
18
23
  gem "rails", "~> 4.1.16"
19
24
  gem "mysql2", "~> 0.3.13"
25
+ gem "pg", "< 1.0"
20
26
  end
21
27
 
22
28
  appraise "rails-4.2" do
23
29
  gem "rails", "~> 4.2.8"
30
+ gem "mysql2", "~> 0.4.4"
31
+ gem "pg", "< 1.0"
24
32
  end
25
33
  end
26
34
 
27
35
  appraise "rails-5.0" do
28
36
  gem "rails", "~> 5.0.2"
37
+ gem "mysql2", "~> 0.4.4"
38
+ gem "pg", "< 1.0"
29
39
  end
30
40
 
31
41
  appraise "rails-5.1" do
32
42
  gem "rails", "~> 5.1.0"
43
+ gem "mysql2", "~> 0.4.4"
44
+ gem "pg", "< 1.0"
45
+ end
46
+
47
+ appraise "rails-5.2" do
48
+ gem "rails", "~> 5.2.0"
49
+ gem "mysql2", "~> 0.5.0"
33
50
  end
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "http://rubygems.org"
2
4
 
3
5
  gemspec
data/HISTORY CHANGED
@@ -1,3 +1,15 @@
1
+ 0.9.1 - April 25th 2018
2
+ * Fix Rails 5.2 compatibility by not setting the deprecated secret_token configuration option.
3
+
4
+ 0.9.0 - March 26th 2018
5
+ * Only reset databases that are either custom or the current one (Moritz Winter).
6
+ * More consistency around environment handling (rather than presuming it's always the test environment).
7
+
8
+ 0.8.0 - February 1st 2018
9
+ * Rails 5.2.0 support.
10
+ * Requiring digest from std-lib directly.
11
+ * Refactoring for cleaner code.
12
+
1
13
  0.7.0 - June 20th 2017
2
14
  * Confirm support for MRI frozen string literals.
3
15
  * Hide migration output (Michael Grosser).
data/README.md CHANGED
@@ -10,10 +10,10 @@ Get the gem into either your gemspec or your Gemfile, depending on how you manag
10
10
 
11
11
  ```ruby
12
12
  # gemspec
13
- gem.add_development_dependency 'combustion', '~> 0.7.0'
13
+ gem.add_development_dependency 'combustion', '~> 0.9.1'
14
14
 
15
15
  # Gemfile
16
- gem 'combustion', '~> 0.7.0', :group => :test
16
+ gem 'combustion', '~> 0.9.1'
17
17
  ```
18
18
 
19
19
  In your `spec_helper.rb`, get Combustion to set itself up - which has to happen before you introduce `rspec/rails` and - if being used - `capybara/rails`. Here's an example within context:
data/Rakefile CHANGED
@@ -1 +1,11 @@
1
- require 'bundler/gem_tasks'
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new(:rubocop)
9
+
10
+ Rake::Task["default"].clear if Rake::Task.task_defined?("default")
11
+ task :default => %i[ rubocop spec ]
data/combustion.gemspec CHANGED
@@ -1,30 +1,34 @@
1
- # -*- encoding: utf-8 -*-
1
+ # frozen_string_literal: true
2
+
2
3
  Gem::Specification.new do |s|
3
- s.name = 'combustion'
4
- s.version = '0.7.0'
5
- s.authors = ['Pat Allan']
6
- s.email = ['pat@freelancing-gods.com']
7
- s.homepage = 'https://github.com/pat/combustion'
8
- s.summary = 'Elegant Rails Engine Testing'
9
- s.description = 'Test your Rails Engines without needing a full Rails app'
10
- s.license = 'MIT'
4
+ s.name = "combustion"
5
+ s.version = "0.9.1"
6
+ s.authors = ["Pat Allan"]
7
+ s.email = ["pat@freelancing-gods.com"]
8
+ s.homepage = "https://github.com/pat/combustion"
9
+ s.summary = "Elegant Rails Engine Testing"
10
+ s.description = "Test your Rails Engines without needing a full Rails app"
11
+ s.license = "MIT"
11
12
 
12
- s.rubyforge_project = 'combustion'
13
+ s.rubyforge_project = "combustion"
13
14
 
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- exe/*`.split("\n").map{ |f| File.basename(f) }
17
- s.bindir = 'exe'
18
- s.require_paths = ['lib']
17
+ s.executables = `git ls-files -- exe/*`.split("\n").map do |file|
18
+ File.basename(file)
19
+ end
20
+ s.bindir = "exe"
21
+ s.require_paths = ["lib"]
19
22
 
20
- s.add_runtime_dependency 'activesupport', '>= 3.0.0'
21
- s.add_runtime_dependency 'railties', '>= 3.0.0'
22
- s.add_runtime_dependency 'thor', '>= 0.14.6'
23
+ s.add_runtime_dependency "activesupport", ">= 3.0.0"
24
+ s.add_runtime_dependency "railties", ">= 3.0.0"
25
+ s.add_runtime_dependency "thor", ">= 0.14.6"
23
26
 
24
- s.add_development_dependency 'appraisal', '~> 2.1.0'
25
- s.add_development_dependency 'mysql2'
26
- s.add_development_dependency 'pg'
27
- s.add_development_dependency 'rails'
28
- s.add_development_dependency 'rspec'
29
- s.add_development_dependency 'sqlite3'
27
+ s.add_development_dependency "appraisal", "~> 2.1.0"
28
+ s.add_development_dependency "mysql2"
29
+ s.add_development_dependency "pg"
30
+ s.add_development_dependency "rails"
31
+ s.add_development_dependency "rspec"
32
+ s.add_development_dependency "rubocop", "~> 0.54.0"
33
+ s.add_development_dependency "sqlite3"
30
34
  end
data/exe/combust CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- mode: ruby -*-
3
+ # frozen_string_literal: true
3
4
 
4
- require 'combustion'
5
- require 'combustion/generator'
5
+ require "combustion"
6
+ require "combustion/generator"
6
7
 
7
8
  Combustion::Generator.start
@@ -4,5 +4,6 @@ source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 3.1.12"
6
6
  gem "mysql2", "~> 0.3.10"
7
+ gem "pg", "< 1.0"
7
8
 
8
9
  gemspec :path => "../"
@@ -4,5 +4,6 @@ source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 3.2.22.5"
6
6
  gem "mysql2", "~> 0.3.10"
7
+ gem "pg", "< 1.0"
7
8
 
8
9
  gemspec :path => "../"
@@ -4,5 +4,6 @@ source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.0.13"
6
6
  gem "mysql2", "~> 0.3.10"
7
+ gem "pg", "< 1.0"
7
8
 
8
9
  gemspec :path => "../"
@@ -4,5 +4,6 @@ source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.1.16"
6
6
  gem "mysql2", "~> 0.3.13"
7
+ gem "pg", "< 1.0"
7
8
 
8
9
  gemspec :path => "../"
@@ -3,5 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.8"
6
+ gem "mysql2", "~> 0.4.4"
7
+ gem "pg", "< 1.0"
6
8
 
7
9
  gemspec :path => "../"
@@ -3,5 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0.2"
6
+ gem "mysql2", "~> 0.4.4"
7
+ gem "pg", "< 1.0"
6
8
 
7
9
  gemspec :path => "../"
@@ -3,5 +3,7 @@
3
3
  source "http://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.1.0"
6
+ gem "mysql2", "~> 0.4.4"
7
+ gem "pg", "< 1.0"
6
8
 
7
9
  gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.0"
6
+ gem "mysql2", "~> 0.5.0"
7
+
8
+ gemspec :path => "../"
@@ -1,15 +1,21 @@
1
- require 'securerandom'
2
- Rails.env = ENV['RAILS_ENV'] || 'test'
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require "digest"
5
+ Rails.env = ENV["RAILS_ENV"] || "test"
3
6
 
4
7
  module Combustion
5
8
  class Application < Rails::Application
9
+ version = Rails.version.to_f
10
+
6
11
  # Core Settings
7
12
  config.cache_classes = true
8
- config.whiny_nils = true if Rails.version.to_s < '4.0.0'
9
13
  config.consider_all_requests_local = true
10
- config.secret_token = Digest::SHA1.hexdigest Time.now.to_s
11
14
  config.eager_load = Rails.env.production?
12
- config.secret_key_base = SecureRandom.hex if Rails.version.to_s >= '4.0.0'
15
+
16
+ config.secret_key_base = SecureRandom.hex if version >= 4.0
17
+ config.whiny_nils = true if version < 4.0
18
+ config.secret_token = Digest::SHA1.hexdigest Time.now.to_s if version < 5.2
13
19
 
14
20
  # ActiveSupport Settings
15
21
  config.active_support.deprecation = :stderr
@@ -20,31 +26,20 @@ module Combustion
20
26
  def self.configure_for_combustion
21
27
  config.root = File.expand_path File.join(Dir.pwd, Combustion.path)
22
28
 
23
- if defined?(ActiveRecord::Railtie) && ::ActiveRecord.constants.include?(:MassAssignmentSecurity)
24
- # Turn on ActiveRecord attribute whitelisting
25
- # This way the dummy app matches new rails apps re: this setting
26
- config.active_record.whitelist_attributes = true
27
- config.active_record.mass_assignment_sanitizer = :strict
28
- end
29
-
30
- if defined?(ActionController::Railtie)
31
- config.action_dispatch.show_exceptions = false
32
- config.action_controller.perform_caching = false
33
- config.action_controller.allow_forgery_protection = false
34
- end
35
-
36
- if defined?(ActionMailer::Railtie)
37
- config.action_mailer.delivery_method = :test
38
- config.action_mailer.default_url_options = {:host => 'www.example.com'}
39
- end
40
-
41
- if defined?(Sprockets)
42
- config.assets.enabled = true
43
- end
29
+ Combustion::Configurations::ActiveRecord.call config
30
+ Combustion::Configurations::ActionController.call config
31
+ Combustion::Configurations::ActionMailer.call config
32
+
33
+ config.assets.enabled = true if defined?(Sprockets)
44
34
  end
45
35
 
46
- initializer :load_customized_environment_for_combustion, :before => :load_environment_config, :group => :all do
47
- Combustion::Application.class_eval(&Combustion.setup_environment) if Combustion.setup_environment
36
+ initializer(
37
+ :load_customized_environment_for_combustion,
38
+ :before => :load_environment_config,
39
+ :group => :all
40
+ ) do
41
+ next unless Combustion.setup_environment
42
+ Combustion::Application.class_eval(&Combustion.setup_environment)
48
43
  end
49
44
  end
50
45
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Combustion::Configurations::ActionController
4
+ def self.call(config)
5
+ return unless defined?(ActionController::Railtie)
6
+
7
+ config.action_dispatch.show_exceptions = false
8
+ config.action_controller.perform_caching = false
9
+ config.action_controller.allow_forgery_protection = false
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Combustion::Configurations::ActionMailer
4
+ def self.call(config)
5
+ return unless defined?(ActionMailer::Railtie)
6
+
7
+ config.action_mailer.delivery_method = :test
8
+ config.action_mailer.default_url_options = {:host => "www.example.com"}
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Combustion::Configurations::ActiveRecord
4
+ def self.call(config)
5
+ return unless defined?(ActiveRecord::Railtie)
6
+ return unless ::ActiveRecord.constants.include?(:MassAssignmentSecurity)
7
+
8
+ # Turn on ActiveRecord attribute whitelisting
9
+ # This way the dummy app matches new rails apps re: this setting
10
+ config.active_record.whitelist_attributes = true
11
+ config.active_record.mass_assignment_sanitizer = :strict
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Combustion::Database::LoadSchema
2
4
  UnknownSchemaFormat = Class.new StandardError
3
5
 
@@ -10,11 +12,9 @@ class Combustion::Database::LoadSchema
10
12
 
11
13
  case schema_format
12
14
  when :ruby
13
- load Rails.root.join('db', 'schema.rb')
15
+ load_ruby_schema
14
16
  when :sql
15
- ActiveRecord::Base.connection.execute(
16
- File.read(Rails.root.join('db', 'structure.sql'))
17
- )
17
+ load_sql_schema
18
18
  else
19
19
  raise UnknownSchemaFormat, "Unknown schema format: #{schema_format}"
20
20
  end
@@ -22,6 +22,16 @@ class Combustion::Database::LoadSchema
22
22
 
23
23
  private
24
24
 
25
+ def load_ruby_schema
26
+ load Rails.root.join("db", "schema.rb")
27
+ end
28
+
29
+ def load_sql_schema
30
+ ActiveRecord::Base.connection.execute(
31
+ File.read(Rails.root.join("db", "structure.sql"))
32
+ )
33
+ end
34
+
25
35
  def schema_format
26
36
  Combustion.schema_format
27
37
  end
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Combustion::Database::Migrate
2
4
  def self.call
3
5
  new.call
4
6
  end
5
7
 
6
8
  def call
7
- if ActiveRecord::VERSION::STRING >= '3.1.0'
9
+ if ActiveRecord::VERSION::STRING.to_f >= 5.2
10
+ migration_context.migrate
11
+ elsif ActiveRecord::VERSION::STRING.to_f >= 3.1
8
12
  migrator.migrate paths, nil
9
13
  else
10
14
  paths.each { |path| migrator.migrate path, nil }
@@ -17,24 +21,37 @@ class Combustion::Database::Migrate
17
21
  if migrator.respond_to?(:migrations_paths)
18
22
  migrator.migrations_paths
19
23
  else
20
- Array('db/migrate/')
24
+ Array("db/migrate/")
25
+ end
26
+ end
27
+
28
+ def engine_migration_paths
29
+ migration_paths = Rails.application.paths["db/migrate"].to_a
30
+
31
+ if engine_paths_exist_in?(migration_paths)
32
+ migration_paths
33
+ else
34
+ base_migration_paths + migration_paths
21
35
  end
22
36
  end
23
37
 
38
+ def engine_path
39
+ Rails.application.root.sub(::Combustion.path, "")
40
+ end
41
+
42
+ def engine_paths_exist_in?(paths)
43
+ paths.include?(engine_path.join("db/migrate").to_s)
44
+ end
45
+
46
+ def migration_context
47
+ ActiveRecord::MigrationContext.new paths
48
+ end
49
+
24
50
  def migrator
25
51
  @migrator ||= ActiveRecord::Migrator
26
52
  end
27
53
 
28
54
  def paths
29
- engine_path = Rails.application.root.sub(::Combustion.path, '')
30
- migration_paths = Rails.application.paths['db/migrate'].to_a
31
-
32
- if migration_paths.include?(engine_path.join('db/migrate').to_s)
33
- paths = []
34
- else
35
- paths = base_migration_paths
36
- end
37
-
38
- (paths + migration_paths + [File.join(Rails.root, 'db/migrate')]).uniq
55
+ (engine_migration_paths + [File.join(Rails.root, "db/migrate")]).uniq
39
56
  end
40
57
  end
@@ -1,20 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Combustion::Database::Reset
2
4
  UnsupportedDatabase = Class.new StandardError
3
5
 
6
+ OPERATOR_PATTERNS = {
7
+ Combustion::Databases::MySQL => [/mysql/],
8
+ Combustion::Databases::PostgreSQL => [/postgres/, /postgis/],
9
+ Combustion::Databases::SQLite => [/sqlite/],
10
+ Combustion::Databases::SQLServer => [/sqlserver/],
11
+ Combustion::Databases::Oracle => %w[ oci oracle ],
12
+ Combustion::Databases::Firebird => %w[ firebird ]
13
+ }.freeze
14
+
15
+ RAILS_DEFAULT_ENVIRONMENTS = %w[ development production test ].freeze
16
+
4
17
  def self.call
5
18
  new.call
6
19
  end
7
20
 
8
21
  def initialize
9
- ActiveRecord::Base.configurations = YAML.load(
10
- ERB.new(File.read("#{Rails.root}/config/database.yml")).result
22
+ ActiveRecord::Base.configurations = YAML.safe_load(
23
+ ERB.new(database_yaml).result, [], [], true
11
24
  )
12
25
  end
13
26
 
14
27
  def call
15
- ActiveRecord::Base.configurations.values.each do |configuration|
16
- adapter = configuration['adapter'] ||
17
- configuration['url'].split('://').first
28
+ resettable_db_configs.each_value do |configuration|
29
+ adapter = configuration["adapter"] ||
30
+ configuration["url"].split("://").first
18
31
 
19
32
  operator_class(adapter).new(configuration).reset
20
33
  end
@@ -22,23 +35,29 @@ class Combustion::Database::Reset
22
35
 
23
36
  private
24
37
 
38
+ def database_yaml
39
+ File.read "#{Rails.root}/config/database.yml"
40
+ end
41
+
25
42
  def operator_class(adapter)
26
- @operator ||= case adapter
27
- when /mysql/
28
- Combustion::Databases::MySQL
29
- when /postgres/, /postgis/
30
- Combustion::Databases::PostgreSQL
31
- when /sqlite/
32
- Combustion::Databases::SQLite
33
- when /sqlserver/
34
- Combustion::Databases::SQLServer
35
- when 'oci', 'oracle'
36
- Combustion::Databases::Oracle
37
- when 'firebird'
38
- Combustion::Databases::Firebird
39
- else
40
- raise UnsupportedDatabase,
41
- "Unsupported database type: #{adapter}"
43
+ klass = nil
44
+ OPERATOR_PATTERNS.each do |operator, keys|
45
+ klass = operator if keys.any? { |key| adapter[key] }
46
+ end
47
+ return klass if klass
48
+
49
+ raise UnsupportedDatabase, "Unsupported database type: #{adapter}"
50
+ end
51
+
52
+ # All database configs except Rails default environments
53
+ # that are not currently in use
54
+ def resettable_db_configs
55
+ unused_environments = RAILS_DEFAULT_ENVIRONMENTS - [Rails.env.to_s]
56
+ resettable_environments = ActiveRecord::Base.configurations.keys -
57
+ unused_environments
58
+
59
+ ActiveRecord::Base.configurations.select do |name|
60
+ resettable_environments.include?(name)
42
61
  end
43
62
  end
44
63
  end