Sha256: 6a6666d85632c6b1349696d895d2f0abb315d88e6af7d31e57c6808cb32dd6ee
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
require 'rspec' require 'yaml' def db ENV["DB"] || "mysql" end def load_schema filename # silence verbose schema loading original_stdout = $stdout $stdout = StringIO.new root = File.expand_path(File.dirname(__FILE__)) load root + "/schema/#{filename}.rb" ensure $stdout = original_stdout end def dumped_schema stream = StringIO.new ActiveRecord::SchemaDumper.ignore_tables = [] ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) stream.string.lines.select {|l| /^\s*#/.match(l).nil? }.join end def column_props table, column case db when "mysql" result = ActiveRecord::Base.connection.select_one "SHOW FIELDS FROM #{table} WHERE Field='#{column}'" { :type => result["Type"], :default => result["Default"], :null => ( result["Null"] == "YES" ) } when "sqlite" result = ActiveRecord::Base.connection.select_value "SELECT sql FROM sqlite_master WHERE type='table' AND name='#{table}'" matches = /"#{column}" ([^[:space:]]+) (?:DEFAULT '([^[:space:]]+)')?( NOT NULL)?,/.match result { :type => matches[1], :default => matches[2], :null => matches[3].nil? } end end db_config = YAML::load(IO.read("spec/database.yml")) require db_config[db]["adapter"] require 'native_enum' ActiveRecord::Base.configurations = db_config ActiveRecord::Base.establish_connection db.to_sym RSpec.configure do |c| c.filter_run_excluding :db_support => ! db_config[db]["supports_enums"] end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
native_enum-1.0.0 | spec/spec_helper.rb |
native_enum-1.0.0pre1 | spec/spec_helper.rb |