active_resource_pagination 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{active_resource_pagination}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dorren Chen"]
@@ -11,15 +11,13 @@ module ActiveResource
11
11
  # :params => {:year => 2010, :page => 1, :per_page => 20})
12
12
  #
13
13
  # To set default per_page value for all resources. you can do
14
- # ActiveResource.per_page = 20 # do this in config/environment or initializers
14
+ # ActiveResource::Base.per_page = 20 # do this in config/environment or initializers
15
15
  #
16
16
  # or to implement per_page() in your resource class.
17
17
  module Pagination
18
18
  def self.included(base)
19
19
  base.class_eval do
20
- class << self
21
- attr_accessor :per_page
22
- end
20
+ cattr_accessor :per_page
23
21
  end
24
22
  base.extend ClassMethods
25
23
  end
@@ -36,11 +34,12 @@ module ActiveResource
36
34
  def paginate(*args)
37
35
  options = args.last || {}
38
36
  options = options[:params] || options
37
+ options = options.reject{|k, v| v.blank?}
39
38
  options = {:page => 1, :per_page => per_page}.merge(options)
40
39
  page = options[:page]
41
40
  per_page = options[:per_page]
42
41
 
43
- arr = find(*args)
42
+ arr = find(*args) || []
44
43
  total_entries = options[:total_entries] || arr.size
45
44
  WillPaginate::Collection.create(page, per_page, total_entries) do |pager|
46
45
  if arr.size > per_page
@@ -1,6 +1,34 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe ActiveResource::Pagination do
4
+ describe "##per_page" do
5
+ it "should config per_page" do
6
+ ActiveResource::Base.per_page.should be_nil
7
+ ActiveResource::Base.per_page = 3
8
+ ActiveResource::Base.per_page.should == 3
9
+
10
+ class MySrc < ActiveResource::Base; end
11
+ MySrc.per_page.should == 3
12
+ end
13
+
14
+ it "should override per_page in method" do
15
+ class Something < ActiveResource::Base
16
+ def self.per_page
17
+ 2
18
+ end
19
+ end
20
+
21
+ Something.per_page.should == 2
22
+ end
23
+
24
+ it "should override per_page ad hoc" do
25
+ class Comment < ActiveResource::Base
26
+ end
27
+ Comment.per_page = 5
28
+ Comment.per_page.should == 5
29
+ end
30
+ end
31
+
4
32
  describe "##paginate" do
5
33
  before(:all) do
6
34
  class Article < ActiveResource::Base
@@ -24,17 +52,6 @@ describe ActiveResource::Pagination do
24
52
  ActiveResource::Base.should respond_to(:paginate)
25
53
  end
26
54
 
27
- it "should override per_page in method" do
28
- Article.per_page.should == 2
29
- end
30
-
31
- it "should override per_page ad hoc" do
32
- class Comment < ActiveResource::Base
33
- end
34
- Comment.per_page = 5
35
- Comment.per_page.should == 5
36
- end
37
-
38
55
  describe "when backend does not paginate" do
39
56
  before(:each) do
40
57
  Article.should_receive(:find).and_return(@articles)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Dorren Chen