Skip to content

Loading…

Make sure nil values get cast as nil #16

Merged
merged 1 commit into from

2 participants

@rykov

Before this patch, different types came out with different behaviors. In some instances, it would throw a MethodMissing, in others, it would return a blank string instead of nil.

This patch makes sure that nil is nil.

@kreynolds kreynolds merged commit f0a018b into kreynolds:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 19, 2011
  1. @rykov
Showing with 9 additions and 0 deletions.
  1. +2 −0 lib/cassandra-cql/schema.rb
  2. +7 −0 spec/column_family_spec.rb
View
2 lib/cassandra-cql/schema.rb
@@ -60,6 +60,8 @@ def columns
end
def self.cast(value, type)
+ return nil if value.nil?
+
case type
when "org.apache.cassandra.db.marshal.TimeUUIDType"
UUID.to_time(value)
View
7 spec/column_family_spec.rb
@@ -87,6 +87,13 @@
obj = Object.new
ColumnFamily.cast(obj, "org.apache.cassandra.db.marshal.BytesType").object_id.should eq(obj.object_id)
end
+
+ it "should return nil for all types of nil" do
+ %w(TimeUUIDType UUIDType LongType IntegerType
+ UTF8Type AsciiType CounterColumnType).each do |type|
+ ColumnFamily.cast(nil, "org.apache.cassandra.db.marshal.#{type}").should eq(nil)
+ end
+ end
end
context "validations classes" do
Something went wrong with that request. Please try again.