Permalink
Browse files

Changed Typecasting::DateTypecaster to raise on invalid Strings, fixes

  • Loading branch information...
1 parent 39d0b32 commit 501ebd8d76b4263ded942eabea2f507773965f76 @cgriego committed Jul 10, 2012
View
4 CHANGELOG.md
@@ -1,3 +1,7 @@
+# ActiveAttr 0.7.0 (Unreleased) #
+
+* Changed Typecasting::DateTypecaster to raise on invalid Strings
+
# ActiveAttr 0.6.0 (June 27, 2012) #
* Added AttributeDefinition#inspect
View
1 lib/active_attr/typecasting/date_typecaster.rb
@@ -24,6 +24,7 @@ class DateTypecaster
# @since 0.5.0
def call(value)
value.to_date if value.respond_to? :to_date
+ rescue NoMethodError
end
end
end
View
4 spec/unit/active_attr/typecasting/date_typecaster_spec.rb
@@ -14,6 +14,10 @@ module Typecasting
subject.call(nil).should equal nil
end
+ it "returns nil for an invalid String" do
+ subject.call("x").should equal nil
+ end
+
it "casts a UTC Time to a Date representing the date portion" do
subject.call(Time.utc(2012, 1, 1, 0, 0, 0)).should eql Date.new(2012, 1, 1)
end

0 comments on commit 501ebd8

Please sign in to comment.