usergrid_ironhorse 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/lib/usergrid_ironhorse/base.rb +1 -1
- data/lib/usergrid_ironhorse/query.rb +14 -2
- data/lib/usergrid_ironhorse/version.rb +1 -1
- data/spec/usergrid_ironhorse/base_spec.rb +43 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -149,6 +149,15 @@ usergrid_ironhorse/spec/spec_settings.yaml to match.)
|
|
149
149
|
|
150
150
|
## Release notes
|
151
151
|
|
152
|
+
### 0.1.0
|
153
|
+
* New Features
|
154
|
+
1. next_page() added to return the next page of results from the server. An example of this used in conjunction
|
155
|
+
with to_a() is in base_spec.rb (see "should be able to page through results").
|
156
|
+
* Incompatible changes
|
157
|
+
1. each() iteration will now transparently cross page boundaries (as generally expected by Rails users).
|
158
|
+
You may use limit(n) to restrict the result set, but note that limit will retrieve the number of entities
|
159
|
+
specified as a single batch (no paging).
|
160
|
+
|
152
161
|
### 0.0.5
|
153
162
|
* New Features
|
154
163
|
1. support MassAssignmentSecurity (attr_accessible & attr_protected)
|
@@ -192,7 +192,7 @@ module Usergrid
|
|
192
192
|
# reflect that no changes should be made (since they can't be
|
193
193
|
# persisted). Returns the frozen instance.
|
194
194
|
#
|
195
|
-
# The row is simply removed with
|
195
|
+
# The row is simply removed with a +DELETE+ statement on the
|
196
196
|
# record's primary key, and no callbacks are executed.
|
197
197
|
#
|
198
198
|
# To enforce the object's +before_destroy+ and +after_destroy+
|
@@ -128,6 +128,17 @@ module Usergrid
|
|
128
128
|
|
129
129
|
def each
|
130
130
|
to_a.each { |*block_args| yield(*block_args) }
|
131
|
+
while @response.data['cursor'] && !limit_value
|
132
|
+
next_page
|
133
|
+
to_a.each { |*block_args| yield(*block_args) }
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def next_page
|
138
|
+
@options[:cursor] = @response.data['cursor']
|
139
|
+
@records = nil
|
140
|
+
load
|
141
|
+
self
|
131
142
|
end
|
132
143
|
|
133
144
|
# Returns +true+ if a record exists in the table that matches the +id+ or
|
@@ -859,6 +870,7 @@ module Usergrid
|
|
859
870
|
options.merge!({:skip => @options[:skip].to_json}) if @options[:skip]
|
860
871
|
options.merge!({:reversed => reversed?.to_json}) if reversed?
|
861
872
|
options.merge!({:order => @options[:order]}) if @options[:order]
|
873
|
+
options.merge!({:cursor => @options[:cursor]}) if @options[:cursor]
|
862
874
|
options
|
863
875
|
end
|
864
876
|
|
@@ -879,8 +891,8 @@ module Usergrid
|
|
879
891
|
def load
|
880
892
|
return if loaded?
|
881
893
|
begin
|
882
|
-
response = run_query
|
883
|
-
@records = response.entities.collect {|r| @model_class.model_name.constantize.new(r.data)}
|
894
|
+
@response = run_query
|
895
|
+
@records = @response.entities.collect {|r| @model_class.model_name.constantize.new(r.data)}
|
884
896
|
rescue RestClient::ResourceNotFound
|
885
897
|
@records = []
|
886
898
|
end
|
@@ -16,7 +16,7 @@ describe Usergrid::Ironhorse::Base do
|
|
16
16
|
after :all do
|
17
17
|
@foo.delete
|
18
18
|
@user.delete
|
19
|
-
#delete_application @application
|
19
|
+
#delete_application @application # not supported on server yet
|
20
20
|
end
|
21
21
|
|
22
22
|
class Foo < Usergrid::Ironhorse::Base; end
|
@@ -330,5 +330,47 @@ describe Usergrid::Ironhorse::Base do
|
|
330
330
|
Foo._protected_attributes = nil
|
331
331
|
end
|
332
332
|
|
333
|
+
it "should be able to page through results" do
|
334
|
+
bars = (1..15).collect do |i|
|
335
|
+
Bar.create! name: "name_#{i}", value: "value_#{i+1}"
|
336
|
+
end
|
337
|
+
query = Bar.all
|
338
|
+
page = query.to_a # first page
|
339
|
+
page.count.should eq 10
|
340
|
+
page = query.next_page # second page
|
341
|
+
count = 10
|
342
|
+
page.each do |bar|
|
343
|
+
bars[count].name.should eq bar.name
|
344
|
+
count += 1
|
345
|
+
end
|
346
|
+
count.should eq bars.count
|
347
|
+
bars.each {|bar| bar.delete}
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should iterate past page boundaries" do
|
351
|
+
bars = (1..15).collect do |i|
|
352
|
+
Bar.create! name: "name_#{i}", value: "value_#{i+1}"
|
353
|
+
end
|
354
|
+
count = 0
|
355
|
+
Bar.all.each do |bar|
|
356
|
+
bars[count].name.should eq bar.name
|
357
|
+
count += 1
|
358
|
+
end
|
359
|
+
count.should eq bars.count
|
360
|
+
bars.each {|bar| bar.delete}
|
361
|
+
end
|
362
|
+
|
363
|
+
it "should honor limit" do
|
364
|
+
bars = (1..15).collect do |i|
|
365
|
+
Bar.create! name: "name_#{i}", value: "value_#{i+1}"
|
366
|
+
end
|
367
|
+
count = 0
|
368
|
+
Bar.limit(13).each do |bar|
|
369
|
+
bars[count].name.should eq bar.name
|
370
|
+
count += 1
|
371
|
+
end
|
372
|
+
count.should eq 13
|
373
|
+
bars.each {|bar| bar.delete}
|
374
|
+
end
|
333
375
|
end
|
334
376
|
end
|