Skip to content

Commit 8064b82

Browse files
committed
correctly tidy an empty result
1 parent a45a994 commit 8064b82

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: lib/mondrian_rest/api_formatters.rb

+6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@ module Mondrian::REST::Formatters
1111
# Generate 'tidy data' (http://vita.had.co.nz/papers/tidy-data.pdf)
1212
# from a result set.
1313
def self.tidy(result, options)
14+
1415
cube = result.cube
1516

1617
add_parents = options[:add_parents]
1718
properties = options[:properties]
1819
rs = result.to_h(add_parents, options[:debug])
20+
21+
if rs[:values].empty?
22+
return []
23+
end
24+
1925
measures = rs[:axes].first[:members]
2026
dimensions = rs[:axis_dimensions][1..-1]
2127
columns = []

Diff for: spec/api_spec.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,14 @@ def app
297297

298298
expect(JSON.parse(last_response.body)['values'].size).to eql(0)
299299

300-
end
300+
get '/cubes/Warehouse/aggregate.jsonrecords?drilldown[]=[Store+Type].[Store+Type]&cut[]=[Store].[Store].[Store+Country].%26[Mexico]&measures[]=Store+Invoice&nonempty=true&distinct=false&parents=false&debug=true'
301+
302+
expect(JSON.parse(last_response.body)).to eql({"data" => []})
301303

304+
get '/cubes/Warehouse/aggregate.csv?drilldown[]=[Store+Type].[Store+Type]&cut[]=[Store].[Store].[Store+Country].%26[Mexico]&measures[]=Store+Invoice&nonempty=true&distinct=false&parents=false&debug=true'
305+
306+
expect(last_response.body).to eql("")
307+
end
302308
end
303309
end
304310

0 commit comments

Comments
 (0)