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

- old
+ new

@@ -1,11 +1,23 @@ +require "activesupport" + +require "modelizer/assertions" +require "modelizer/validations" + module Modelizer + + # Duh. + VERSION = "1.3.0" + + include Modelizer::Assertions + @@cache = {} def self.cache; @@cache end def self.included target target.extend ClassMethods + target.extend Modelizer::Validations end def assign_model_template_attributes model, attributes model.send :attributes=, attributes, false model @@ -24,11 +36,11 @@ end module ClassMethods def model_template_for klass, defaults = {}, &block if defaults.empty? && !block - raise "default attributes or lazy block required" + raise ArgumentError, "default attributes or lazy block required" end ::Modelizer.cache[klass] = [defaults, block] klass = klass.name @@ -76,18 +88,18 @@ # concrete test, just generate a method. file, line = caller.first.split ":" line = line.to_i - test =<<-END + test = <<-END def test_model_template_for_#{model} assert (m = new_#{model}).valid?, "#{klass} template is invalid: " + m.errors.full_messages.to_sentence end END - if self == Test::Unit::TestCase + if [Test::Unit::TestCase, ActiveSupport::TestCase].include? self eval <<-END, nil, file, line - 2 class ::ModelTemplateFor#{klass}Test < ActiveSupport::TestCase #{test} end END