Sha256: 6299b8cc5b9da5c23b584f7bb20008a22d0aab2104bc0da7565d920c9d553c8a

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require 'rspec'

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 'activerecord_enum'

ActiveRecord::Base.configurations = db_config
ActiveRecord::Base.establish_connection db
RSpec.configure do |c|
  c.filter_run_excluding :db_support => ! db_config[db]["supports_enums"]
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord_enum-0.2.0 spec/spec_helper.rb