active-resource-pagination 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,15 +28,21 @@ module ActiveResource
28
28
 
29
29
  def decode(json)
30
30
  meta = super(json)
31
- if meta.is_a?(Hash)
31
+ if meta.is_a?(Hash) && meta['total_pages']
32
32
  list = PagedArray.new(meta[collection_name])
33
33
 
34
34
  list.total_pages = meta['total_pages']
35
35
  list.current_page = meta['current_page']
36
36
 
37
+ list
38
+ elsif meta.is_a?(Array)
39
+ list = PagedArray.new(meta)
40
+
41
+ list.total_pages = 1
42
+ list.current_page = 1
43
+
37
44
  list
38
45
  else
39
- # unexpected result, fall back to default behavior
40
46
  meta
41
47
  end
42
48
  end
@@ -60,5 +60,9 @@ class PaginationTest < Test::Unit::TestCase
60
60
  posts = Post.find(:all)
61
61
 
62
62
  assert_equal posts.length, 1
63
+
64
+ # mock page totals
65
+ assert_equal posts.total_pages, 1
66
+ assert_equal posts.current_page, 1
63
67
  end
64
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-resource-pagination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: