modelizer 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.autotest ADDED
@@ -0,0 +1,5 @@
1
+ require "autotest/restart"
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.testlib = "minitest/autorun"
5
+ end
data/CHANGELOG.rdoc CHANGED
@@ -1,15 +1,21 @@
1
- === 1.2.0 (2009-03-17)
1
+ === 1.3.0 / 2009-07-10
2
+
3
+ * Switch to modern Hoe.
4
+ * Support default values when testing presence validations.
5
+ * Require explicit 'include Modelizer', don't be fancy with Rails init.
6
+
7
+ === 1.2.0 / 2009-03-17
2
8
 
3
9
  * Added a simple stab at some validation tests.
4
10
 
5
- === 1.1.1 (2009-03-16)
11
+ === 1.1.1 / 2009-03-16
6
12
 
7
13
  * Fixed <tt>assert_invalid</tt>'s misleading message.
8
14
 
9
- === 1.1.0 (2009-03-04)
15
+ === 1.1.0 / 2009-03-04
10
16
 
11
17
  * Added <tt>assert_invalid</tt>.
12
18
 
13
- === 1.0.0 (2009-02-24)
19
+ === 1.0.0 / 2009-02-24
14
20
 
15
21
  * Birthday!
data/Manifest.txt CHANGED
@@ -1,3 +1,4 @@
1
+ .autotest
1
2
  CHANGELOG.rdoc
2
3
  Manifest.txt
3
4
  README.rdoc
@@ -5,6 +6,5 @@ Rakefile
5
6
  lib/modelizer.rb
6
7
  lib/modelizer/assertions.rb
7
8
  lib/modelizer/validations.rb
8
- rails/init.rb
9
- test/modelizer/assertions_test.rb
10
- test/modelizer_test.rb
9
+ test/test_assertions.rb
10
+ test/test_modelizer.rb
data/README.rdoc CHANGED
@@ -1,14 +1,24 @@
1
1
  = Modelizer
2
2
 
3
+ * http://github.com/jbarnette/modelizer
4
+
5
+ == Description
6
+
3
7
  Need a simple, consistent way to create model instances and check
4
8
  validations in your Rails tests? Use the Modelizer.
5
9
 
6
10
  == Examples
7
11
 
8
- First, define a model template. I generally do this in the unit test
12
+ First, enable the Modelizer. I do it in <tt>test/test_helper.rb</tt>:
13
+
14
+ class ActiveSupport::TestCase
15
+ include Modelizer
16
+ end
17
+
18
+ Next, define a model template. I generally do this in the unit test
9
19
  for the model until I need to use the template somewhere else. As soon
10
20
  as it's used in multiple places, I move it to a reopened
11
- <tt>Test::Unit::TestCase</tt> in <tt>test/test_helper.rb</tt>.
21
+ <tt>ActiveSupport::TestCase</tt> in <tt>test/test_helper.rb</tt>.
12
22
 
13
23
  class UserTest < ActiveSupport::TestCase
14
24
 
@@ -24,14 +34,14 @@ as it's used in multiple places, I move it to a reopened
24
34
 
25
35
  This declaration generates a bunch of instance methods for you:
26
36
 
27
- * def valid_user_attributes(extras = {})
28
- * def valid_user_attributes_without(*excluded)
29
- * def new_user(extras = {})
30
- * def new_user_without(*excluded)
31
- * def create_user(extras = {})
32
- * def create_user!(extras = {})
33
- * def create_user_without(*excluded)
34
- * def create_user_without!(*excluded)
37
+ * <tt>def valid_user_attributes(extras = {})</tt>
38
+ * <tt>def valid_user_attributes_without(*excluded)</tt>
39
+ * <tt>def new_user(extras = {})</tt>
40
+ * <tt>def new_user_without(*excluded)</tt>
41
+ * <tt>def create_user(extras = {})</tt>
42
+ * <tt>def create_user!(extras = {})</tt>
43
+ * <tt>def create_user_without(*excluded)</tt>
44
+ * <tt>def create_user_without!(*excluded)</tt>
35
45
 
36
46
  It also generates a test to make sure your model template is valid.
37
47
 
@@ -39,7 +49,7 @@ It also generates a test to make sure your model template is valid.
39
49
 
40
50
  Modelizer adds one additional assertion, <tt>assert_invalid</tt>.
41
51
 
42
- assert_invalid(:email, model, /is bad/)
52
+ assert_invalid :email, model, /is bad/
43
53
 
44
54
  The third argument is optional.
45
55
 
data/Rakefile CHANGED
@@ -1,14 +1,13 @@
1
1
  require "rubygems"
2
2
  require "hoe"
3
3
 
4
- Hoe.new "modelizer", "1.2.0" do |p|
5
- p.developer "John Barnette", "jbarnette@rubyforge.org"
4
+ Hoe.plugin :doofus, :git
6
5
 
7
- p.url = "http://github.com/jbarnette/modelizer"
8
- p.history_file = "CHANGELOG.rdoc"
9
- p.readme_file = "README.rdoc"
10
- p.extra_rdoc_files = [p.readme_file]
11
- p.need_tar = false
12
- p.test_globs = %w(test/**/*_test.rb)
13
- p.testlib = :minitest
6
+ Hoe.spec "modelizer" do
7
+ developer "John Barnette", "jbarnette@rubyforge.org"
8
+
9
+ self.extra_rdoc_files = FileList["*.rdoc"]
10
+ self.history_file = "CHANGELOG.rdoc"
11
+ self.readme_file = "README.rdoc"
12
+ self.testlib = :minitest
14
13
  end
