Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update to handle results from queries that use parameter selection or…

… parameter redefinition
  • Loading branch information...
commit 6ba1410d546008b9bc4badec5c9dfd0dd115f1a5 1 parent 68271bc
@theganyo authored
View
10 lib/usergrid/extensions/response.rb
@@ -25,10 +25,10 @@ def multiple_entities?
def entities_data
return @entities_data if @entities_data
- entities_data = data['entities'] || data['data'] || data['messages']
+ entities_data = data['entities'] || data['data'] || data['messages'] || data['list']
raise "unable to determine entities from: #{data}" unless entities_data.is_a?(Array)
entities_data.each do |e|
- e['uri'] = resource.concat_urls(data['uri'], e['uuid']) if e['uuid']
+ e['uri'] = resource.concat_urls(data['uri'], e['uuid']) if e.is_a?(Hash) && e['uuid']
end
@entities_data = entities_data
end
@@ -37,7 +37,11 @@ def entities
return @entities if @entities
index = -1
@entities = entities_data.collect do |e|
- Usergrid::Entity.new e['uri'], resource.api_url, resource.options, self, index+=1
+ if e.is_a? Array
+ e
+ else
+ Usergrid::Entity.new e['uri'], resource.api_url, resource.options, self, index+=1
+ end
end
end
View
22 spec/usergrid/core/collection_spec.rb
@@ -7,7 +7,7 @@
@collection = @application['tests'].collection
@entity_data = []
(1..10).each do |i|
- test = { name: "test_#{i}" }
+ test = { name: "name_#{i}", value: "value_#{i+1}" }
@entity_data << test
end
@collection.create_entities @entity_data
@@ -18,11 +18,29 @@
delete_application @application
end
- it "should be able to query a collection" do
+ it "should be able to do a simple query" do
@collection.query "select * where name = \'#{@entity_data[0][:name]}\'"
@collection.size.should eq 1
end
+ it "should be able to select data elements" do
+ @collection.query "select name, value where name = \'#{@entity_data[0][:name]}\'"
+ @collection.size.should eq 1
+ # note: not Usergrid::Entity objects: it is an Array for this kind of query
+ values = @collection.entities.first
+ values[0].should eq @entity_data[0][:name]
+ values[1].should eq @entity_data[0][:value]
+ end
+
+ it "should be able to select redefined data elements" do
+ @collection.query "select { test1: name, test2 : value } where name = \'#{@entity_data[0][:name]}\'"
+ @collection.size.should eq 1
+ # note: not Usergrid::Entity objects: it is a Hash for this kind of query
+ values = @collection.entities.first
+ values.test1.should eq @entity_data[0][:name]
+ values.test2.should eq @entity_data[0][:value]
+ end
+
it "should be able to find an entity" do
@collection.query
entity = @collection.detect { |e| e.name == @entity_data[5][:name] }
Please sign in to comment.
Something went wrong with that request. Please try again.