Module: GoogleDataSource::TestHelper
- Defined in:
- lib/google_data_source/test_helper.rb
Overview
Some usefull helpers for testing datasources
Instance Method Summary collapse
-
#datasource_column(column) ⇒ Object
Returns the columns array of the JSON response.
-
#datasource_column_ids ⇒ Object
Returns the column ids of the JSON response.
-
#datasource_response ⇒ Object
Returns the parsed JSON argument of the datasource response.
Instance Method Details
#datasource_column(column) ⇒ Object
Returns the columns array of the JSON response
14 15 16 17 18 |
# File 'lib/google_data_source/test_helper.rb', line 14 def datasource_column(column) response = datasource_response column_no = response.table.cols.collect { |c| c['id'] }.index(column.to_s) response.table.rows.collect { |r| r['c'][column_no] } end |
#datasource_column_ids ⇒ Object
Returns the column ids of the JSON response
21 22 23 |
# File 'lib/google_data_source/test_helper.rb', line 21 def datasource_column_ids datasource_response.table.cols.collect { |c| c['id'] } end |
#datasource_response ⇒ Object
Returns the parsed JSON argument of the datasource response
6 7 8 9 10 11 |
# File 'lib/google_data_source/test_helper.rb', line 6 def datasource_response first_cmd = @response.body.match(/([^;"]*|"(\\"|[^"])*;?(\\"|[^"])*")*;/)[0] response = OpenStruct.new(JSON.parse(first_cmd.match(/^[^(]*\((.*)\);$/)[1])) response.table = OpenStruct.new(response.table) response end |