/
active_resource_spec.rb
52 lines (41 loc) · 1.51 KB
/
active_resource_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'spec_helper'
require 'will_paginate/finders/active_resource'
require 'active_resource/http_mock'
class AresProject < ActiveResource::Base
self.site = 'http://localhost:4000'
end
describe WillPaginate::Finders::ActiveResource do
before :all do
# ActiveResource::HttpMock.respond_to do |mock|
# mock.get "/ares_projects.xml?page=1&per_page=5", {}, [].to_xml
# end
end
it "should integrate with ActiveResource::Base" do
ActiveResource::Base.should respond_to(:paginate)
end
it "should error when no parameters for #paginate" do
lambda { AresProject.paginate }.should raise_error(ArgumentError)
end
it "should paginate" do
AresProject.expects(:find_every).with(:params => { :page => 1, :per_page => 5 }).returns([])
AresProject.paginate(:page => 1, :per_page => 5)
end
it "should have 30 per_page as default" do
AresProject.expects(:find_every).with(:params => { :page => 1, :per_page => 30 }).returns([])
AresProject.paginate(:page => 1)
end
it "should support #paginate(:all)" do
lambda { AresProject.paginate(:all) }.should raise_error(ArgumentError)
end
it "should error #paginate(:other)" do
lambda { AresProject.paginate(:first) }.should raise_error(ArgumentError)
end
protected
def create(page = 2, limit = 5, total = nil, &block)
if block_given?
WillPaginate::Collection.create(page, limit, total, &block)
else
WillPaginate::Collection.new(page, limit, total)
end
end
end