data/lib/modelizer.rb CHANGED
@@ -1,9 +1,21 @@
1
+ require "activesupport"
2
+
3
+ require "modelizer/assertions"
4
+ require "modelizer/validations"
5
+
1
6
  module Modelizer
7
+
8
+ # Duh.
9
+ VERSION = "1.3.0"
10
+
11
+ include Modelizer::Assertions
12
+
2
13
  @@cache = {}
3
14
  def self.cache; @@cache end
4
15
 
5
16
  def self.included target
6
17
  target.extend ClassMethods
18
+ target.extend Modelizer::Validations
7
19
  end
8
20
 
9
21
  def assign_model_template_attributes model, attributes
@@ -26,7 +38,7 @@ module Modelizer
26
38
  module ClassMethods
27
39
  def model_template_for klass, defaults = {}, &block
28
40
  if defaults.empty? && !block
29
- raise "default attributes or lazy block required"
41
+ raise ArgumentError, "default attributes or lazy block required"
30
42
  end
31
43
 
32
44
  ::Modelizer.cache[klass] = [defaults, block]
@@ -78,7 +90,7 @@ module Modelizer
78
90
  file, line = caller.first.split ":"
79
91
  line = line.to_i
80
92
 
81
- test =<<-END
93
+ test = <<-END
82
94
  def test_model_template_for_#{model}
83
95
  assert (m = new_#{model}).valid?,
84
96
  "#{klass} template is invalid: " +
@@ -86,7 +98,7 @@ module Modelizer
86
98
  end
87
99
  END
88
100
 
89
- if self == Test::Unit::TestCase
101
+ if [Test::Unit::TestCase, ActiveSupport::TestCase].include? self
90
102
  eval <<-END, nil, file, line - 2
91
103
  class ::ModelTemplateFor#{klass}Test < ActiveSupport::TestCase
92
104
  #{test}
@@ -8,6 +8,8 @@ module Modelizer
8
8
  raise "no model template for #{@klass.name}"
9
9
  end
10
10
 
11
+ # FIX: location in original test file
12
+
11
13
  validations.each do |v|
12
14
  test = send "validation_lambda_for_#{v}", @klass, @model, attribute
13
15
  define_method "test_#{attribute}_#{v}", &test
@@ -18,7 +20,7 @@ module Modelizer
18
20
 
19
21
  def validation_lambda_for_presence klass, model, attribute
20
22
  lambda do
21
- assert_invalid attribute, send("new_#{model}_without", attribute)
23
+ assert_invalid attribute, send("new_#{model}", attribute => nil)
22
24
  end
23
25
  end
24
26
 
@@ -1,9 +1,8 @@
1
- require "minitest/unit"
2
- require "activesupport"
1
+ require "minitest/autorun"
3
2
  require "modelizer/assertions"
4
3
 
5
4
  module Modelizer
6
- class AssertionsTest < MiniTest::Unit::TestCase
5
+ class TestAssertions < MiniTest::Unit::TestCase
7
6
  include Modelizer::Assertions
8
7
 
9
8
  class MockModel
@@ -1,8 +1,7 @@
1
- require "minitest/unit"
2
- require "activesupport"
1
+ require "minitest/autorun"
3
2
  require "modelizer"
4
3
 
5
- class ModelizerTest < MiniTest::Unit::TestCase
4
+ class TestModelizer < MiniTest::Unit::TestCase
6
5
  def setup
7
6
  @klass = Class.new
8
7
  @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.2.0
4
+ version: 1.3.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-17 00:00:00 -07:00
12
+ date: 2009-07-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,9 +20,11 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.11.0
23
+ version: 2.3.2
24
24
  version:
25
- description: ""
25
+ description: |-
26
+ Need a simple, consistent way to create model instances and check
27
+ validations in your Rails tests? Use the Modelizer.
26
28
  email:
27
29
  - jbarnette@rubyforge.org
28
30
  executables: []
@@ -31,8 +33,10 @@ extensions: []
31
33
 
32
34
  extra_rdoc_files:
33
35
  - Manifest.txt
36
+ - CHANGELOG.rdoc
34
37
  - README.rdoc
35
38
  files:
39
+ - .autotest
36
40
  - CHANGELOG.rdoc
37
41
  - Manifest.txt
38
42
  - README.rdoc
@@ -40,11 +44,12 @@ files:
40
44
  - lib/modelizer.rb
41
45
  - lib/modelizer/assertions.rb
42
46
  - lib/modelizer/validations.rb
43
- - rails/init.rb
44
- - test/modelizer/assertions_test.rb
45
- - test/modelizer_test.rb
47
+ - test/test_assertions.rb
48
+ - test/test_modelizer.rb
46
49
  has_rdoc: true
47
50
  homepage: http://github.com/jbarnette/modelizer
51
+ licenses: []
52
+
48
53
  post_install_message:
49
54
  rdoc_options:
50
55
  - --main
@@ -66,10 +71,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
71
  requirements: []
67
72
 
68
73
  rubyforge_project: modelizer
69
- rubygems_version: 1.3.1
74
+ rubygems_version: 1.3.4
70
75
  signing_key:
71
- specification_version: 2
72
- summary: ""
76
+ specification_version: 3
77
+ summary: Need a simple, consistent way to create model instances and check validations in your Rails tests? Use the Modelizer.
73
78
  test_files:
74
- - test/modelizer/assertions_test.rb
75
- - test/modelizer_test.rb
79
+ - test/test_assertions.rb
80
+ - test/test_modelizer.rb
data/rails/init.rb DELETED
@@ -1,5 +0,0 @@
1
- class ::Test::Unit::TestCase
2
- include Modelizer
3
- include Modelizer::Assertions
4
- extend Modelizer::Validations
5
- end