Sha256: 75c0719ceabdb831555421aa3ff937124cc9d4b3a90410bc0b421ceaeeb07bd6

Contents?: true

Size: 1.53 KB

Versions: 12

Compression:

Stored size: 1.53 KB

Contents

ENV["RAILS_ENV"] = "test"

require 'test/unit'
require 'rubygems'
require 'yaml'
require 'active_record'
require 'mysql'

require 'app/models/gmaps4rails/widget.rb'

def gmaps4rails_widget( fixture_name )
  id = @@fixtures['gmaps4rails_widget'][ fixture_name.to_s ][ 'id' ]
  gmaps4rails::Widget.find( id )
end

def load_schema
  config = YAML::load( IO.read( File.dirname(__FILE__) + '/database.yml') )

  # Manually initialize the database
  conn = Mysql.real_connect( config['mysql']['host'], config['mysql']['username'], config['mysql']['password'] )
  conn.query( "CREATE DATABASE IF NOT EXISTS #{config['mysql']['database']}" )
  
  ActiveRecord::Base.establish_connection( config['mysql'] )
  ActiveRecord::Base.connection()
  
  load(File.dirname(__FILE__) + "/../" +
    "lib/rails/generators/gmaps4rails/templates/schema.rb")

  @@fixtures = {}
  
  load_fixture( 'gmaps4rails_widget' )
end

def load_fixture( table )
  @@fixtures[ table ] = {}
  fixture = YAML::load( IO.read( File.dirname(__FILE__) + "/fixtures/#{table}.yml") )
  @@fixtures[ table ] = fixture

  klass = class_eval table.titleize.gsub(/ /, '::')

  fixture.each do |record_name, record|
    record.each do |column, value|
      if ( match = column.match(/(.*)_id/) )
        fixture_reference = "gmaps4rails_" + match[1].pluralize
        if value.is_a? Symbol
          r = class_eval "#{fixture_reference}( '#{value}' )"
          record[ column ] = r.id
        end
      end
    end
      
    r = klass.create( record )
    @@fixtures[ table ][ record_name ][ 'id' ] = r.id
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gmaps4rails-0.3.0 test/test_helper.rb
gmaps4rails-0.2.6 test/test_helper.rb
gmaps4rails-0.2.5 test/test_helper.rb
gmaps4rails-0.2.3 test/test_helper.rb
gmaps4rails-0.2.2 test/test_helper.rb
gmaps4rails-0.2.1 test/test_helper.rb
gmaps4rails-0.2.0 test/test_helper.rb
gmaps4rails-0.1.0 test/test_helper.rb
gmaps4rails-0.0.14 test/test_helper.rb
gmaps4rails-0.0.2 test/test_helper.rb
gmaps4rails-0.0.1 test/test_helper.rb
gmaps4rails-0.0.0 test/test_helper.rb