input_sanitizer 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,14 @@
1
1
  module InputSanitizer
2
+ module AllowNil
3
+ def call(value)
4
+ if value.nil? || value == ""
5
+ nil
6
+ else
7
+ super(value)
8
+ end
9
+ end
10
+ end
11
+
2
12
  class PositiveIntegerConverter < IntegerConverter
3
13
  def call(value)
4
14
  val = super
@@ -45,6 +45,11 @@ class InputSanitizer::Sanitizer
45
45
  :date => InputSanitizer::DateConverter.new,
46
46
  :time => InputSanitizer::TimeConverter.new,
47
47
  :boolean => InputSanitizer::BooleanConverter.new,
48
+ :integer_or_blank => InputSanitizer::IntegerConverter.new.extend(InputSanitizer::AllowNil),
49
+ :string_or_blank => InputSanitizer::StringConverter.new.extend(InputSanitizer::AllowNil),
50
+ :date_or_blank => InputSanitizer::DateConverter.new.extend(InputSanitizer::AllowNil),
51
+ :time_or_blank => InputSanitizer::TimeConverter.new.extend(InputSanitizer::AllowNil),
52
+ :boolean_or_blank => InputSanitizer::BooleanConverter.new.extend(InputSanitizer::AllowNil),
48
53
  }
49
54
  end
50
55
 
@@ -1,3 +1,3 @@
1
1
  module InputSanitizer
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -1,6 +1,25 @@
1
1
  require 'spec_helper'
2
2
  require 'input_sanitizer/extended_converters'
3
3
 
4
+ describe InputSanitizer::AllowNil do
5
+ it "passes blanks" do
6
+ lambda { |_| 1 }.extend(InputSanitizer::AllowNil).call("").should be_nil
7
+ end
8
+
9
+ it "passes things the extended sanitizer passes" do
10
+ lambda { |_| :something }.extend(InputSanitizer::AllowNil).call(:stuff).
11
+ should eq(:something)
12
+ end
13
+
14
+ it "raises error if the extended sanitizer raises error" do
15
+ action = lambda do
16
+ lambda { |_| raise "Some error" }.extend(InputSanitizer::AllowNil).call(:stuff)
17
+ end
18
+
19
+ action.should raise_error
20
+ end
21
+ end
22
+
4
23
  describe InputSanitizer::PositiveIntegerConverter do
5
24
  let(:converter) { InputSanitizer::PositiveIntegerConverter.new }
6
25
 
@@ -122,7 +122,7 @@ describe InputSanitizer::Sanitizer do
122
122
  it "raises an error when converter is not defined" do
123
123
  expect do
124
124
  BrokenCustomSanitizer.custom(:x)
125
- end.should raise_error
125
+ end.to raise_error
126
126
  end
127
127
  end
128
128
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: input_sanitizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-09 00:00:00.000000000 Z
14
+ date: 2013-05-13 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 1.8.24
96
+ rubygems_version: 1.8.23
97
97
  signing_key:
98
98
  specification_version: 3
99
99
  summary: Gem to sanitize hash of incoming data