modelizer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +4 -0
- data/Manifest.txt +2 -1
- data/README.rdoc +11 -5
- data/Rakefile +1 -1
- data/lib/modelizer/assertions.rb +13 -0
- data/rails/init.rb +1 -0
- data/test/modelizer/assertions_test.rb +38 -0
- data/test/modelizer_test.rb +1 -1
- metadata +5 -3
- data/test/helper.rb +0 -2
data/CHANGELOG.rdoc
CHANGED
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
= Modelizer
|
2
2
|
|
3
|
-
Need a simple, consistent way to create model instances
|
4
|
-
tests? Use the Modelizer.
|
3
|
+
Need a simple, consistent way to create model instances and check
|
4
|
+
validations in your Rails tests? Use the Modelizer.
|
5
5
|
|
6
6
|
== Examples
|
7
7
|
|
@@ -35,16 +35,22 @@ This declaration generates a bunch of instance methods for you:
|
|
35
35
|
|
36
36
|
It also generates a test to make sure your model template is valid.
|
37
37
|
|
38
|
-
===
|
38
|
+
=== Custom Assertions
|
39
|
+
|
40
|
+
Modelizer adds one additional assertion, <tt>assert_invalid</tt>.
|
41
|
+
|
42
|
+
assert_invalid(:email, model, /is bad/)
|
39
43
|
|
40
|
-
|
44
|
+
The third argument is optional.
|
45
|
+
|
46
|
+
=== Using in Tests
|
41
47
|
|
42
48
|
class UserTest < ActiveSupport::TestCase
|
43
49
|
model_template_for User, :name => "Bob"
|
44
50
|
|
45
51
|
def test_pointless_stuff
|
46
52
|
assert new_user.valid?
|
47
|
-
|
53
|
+
assert_invalid :name, new_user_without(:name)
|
48
54
|
|
49
55
|
assert !create_user.new_record?
|
50
56
|
|
data/Rakefile
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
module Modelizer
|
2
|
+
module Assertions
|
3
|
+
def assert_invalid attribute, model, match = nil
|
4
|
+
assert !model.valid?, "#{model.class.name} should be valid, but isn't."
|
5
|
+
|
6
|
+
assert !model.errors.on(attribute).blank?,
|
7
|
+
"No error on #{attribute}, but: " +
|
8
|
+
model.errors.full_messages.to_sentence
|
9
|
+
|
10
|
+
assert_match match, model.errors.on(attribute) if match
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/rails/init.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "minitest/unit"
|
2
|
+
require "activesupport"
|
3
|
+
require "modelizer/assertions"
|
4
|
+
|
5
|
+
module Modelizer
|
6
|
+
class AssertionsTest < MiniTest::Unit::TestCase
|
7
|
+
include Modelizer::Assertions
|
8
|
+
|
9
|
+
class MockModel
|
10
|
+
attr_reader :errors
|
11
|
+
|
12
|
+
def initialize valid, errors = {}
|
13
|
+
def errors.on attribute; self[attribute] end
|
14
|
+
def errors.full_messages; values end
|
15
|
+
|
16
|
+
@valid = valid
|
17
|
+
@errors = errors
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid?; @valid end
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_assert_invalid
|
24
|
+
model = MockModel.new false, :thing => "is invalid"
|
25
|
+
assert_invalid :thing, model
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_assert_invalid_fails_fast_for_valid_models
|
29
|
+
model = MockModel.new false
|
30
|
+
assert_raises(MiniTest::Assertion) { assert_invalid :ignored, model }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_assert_invalid_looks_for_errors_on_attribute
|
34
|
+
model = MockModel.new false, :other => "is broken"
|
35
|
+
assert_raises(MiniTest::Assertion) { assert_invalid :attribute, model }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/test/modelizer_test.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.1.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-
|
12
|
+
date: 2009-03-04 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,8 +38,9 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- lib/modelizer.rb
|
41
|
+
- lib/modelizer/assertions.rb
|
41
42
|
- rails/init.rb
|
42
|
-
- test/
|
43
|
+
- test/modelizer/assertions_test.rb
|
43
44
|
- test/modelizer_test.rb
|
44
45
|
has_rdoc: true
|
45
46
|
homepage: http://github.com/jbarnette/modelizer
|
@@ -69,4 +70,5 @@ signing_key:
|
|
69
70
|
specification_version: 2
|
70
71
|
summary: ""
|
71
72
|
test_files:
|
73
|
+
- test/modelizer/assertions_test.rb
|
72
74
|
- test/modelizer_test.rb
|
data/test/helper.rb
DELETED