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 CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.1.0 (2009-03-04)
2
+
3
+ * Added <tt>assert_invalid</tt>.
4
+
1
5
  === 1.0.0 (2009-02-24)
2
6
 
3
7
  * Birthday!
data/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile
5
5
  lib/modelizer.rb
6
+ lib/modelizer/assertions.rb
6
7
  rails/init.rb
7
- test/helper.rb
8
+ test/modelizer/assertions_test.rb
8
9
  test/modelizer_test.rb
data/README.rdoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = Modelizer
2
2
 
3
- Need a simple, consistent way to create model instances in your Rails
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
- === Using in Tests
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
- These methods are just simple helpers for model creation:
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
- assert !new_user_without(:name).valid?
53
+ assert_invalid :name, new_user_without(:name)
48
54
 
49
55
  assert !create_user.new_record?
50
56
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "rubygems"
2
2
  require "hoe"
3
3
 
4
- Hoe.new "modelizer", "1.0.0" do |p|
4
+ Hoe.new "modelizer", "1.1.0" do |p|
5
5
  p.developer "John Barnette", "jbarnette@rubyforge.org"
6
6
 
7
7
  p.url = "http://github.com/jbarnette/modelizer"
@@ -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
@@ -1,3 +1,4 @@
1
1
  class ::Test::Unit::TestCase
2
2
  include Modelizer
3
+ include Modelizer::Assertions
3
4
  end
@@ -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
@@ -2,7 +2,7 @@ require "minitest/unit"
2
2
  require "activesupport"
3
3
  require "modelizer"
4
4
 
5
- class TestModelizer < MiniTest::Unit::TestCase
5
+ class ModelizerTest < MiniTest::Unit::TestCase
6
6
  def setup
7
7
  @klass = Class.new
8
8
  @klass.send :include, Modelizer
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.0.0
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-02-26 00:00:00 -08:00
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/helper.rb
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
@@ -1,2 +0,0 @@
1
- require "minitest/autorun"
2
- require "modelizer"