modelizer 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +6 -0
- data/lib/modelizer.rb +10 -7
- data/lib/modelizer/validations.rb +3 -3
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
data/lib/modelizer.rb
CHANGED
@@ -4,7 +4,7 @@ require "modelizer/validations"
|
|
4
4
|
module Modelizer
|
5
5
|
|
6
6
|
# Duh.
|
7
|
-
VERSION = "
|
7
|
+
VERSION = "3.0.0"
|
8
8
|
|
9
9
|
include Modelizer::Assertions
|
10
10
|
|
@@ -28,9 +28,13 @@ module Modelizer
|
|
28
28
|
target.extend Modelizer::Validations
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def self.method_name_for model_class
|
32
|
+
underscore model_class.name
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.model_class_for test_class
|
36
|
+
test_class.name.gsub(/Test$/, "").constantize
|
37
|
+
end
|
34
38
|
|
35
39
|
def self.underscore classname
|
36
40
|
classname.gsub(/::/, '_').
|
@@ -65,9 +69,8 @@ module Modelizer
|
|
65
69
|
|
66
70
|
::Modelizer.cache[klass] = [defaults, block]
|
67
71
|
|
68
|
-
|
69
|
-
|
70
|
-
model = ::Modelizer.underscore nsklass
|
72
|
+
model = ::Modelizer.method_name_for klass
|
73
|
+
klass = klass.name
|
71
74
|
|
72
75
|
module_eval <<-END, __FILE__, __LINE__ + 1
|
73
76
|
def valid_#{model}_attributes extras = {}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Modelizer
|
2
2
|
module Validations
|
3
3
|
def test_validations_for attribute, *validations
|
4
|
-
@klass ||=
|
5
|
-
@model ||= ::Modelizer.
|
4
|
+
@klass ||= ::Modelizer.model_class_for self
|
5
|
+
@model ||= ::Modelizer.method_name_for @klass
|
6
6
|
|
7
7
|
unless instance_methods.collect { |m| m.to_s }.include? "new_#{@model}"
|
8
8
|
raise "no model template for #{@klass.name}"
|
@@ -27,7 +27,7 @@ module Modelizer
|
|
27
27
|
def validation_lambda_for_uniqueness klass, model, attribute
|
28
28
|
lambda do
|
29
29
|
existing = klass.first
|
30
|
-
|
30
|
+
assert existing, "There's at least one #{model} fixture."
|
31
31
|
|
32
32
|
assert_invalid attribute,
|
33
33
|
send("new_#{model}", attribute => existing.send(attribute))
|