spec/sanitizer_spec.rb in input_sanitizer-0.2.0 vs spec/sanitizer_spec.rb in input_sanitizer-0.2.2

- old
+ new

@@ -12,10 +12,13 @@ integer :num date :birthday time :updated_at custom :cust1, :cust2, :converter => lambda { |v| v.reverse } nested :stuff, :sanitizer => NestedSanitizer, :collection => true, :namespace => :nested + custom :custom3, :provide => :num, :converter => lambda { |v, num| + num == 1 ? v.reverse : v + } end class BrokenCustomSanitizer < InputSanitizer::Sanitizer end @@ -130,11 +133,11 @@ sanitizer = ExtendedSanitizer.new({:num => "23", :is_nice => 'false'}) cleaned = sanitizer.cleaned cleaned.should have_key(:num) cleaned[:num].should == 23 - cleaned[:is_nice].should be_false + cleaned[:is_nice].should eq(false) end it "overrides inherited fields" do sanitizer = OverridingSanitizer.new({:is_nice => "42"}) cleaned = sanitizer.cleaned @@ -181,12 +184,20 @@ cleaned.should have_key(:cust1) cleaned[:cust1].should == "magic" end it "raises an error when converter is not defined" do - expect do + lambda do BrokenCustomSanitizer.custom(:x) - end.to raise_error + end.should raise_error + end + + it "provides the converter with requested value" do + @params = { :custom3 => 'three', :num => 1 } + cleaned.should have_key(:custom3) + cleaned.should have_key(:num) + cleaned[:custom3].should eq('eerht') + cleaned[:num].should eq(1) end end describe ".nested" do let(:sanitizer) { BasicSanitizer.new(@params) }