modelizer 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +2 -2
- data/Rakefile +1 -1
- data/lib/modelizer.rb +11 -5
- data/lib/modelizer/assertions.rb +4 -2
- data/lib/modelizer/validations.rb +1 -1
- metadata +35 -11
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -74,11 +74,11 @@ The third argument is optional.
|
|
74
74
|
|
75
75
|
== Installation
|
76
76
|
|
77
|
-
$
|
77
|
+
$ gem install modelizer
|
78
78
|
|
79
79
|
== License
|
80
80
|
|
81
|
-
Copyright 2009 John Barnette (jbarnette
|
81
|
+
Copyright 2009-10 John Barnette (code@jbarnette.com)
|
82
82
|
|
83
83
|
Permission is hereby granted, free of charge, to any person obtaining
|
84
84
|
a copy of this software and associated documentation files (the
|
data/Rakefile
CHANGED
data/lib/modelizer.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require "active_support"
|
2
|
-
|
3
1
|
require "modelizer/assertions"
|
4
2
|
require "modelizer/validations"
|
5
3
|
|
6
4
|
module Modelizer
|
7
5
|
|
8
6
|
# Duh.
|
9
|
-
VERSION = "
|
7
|
+
VERSION = "2.0.0"
|
10
8
|
|
11
9
|
include Modelizer::Assertions
|
12
10
|
|
@@ -18,6 +16,14 @@ module Modelizer
|
|
18
16
|
target.extend Modelizer::Validations
|
19
17
|
end
|
20
18
|
|
19
|
+
def self.underscore classname
|
20
|
+
classname.gsub(/::/, '_').
|
21
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
22
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
23
|
+
tr("-", "_").
|
24
|
+
downcase
|
25
|
+
end
|
26
|
+
|
21
27
|
def assign_model_template_attributes model, attributes
|
22
28
|
model.send :attributes=, attributes, false
|
23
29
|
model
|
@@ -37,14 +43,14 @@ module Modelizer
|
|
37
43
|
|
38
44
|
module ClassMethods
|
39
45
|
def model_template_for klass, defaults = {}, &block
|
40
|
-
if defaults.
|
46
|
+
if defaults.nil? && !block
|
41
47
|
raise ArgumentError, "default attributes or lazy block required"
|
42
48
|
end
|
43
49
|
|
44
50
|
::Modelizer.cache[klass] = [defaults, block]
|
45
51
|
|
46
52
|
klass = klass.name
|
47
|
-
model =
|
53
|
+
model = ::Modelizer.underscore klass
|
48
54
|
|
49
55
|
module_eval <<-END, __FILE__, __LINE__ + 1
|
50
56
|
def valid_#{model}_attributes extras = {}
|
data/lib/modelizer/assertions.rb
CHANGED
@@ -4,9 +4,11 @@ module Modelizer
|
|
4
4
|
assert !model.valid?,
|
5
5
|
"#{model.class.name} should have invalid #{attribute}, but it's valid."
|
6
6
|
|
7
|
-
|
7
|
+
errors = model.errors[attribute]
|
8
|
+
|
9
|
+
assert !errors.nil? && !errors.empty?,
|
8
10
|
"No error on #{attribute}, but: " +
|
9
|
-
model.errors.full_messages.
|
11
|
+
model.errors.full_messages.join(", ")
|
10
12
|
|
11
13
|
assert_match match, model.errors.on(attribute) if match
|
12
14
|
end
|
@@ -2,7 +2,7 @@ module Modelizer
|
|
2
2
|
module Validations
|
3
3
|
def test_validations_for attribute, *validations
|
4
4
|
@klass ||= name.gsub(/Test$/, "").constantize
|
5
|
-
@model ||= @klass.name
|
5
|
+
@model ||= ::Modelizer.underscore @klass.name
|
6
6
|
|
7
7
|
unless instance_methods.collect { |m| m.to_s }.include? "new_#{@model}"
|
8
8
|
raise "no model template for #{@klass.name}"
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: modelizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
|
-
-
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Barnette
|
@@ -14,27 +15,46 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
+
date: 2010-07-15 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
|
-
name:
|
22
|
+
name: rubyforge
|
23
|
+
prerelease: false
|
22
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
26
30
|
segments:
|
27
31
|
- 2
|
28
|
-
-
|
29
|
-
-
|
30
|
-
version: 2.
|
32
|
+
- 0
|
33
|
+
- 4
|
34
|
+
version: 2.0.4
|
31
35
|
type: :development
|
32
36
|
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: hoe
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 21
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
- 1
|
50
|
+
version: 2.6.1
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
33
53
|
description: |-
|
34
54
|
Need a simple, consistent way to create model instances and check
|
35
55
|
validations in your Rails tests? Use the Modelizer.
|
36
56
|
email:
|
37
|
-
- jbarnette
|
57
|
+
- code@jbarnette.com
|
38
58
|
executables: []
|
39
59
|
|
40
60
|
extensions: []
|
@@ -65,23 +85,27 @@ rdoc_options:
|
|
65
85
|
require_paths:
|
66
86
|
- lib
|
67
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
68
89
|
requirements:
|
69
90
|
- - ">="
|
70
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
71
93
|
segments:
|
72
94
|
- 0
|
73
95
|
version: "0"
|
74
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
75
98
|
requirements:
|
76
99
|
- - ">="
|
77
100
|
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
78
102
|
segments:
|
79
103
|
- 0
|
80
104
|
version: "0"
|
81
105
|
requirements: []
|
82
106
|
|
83
107
|
rubyforge_project: modelizer
|
84
|
-
rubygems_version: 1.3.
|
108
|
+
rubygems_version: 1.3.7
|
85
109
|
signing_key:
|
86
110
|
specification_version: 3
|
87
111
|
summary: Need a simple, consistent way to create model instances and check validations in your Rails tests? Use the Modelizer.
|