Skip to content

Commit f4ae61b

Browse files
committed
Fix test
1 parent a181cfc commit f4ae61b

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/couchbase-orm/types/timestamp.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@ module CouchbaseOrm
22
module Types
33
class Timestamp < ActiveModel::Type::DateTime
44
def cast(value)
5-
value = super(value)
6-
return nil if value.nil?
7-
return Time.at(value) if value.is_a?(Integer) || value.is_a?(Float)
8-
return Time.at(value.to_i) if value.is_a?(String) && value =~ /^[0-9]+$/
9-
return value.utc if value.is_a?(Time)
5+
return nil if value.nil?
6+
7+
value = if value.is_a?(Integer) || value.is_a?(Float)
8+
Time.at(value)
9+
elsif value.is_a?(String) && value =~ /^[0-9]+$/
10+
Time.at(value.to_i)
11+
elsif value.is_a?(Time)
12+
value.utc
13+
else
14+
value
15+
end
16+
super(value)
1017
end
11-
18+
1219
def serialize(value)
1320
value&.to_i
1421
end

lib/couchbase-orm/utilities/query_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ def build_not_match(key, value)
117117
end
118118

119119
def serialize_value(key, value_before_type_cast)
120-
value =
120+
value =
121121
if value_before_type_cast.is_a?(Array)
122122
value_before_type_cast.map do |v|
123-
attribute_types[key.to_s].serialize(v)
123+
attribute_types[key.to_s].serialize(attribute_types[key.to_s].cast(v))
124124
end
125125
else
126-
attribute_types[key.to_s].serialize(value_before_type_cast)
126+
attribute_types[key.to_s].serialize(attribute_types[key.to_s].cast(value_before_type_cast))
127127
end
128128
CouchbaseOrm.logger.debug { "convert_values: #{key} => #{value_before_type_cast.inspect} => #{value.inspect} #{value.class} #{attribute_types[key.to_s]}" }
129129
value

0 commit comments

Comments
 (0)