lib/temping.rb in temping-1.2.0 vs lib/temping.rb in temping-1.3.0

- old
+ new

@@ -1,28 +1,31 @@ require 'active_record' module Temping - ModelAlreadyDefined = Class.new(StandardError) - def self.included(base) - ActiveRecord::Base.configurations['temping'] = { :adapter => 'sqlite3', :database => ':memory:' } - ActiveRecord::Base.establish_connection 'temping' unless ActiveRecord::Base.connected? + unless ActiveRecord::Base.connected? + ActiveRecord::Base.configurations['temping'] = { + :adapter => 'sqlite3', :database => ':memory:' + } + ActiveRecord::Base.establish_connection 'temping' + end end def create_model(model_name, &block) - unless eval("defined?(#{model_name.to_s.classify})") - factory = ModelFactory.new(model_name, &block) + model_class = model_name.to_s.classify + unless eval("defined?(#{model_class})") + factory = ModelFactory.new(model_class, &block) factory.klass end end class ModelFactory attr_accessor :klass - def initialize(model_name, &block) + def initialize(model_class, &block) @klass = Class.new(ActiveRecord::Base) - Object.const_set(model_name.to_s.classify, @klass) + Object.const_set(model_class, @klass) create_table add_methods @klass.class_eval(&block) if block_given? end @@ -36,9 +39,13 @@ def add_methods class << @klass def with_columns connection.change_table(table_name) { |table| yield(table) } + end + + def table_exists? + true end end end end \ No newline at end of file