validate 1.3 → 1.3.1

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/README.md CHANGED
@@ -43,6 +43,7 @@ module Store
43
43
 
44
44
  # simple ActiveRecord style validation
45
45
  validates_presence_of :name
46
+ validates_booleanness_of :safely
46
47
 
47
48
  # multiple keys can be included in one validation
48
49
  validates_type_of :description, :long_description, is: String
@@ -61,6 +61,15 @@ module Validate
61
61
  obj[field].is_a?(Numeric)
62
62
  end
63
63
 
64
+ # Validates that a field's value is a boolean.
65
+ #
66
+ # validates_booleanness_of :field
67
+ #
68
+ fails_because_key 'was not a boolean value.'
69
+ def validates_booleanness_of(obj, field, opts, validator)
70
+ [true, false].include?(obj[field])
71
+ end
72
+
64
73
  # Validates the value, ensure equality.
65
74
  #
66
75
  # validates_value_of :field, is: 'something'
@@ -1,4 +1,3 @@
1
-
2
1
  module Validate
3
- VERSION = '1.3'
2
+ VERSION = '1.3.1'
4
3
  end
@@ -307,6 +307,27 @@ describe Validate do
307
307
  end
308
308
  end
309
309
 
310
+ context 'validates_booleanness_of' do
311
+
312
+ before do
313
+ class TestClass < BaseTestClass
314
+ validations do
315
+ validates_booleanness_of :field
316
+ end
317
+ end
318
+ end
319
+
320
+ it 'validates' do
321
+ test = TestClass.new(field: true)
322
+ test.validates?.should == true
323
+ end
324
+
325
+ it 'fails' do
326
+ test = TestClass.new(field: 'true')
327
+ test.validates?.should == false
328
+ end
329
+ end
330
+
310
331
  context 'validates_value_of' do
311
332
 
312
333
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validate
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.3'
4
+ version: 1.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec