ohm-contrib 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.0.13
@@ -0,0 +1,11 @@
1
+ module Ohm
2
+ module ExtraValidations
3
+ include NumberValidations
4
+ include WebValidations
5
+
6
+ protected
7
+ def assert_member(att, set, error = [att, :not_member])
8
+ assert set.include?(send(att)), error
9
+ end
10
+ end
11
+ end
data/lib/ohm/contrib.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ohm
2
2
  module Contrib
3
- VERSION = '0.0.12'
3
+ VERSION = '0.0.13'
4
4
  end
5
5
 
6
6
  autoload :Boundaries, "ohm/contrib/boundaries"
@@ -8,6 +8,7 @@ module Ohm
8
8
  autoload :ToHash, "ohm/contrib/to_hash"
9
9
  autoload :WebValidations, "ohm/contrib/web_validations"
10
10
  autoload :NumberValidations, "ohm/contrib/number_validations"
11
+ autoload :ExtraValidations, "ohm/contrib/extra_validations"
11
12
  autoload :Typecast, "ohm/contrib/typecast"
12
13
  autoload :Locking, "ohm/contrib/locking"
13
14
  end
data/ohm-contrib.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ohm-contrib}
8
- s.version = "0.0.12"
8
+ s.version = "0.0.13"
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"]
12
- s.date = %q{2010-05-19}
12
+ s.date = %q{2010-05-21}
13
13
  s.description = %q{Highly decoupled drop-in functionality for Ohm models}
14
14
  s.email = %q{cyx.ucron@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "lib/ohm/contrib.rb",
27
27
  "lib/ohm/contrib/boundaries.rb",
28
+ "lib/ohm/contrib/extra_validations.rb",
28
29
  "lib/ohm/contrib/locking.rb",
29
30
  "lib/ohm/contrib/number_validations.rb",
30
31
  "lib/ohm/contrib/timestamping.rb",
@@ -35,6 +36,7 @@ Gem::Specification.new do |s|
35
36
  "test/helper.rb",
36
37
  "test/test_ohm_boundaries.rb",
37
38
  "test/test_ohm_contrib.rb",
39
+ "test/test_ohm_extra_validations.rb",
38
40
  "test/test_ohm_number_validations.rb",
39
41
  "test/test_ohm_timestamping.rb",
40
42
  "test/test_ohm_to_hash.rb",
@@ -50,6 +52,7 @@ Gem::Specification.new do |s|
50
52
  "test/helper.rb",
51
53
  "test/test_ohm_boundaries.rb",
52
54
  "test/test_ohm_contrib.rb",
55
+ "test/test_ohm_extra_validations.rb",
53
56
  "test/test_ohm_number_validations.rb",
54
57
  "test/test_ohm_timestamping.rb",
55
58
  "test/test_ohm_to_hash.rb",
@@ -42,4 +42,10 @@ class TestOhmContrib < Test::Unit::TestCase
42
42
  Ohm::Locking
43
43
  end
44
44
  end
45
+
46
+ test "autoloading of ExtraValidations" do
47
+ assert_nothing_raised NameError, LoadError do
48
+ Ohm::ExtraValidations
49
+ end
50
+ end
45
51
  end
@@ -0,0 +1,32 @@
1
+ require "helper"
2
+
3
+ class OhmExtraValidationsTest < Test::Unit::TestCase
4
+ context "membership assertion" do
5
+ class Order < Ohm::Model
6
+ include Ohm::ExtraValidations
7
+
8
+ attribute :state
9
+
10
+ def validate
11
+ assert_member :state, %w(pending authorized declined)
12
+ end
13
+ end
14
+
15
+ should "be successful given all the members" do
16
+ order = Order.new(:state => 'pending')
17
+ assert order.valid?
18
+
19
+ order = Order.new(:state => 'authorized')
20
+ assert order.valid?
21
+
22
+ order = Order.new(:state => 'declined')
23
+ assert order.valid?
24
+ end
25
+
26
+ should "fail on a non-member" do
27
+ order = Order.new(:state => 'foobar')
28
+ assert ! order.valid?
29
+ assert_equal [[:state, :not_member]], order.errors
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 12
9
- version: 0.0.12
8
+ - 13
9
+ version: 0.0.13
10
10
  platform: ruby
11
11
  authors:
12
12
  - Cyril David
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-19 00:00:00 +08:00
17
+ date: 2010-05-21 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -95,6 +95,7 @@ files:
95
95
  - VERSION
96
96
  - lib/ohm/contrib.rb
97
97
  - lib/ohm/contrib/boundaries.rb
98
+ - lib/ohm/contrib/extra_validations.rb
98
99
  - lib/ohm/contrib/locking.rb
99
100
  - lib/ohm/contrib/number_validations.rb
100
101
  - lib/ohm/contrib/timestamping.rb
@@ -105,6 +106,7 @@ files:
105
106
  - test/helper.rb
106
107
  - test/test_ohm_boundaries.rb
107
108
  - test/test_ohm_contrib.rb
109
+ - test/test_ohm_extra_validations.rb
108
110
  - test/test_ohm_number_validations.rb
109
111
  - test/test_ohm_timestamping.rb
110
112
  - test/test_ohm_to_hash.rb
@@ -144,6 +146,7 @@ test_files:
144
146
  - test/helper.rb
145
147
  - test/test_ohm_boundaries.rb
146
148
  - test/test_ohm_contrib.rb
149
+ - test/test_ohm_extra_validations.rb
147
150
  - test/test_ohm_number_validations.rb
148
151
  - test/test_ohm_timestamping.rb
149
152
  - test/test_ohm_to_hash.rb