ohm-contrib 0.0.6 → 0.0.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.6
1
+ 0.0.7
@@ -1,6 +1,6 @@
1
1
  module Ohm
2
2
  module Contrib
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
 
6
6
  autoload :Boundaries, "ohm/contrib/boundaries"
@@ -89,7 +89,25 @@ module Ohm
89
89
  end
90
90
 
91
91
  module Typecast
92
- MissingValidation = Class.new(StandardError)
92
+ class MissingValidation < StandardError
93
+ MESSAGE = "%s :%s is required in your #validate method"
94
+
95
+ attr :type
96
+ attr :field
97
+
98
+ def initialize(type, field)
99
+ @type, @field = type, field
100
+ end
101
+
102
+ def message
103
+ MESSAGE % [assertion, field]
104
+ end
105
+
106
+ protected
107
+ def assertion
108
+ 'assert_type_%s' % type.name.split('::').last.downcase
109
+ end
110
+ end
93
111
 
94
112
  include Types
95
113
  include TypeAssertions
@@ -128,7 +146,7 @@ module Ohm
128
146
  value = send(field)
129
147
 
130
148
  unless value.kind_of?(type)
131
- raise MissingValidation, "#{field} expected to be #{type}, but was #{value.class}"
149
+ raise MissingValidation.new(type, field)
132
150
  end
133
151
  end
134
152
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ohm-contrib}
8
- s.version = "0.0.6"
8
+ s.version = "0.0.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril David"]
@@ -26,8 +26,12 @@ class TestOhmTypecast < Test::Unit::TestCase
26
26
  should "raise a MissingValidation error during validation" do
27
27
  product = Product.new(:price => "FooBar")
28
28
 
29
- assert_raise Ohm::Typecast::MissingValidation do
29
+ begin
30
30
  product.valid?
31
+ rescue Ohm::Typecast::MissingValidation => ex
32
+ assert_match(/assert_type_decimal :price is required in your #validate method/, ex.message)
33
+ else
34
+ flunk "Should have raised MissingValidation"
31
35
  end
32
36
  end
33
37
  end
@@ -78,8 +82,12 @@ class TestOhmTypecast < Test::Unit::TestCase
78
82
  end
79
83
 
80
84
  test "an invalid string" do
81
- assert_raise Ohm::Typecast::MissingValidation do
82
- product = Product.create(:start_of_sale => "invalid time")
85
+ begin
86
+ Product.create(:start_of_sale => "invalid time")
87
+ rescue Ohm::Typecast::MissingValidation => ex
88
+ assert_match(/assert_type_time :start_of_sale is required in your #validate method/, ex.message)
89
+ else
90
+ flunk "Should have raised MissingValidation"
83
91
  end
84
92
  end
85
93
 
@@ -138,8 +146,12 @@ class TestOhmTypecast < Test::Unit::TestCase
138
146
  end
139
147
 
140
148
  test "assigning a string which is not a valid date" do
141
- assert_raise Ohm::Typecast::MissingValidation do
142
- product = Product.create(:date_bought => "Bla Bla")
149
+ begin
150
+ Product.create(:date_bought => "Bla Bla")
151
+ rescue Ohm::Typecast::MissingValidation => ex
152
+ assert_match(/assert_type_date :date_bought is required in your #validate method/, ex.message)
153
+ else
154
+ flunk "Should have raised MissingValidation"
143
155
  end
144
156
  end
145
157
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David