Skip to content

Commit

Permalink
select: support vector of Time
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed May 30, 2016
1 parent bbcdd32 commit aed35de
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/groonga/client/response/select.rb
Expand Up @@ -75,11 +75,18 @@ def parse_records(raw_columns, raw_records)
end

def convert_value(value, type)
case type
when "Time"
Time.at(value)
case value
when ::Array
value.collect do |element|
convert_value(element, type)
end
else
value
case type
when "Time"
Time.at(value)
else
value
end
end
end

Expand Down
24 changes: 24 additions & 0 deletions test/response/test-select-command-version1.rb
Expand Up @@ -54,6 +54,30 @@ def test_time
records([[[1], [["updated_at", "Time"]], [updated_at]]]))
end

def test_time_vector
update1 = 1379040474
update2 = 1464598349
assert_equal([
{
"updates" => [
Time.at(update1),
Time.at(update2),
],
},
],
records([
[
[1],
[
["updates", "Time"],
],
[
[update1, update2],
],
]
]))
end

def test_duplicated_column_name
assert_equal([
{
Expand Down
27 changes: 27 additions & 0 deletions test/response/test-select-command-version3.rb
Expand Up @@ -97,6 +97,33 @@ def test_time
}))
end

def test_time_vector
update1 = 1379040474
update2 = 1464598349
assert_equal([
{
"updates" => [
Time.at(update1),
Time.at(update2),
],
},
],
records({
"n_hits" => 1,
"columns" => [
{
"name" => "updates",
"type" => "Time",
},
],
"records" => [
[
[update1, update2],
],
],
}))
end

def test_duplicated_column_name
assert_equal([
{
Expand Down

0 comments on commit aed35de

Please sign in to comment.