modelizer 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/lib/modelizer/validations.rb +35 -0
- data/rails/init.rb +1 -0
- metadata +3 -2
data/CHANGELOG.rdoc
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Modelizer
|
2
|
+
module Validations
|
3
|
+
def test_validations_for attribute, *validations
|
4
|
+
@klass ||= name.gsub(/Test$/, "").constantize
|
5
|
+
@model ||= @klass.name.underscore.tr("/", "_")
|
6
|
+
|
7
|
+
unless instance_methods.collect { |m| m.to_s }.include? "new_#{@model}"
|
8
|
+
raise "no model template for #{@klass.name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
validations.each do |v|
|
12
|
+
test = send "validation_lambda_for_#{v}", @klass, @model, attribute
|
13
|
+
define_method "test_#{attribute}_#{v}", &test
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def validation_lambda_for_presence klass, model, attribute
|
20
|
+
lambda do
|
21
|
+
assert_invalid attribute, send("new_#{model}_without", attribute)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def validation_lambda_for_uniqueness klass, model, attribute
|
26
|
+
lambda do
|
27
|
+
existing = klass.first
|
28
|
+
assert_not_nil existing, "There's at least one #{model} fixture."
|
29
|
+
|
30
|
+
assert_invalid attribute,
|
31
|
+
send("new_#{model}", attribute => existing.send(attribute))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/rails/init.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modelizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Barnette
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- lib/modelizer.rb
|
41
41
|
- lib/modelizer/assertions.rb
|
42
|
+
- lib/modelizer/validations.rb
|
42
43
|
- rails/init.rb
|
43
44
|
- test/modelizer/assertions_test.rb
|
44
45
|
- test/modelizer_test.rb
|