Module: SchemaDev::Rspec::Db
Defined Under Namespace
Modules: Helpers
Instance Method Summary collapse
- #configuration ⇒ Object
- #connect ⇒ Object
- #database ⇒ Object
- #logroot ⇒ Object
- #set_logger ⇒ Object
- #setup ⇒ Object
- #tmproot ⇒ Object
Instance Method Details
#configuration ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/schema_dev/rspec/db.rb', line 38 def configuration case @db when 'mysql' { "adapter" => 'mysql', "database" => database, "username" => ENV.fetch('MYSQL_DB_USER', 'schema_plus'), "encoding" => 'utf8', "min_messages" => 'warning' } when 'mysql2' { "adapter" => 'mysql2', "database" => database, "username" => ENV.fetch('MYSQL_DB_USER', 'schema_plus'), "encoding" => 'utf8', "min_messages" => 'warning' } when 'postgresql' { "adapter" => 'postgresql', "username" => ENV['POSTGRESQL_DB_USER'], "database" => database, "min_messages" => 'warning' } when 'sqlite3' { "adapter" => 'sqlite3', "database" => tmproot.join("#{database}.sqlite3").to_s } else raise "Unknown db adapter #{@db.inspect}" end end |
#connect ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/schema_dev/rspec/db.rb', line 73 def connect ActiveRecord::Base.configurations = { 'schema_dev' => configuration } ActiveRecord::Base.establish_connection :schema_dev case @db when 'sqlite3' ActiveRecord::Base.connection.execute "PRAGMA synchronous = OFF" end end |
#database ⇒ Object
33 34 35 36 |
# File 'lib/schema_dev/rspec/db.rb', line 33 def database @database ||= "schema_plus_test" # @database ||= (Dir["*.gemspec"].first || "schema_dev_test").sub(/\.gemspec$/, '') + "_test" end |
#logroot ⇒ Object
29 30 31 |
# File 'lib/schema_dev/rspec/db.rb', line 29 def logroot @logroot ||= Pathname.new('log').tap { |path| path.mkpath } end |
#set_logger ⇒ Object
82 83 84 85 86 |
# File 'lib/schema_dev/rspec/db.rb', line 82 def set_logger ruby = "#{RUBY_ENGINE}#{RUBY_VERSION}" activerecord = "activerecord#{ActiveRecord.version}" ActiveRecord::Base.logger = Logger.new(logroot.join("#{ruby}-#{activerecord}-#{@db}.log").open("w")) end |
#setup ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/schema_dev/rspec/db.rb', line 10 def setup @db = GemfileSelector.infer_db set_logger connect RSpec.configure do |config| config.include Helpers config.filter_run_excluding :postgresql => :only unless Helpers.postgresql? config.filter_run_excluding :postgresql => :skip if Helpers.postgresql? config.filter_run_excluding :mysql => :only unless Helpers.mysql? config.filter_run_excluding :mysql => :skip if Helpers.mysql? config.filter_run_excluding :sqlite3 => :only unless Helpers.sqlite3? config.filter_run_excluding :sqlite3 => :skip if Helpers.sqlite3? end end |
#tmproot ⇒ Object
25 26 27 |
# File 'lib/schema_dev/rspec/db.rb', line 25 def tmproot @tmproot ||= Pathname.new('tmp').tap { |path| path.mkpath } end |