Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix failing test introduced in 21a8743

  • Loading branch information...
commit 9f6b4b8f40e933eba2697fa749b7a6b2eea15fff 1 parent d80e17a
Michael Guterl authored
Showing with 15 additions and 1 deletion.
  1. +5 −1 lib/serialized_attributes/types.rb
  2. +10 −0 test/types_test.rb
6 lib/serialized_attributes/types.rb
View
@@ -27,7 +27,11 @@ def parse(input) input.blank? ? nil : input.to_f end
class Boolean < AttributeType
attr_reader :default
- def parse(input) input && input.respond_to?(:to_i) ? (input.to_i > 0) : input end
+ def parse(input)
+ return nil if input == ""
+ input && input.respond_to?(:to_i) ? (input.to_i > 0) : input
+ end
+
def encode(input)
return nil if input.nil? || input == ""
return 1 if input == 'true'
10 test/types_test.rb
View
@@ -29,4 +29,14 @@ class SerializedAttributesTypesTest < ActiveSupport::TestCase
assert_equal 1, type.encode(true)
end
+ test "boolean type parses properly" do
+ type = SerializedAttributes::Boolean.new
+
+ assert_equal false, type.parse(0)
+ assert_equal true, type.parse(1)
+ assert_equal false, type.parse("0")
+ assert_equal true, type.parse("1")
+ assert_equal nil, type.parse("")
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.