Permalink
Browse files

Remove ActiveSupport assumption, tweak for Rails 3.

  • Loading branch information...
1 parent 8275bb2 commit 4dc14c985fa3fda53ad7c9284be1e804ed557495 @jbarnette committed Jul 15, 2010
Showing with 15 additions and 7 deletions.
  1. +10 −4 lib/modelizer.rb
  2. +4 −2 lib/modelizer/assertions.rb
  3. +1 −1 lib/modelizer/validations.rb
View
@@ -1,12 +1,10 @@
-require "active_support"
-
require "modelizer/assertions"
require "modelizer/validations"
module Modelizer
# Duh.
- VERSION = "1.3.2"
+ VERSION = "2.0.0"
include Modelizer::Assertions
@@ -18,6 +16,14 @@ def self.included target
target.extend Modelizer::Validations
end
+ def self.underscore classname
+ classname.gsub(/::/, '_').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ end
+
def assign_model_template_attributes model, attributes
model.send :attributes=, attributes, false
model
@@ -44,7 +50,7 @@ def model_template_for klass, defaults = {}, &block
::Modelizer.cache[klass] = [defaults, block]
klass = klass.name
- model = klass.underscore.tr "/", "_"
+ model = ::Modelizer.underscore klass
module_eval <<-END, __FILE__, __LINE__ + 1
def valid_#{model}_attributes extras = {}
@@ -4,9 +4,11 @@ def assert_invalid attribute, model, match = nil
assert !model.valid?,
"#{model.class.name} should have invalid #{attribute}, but it's valid."
- assert !model.errors.on(attribute).blank?,
+ errors = model.errors[attribute]
+
+ assert !errors.nil? && !errors.empty?,
"No error on #{attribute}, but: " +
- model.errors.full_messages.to_sentence
+ model.errors.full_messages.join(", ")
assert_match match, model.errors.on(attribute) if match
end
@@ -2,7 +2,7 @@ module Modelizer
module Validations
def test_validations_for attribute, *validations
@klass ||= name.gsub(/Test$/, "").constantize
- @model ||= @klass.name.underscore.tr("/", "_")
+ @model ||= ::Modelizer.underscore @klass.name
unless instance_methods.collect { |m| m.to_s }.include? "new_#{@model}"
raise "no model template for #{@klass.name}"

0 comments on commit 4dc14c9

Please sign in to comment.