spark_api 1.0.2 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +86 -3
- data/VERSION +1 -1
- data/lib/spark_api.rb +1 -0
- data/lib/spark_api/authentication/oauth2.rb +43 -2
- data/lib/spark_api/configuration/oauth2_configurable.rb +3 -1
- data/lib/spark_api/models.rb +1 -0
- data/lib/spark_api/models/listing.rb +17 -1
- data/lib/spark_api/models/rental_calendar.rb +26 -0
- data/lib/spark_api/options_hash.rb +18 -0
- data/script/combined_flow_example.rb +55 -0
- data/script/oauth2_example.rb +2 -2
- data/spec/fixtures/listings/rental_calendar.json +19 -0
- data/spec/fixtures/listings/with_rental_calendar.json +52 -0
- data/spec/unit/spark_api/authentication/oauth2_spec.rb +79 -1
- data/spec/unit/spark_api/models/listing_spec.rb +7 -0
- data/spec/unit/spark_api/models/rental_calendar_spec.rb +30 -0
- data/spec/unit/spark_api/options_hash_spec.rb +14 -0
- metadata +15 -96
- data/bin/spark_api~ +0 -8
- data/lib/spark_api/authentication/api_auth.rb~ +0 -104
- data/lib/spark_api/authentication/base_auth.rb~ +0 -47
- data/lib/spark_api/authentication/oauth2.rb~ +0 -199
- data/lib/spark_api/authentication/oauth2_impl/grant_type_base.rb~ +0 -87
- data/lib/spark_api/authentication/oauth2_impl/grant_type_code.rb~ +0 -49
- data/lib/spark_api/authentication/oauth2_impl/grant_type_password.rb~ +0 -45
- data/lib/spark_api/authentication/oauth2_impl/grant_type_refresh.rb~ +0 -36
- data/lib/spark_api/authentication/oauth2_impl/middleware.rb~ +0 -39
- data/lib/spark_api/authentication/oauth2_impl/password_provider.rb~ +0 -25
- data/lib/spark_api/cli.rb~ +0 -158
- data/lib/spark_api/cli/api_auth.rb~ +0 -8
- data/lib/spark_api/cli/oauth2.rb~ +0 -14
- data/lib/spark_api/cli/setup.rb~ +0 -47
- data/lib/spark_api/configuration.rb~ +0 -54
- data/lib/spark_api/configuration/yaml.rb~ +0 -101
- data/lib/spark_api/faraday.rb~ +0 -64
- data/lib/spark_api/models.rb~ +0 -33
- data/lib/spark_api/models/account.rb~ +0 -115
- data/lib/spark_api/models/base.rb~ +0 -118
- data/lib/spark_api/models/connect_prefs.rb~ +0 -10
- data/lib/spark_api/models/constraint.rb~ +0 -16
- data/lib/spark_api/models/contact.rb~ +0 -49
- data/lib/spark_api/models/custom_fields.rb~ +0 -12
- data/lib/spark_api/models/document.rb~ +0 -11
- data/lib/spark_api/models/finders.rb~ +0 -45
- data/lib/spark_api/models/idx_link.rb~ +0 -47
- data/lib/spark_api/models/listing.rb~ +0 -197
- data/lib/spark_api/models/listing_cart.rb~ +0 -72
- data/lib/spark_api/models/market_statistics.rb~ +0 -33
- data/lib/spark_api/models/message.rb~ +0 -21
- data/lib/spark_api/models/note.rb~ +0 -41
- data/lib/spark_api/models/notification.rb~ +0 -42
- data/lib/spark_api/models/open_house.rb~ +0 -24
- data/lib/spark_api/models/photo.rb~ +0 -70
- data/lib/spark_api/models/property_types.rb~ +0 -7
- data/lib/spark_api/models/saved_search.rb~ +0 -16
- data/lib/spark_api/models/shared_listing.rb~ +0 -35
- data/lib/spark_api/models/standard_fields.rb~ +0 -50
- data/lib/spark_api/models/subresource.rb~ +0 -19
- data/lib/spark_api/models/system_info.rb~ +0 -14
- data/lib/spark_api/models/tour_of_home.rb~ +0 -24
- data/lib/spark_api/models/video.rb~ +0 -16
- data/lib/spark_api/models/virtual_tour.rb~ +0 -18
- data/lib/spark_api/multi_client.rb~ +0 -59
- data/lib/spark_api/paginate.rb~ +0 -109
- data/lib/spark_api/primary_array.rb~ +0 -29
- data/lib/spark_api/request.rb~ +0 -96
- data/lib/spark_api/response.rb~ +0 -70
- data/lib/spark_api/version.rb~ +0 -4
- data/script/console~ +0 -6
- data/script/example.rb~ +0 -27
- data/spec/unit/flexmls_api_spec.rb~ +0 -23
- data/spec/unit/spark_api/authentication/api_auth_spec.rb~ +0 -169
- data/spec/unit/spark_api/authentication/base_auth_spec.rb~ +0 -10
- data/spec/unit/spark_api/authentication/oauth2_impl/grant_type_base_spec.rb~ +0 -10
- data/spec/unit/spark_api/authentication/oauth2_spec.rb~ +0 -205
- data/spec/unit/spark_api/authentication_spec.rb~ +0 -38
- data/spec/unit/spark_api/configuration/yaml_spec.rb~ +0 -72
- data/spec/unit/spark_api/configuration_spec.rb~ +0 -122
- data/spec/unit/spark_api/faraday_spec.rb~ +0 -90
- data/spec/unit/spark_api/models/contact_spec.rb~ +0 -108
- data/spec/unit/spark_api/models/listing_cart_spec.rb~ +0 -127
- data/spec/unit/spark_api/models/listing_spec.rb~ +0 -320
- data/spec/unit/spark_api/models/message_spec.rb~ +0 -47
- data/spec/unit/spark_api/models/note_spec.rb~ +0 -63
- data/spec/unit/spark_api/models/notification_spec.rb~ +0 -62
- data/spec/unit/spark_api/models/shared_listing_spec.rb~ +0 -45
- data/spec/unit/spark_api/multi_client_spec.rb~ +0 -56
- data/spec/unit/spark_api/paginate_spec.rb~ +0 -224
- data/spec/unit/spark_api/primary_array_spec.rb~ +0 -41
- data/spec/unit/spark_api/request_spec.rb~ +0 -344
@@ -1,47 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe Message do
|
5
|
-
before(:each) do
|
6
|
-
stub_auth_request
|
7
|
-
end
|
8
|
-
|
9
|
-
subject do
|
10
|
-
m = Message.new
|
11
|
-
m.attributes["Type"] = "ShowingRequest"
|
12
|
-
m.attributes["EventDateTime"] = "2011-09-15T14:00:00"
|
13
|
-
m.attributes["SenderId"] = "20110112234857732941000000"
|
14
|
-
m.attributes["Subject"] = "Showing Request For 123 Main St, MLS # 12-345"
|
15
|
-
m.attributes["Body"] = "A showing is requested for ..."
|
16
|
-
m.attributes["ListingId"] = "20110112234857732941000000"
|
17
|
-
m
|
18
|
-
end
|
19
|
-
|
20
|
-
context "/messages", :support do
|
21
|
-
on_get_it "should get all my messages"
|
22
|
-
|
23
|
-
on_post_it "should save a new message" do
|
24
|
-
stub_api_post("/messages", 'messages/new.json', 'messages/post.json')
|
25
|
-
subject.save.should be(true)
|
26
|
-
end
|
27
|
-
|
28
|
-
on_post_it "should save a new message with recipients" do
|
29
|
-
stub_api_post("/messages", 'messages/new_with_recipients.json', 'messages/post.json')
|
30
|
-
subject.attributes["Recipients"] = ["20110112234857732941000000","20110092234857738467000000"]
|
31
|
-
subject.save.should be(true)
|
32
|
-
end
|
33
|
-
|
34
|
-
on_post_it "should fail saving" do
|
35
|
-
stub_api_post("/messages", 'messages/new_empty.json') do |request|
|
36
|
-
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
37
|
-
end
|
38
|
-
m=subject.class.new
|
39
|
-
m.save.should be(false)
|
40
|
-
expect{ m.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "/messages/<message_id>", :support do
|
45
|
-
on_get_it "should get a single message"
|
46
|
-
end
|
47
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
describe Note do
|
4
|
-
|
5
|
-
it "responds to instance and class methods" do
|
6
|
-
Note.should respond_to(:get)
|
7
|
-
Note.new.should respond_to(:save)
|
8
|
-
Note.new.should respond_to(:save!)
|
9
|
-
Note.new.should respond_to(:delete)
|
10
|
-
end
|
11
|
-
|
12
|
-
context "when shared with a contact" do
|
13
|
-
before :each do
|
14
|
-
@note = Listing.new(:ListingKey => "1234").shared_notes("5678")
|
15
|
-
stub_auth_request
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should have the correct path" do
|
19
|
-
@note.path.should == "/listings/1234/shared/notes/contacts/5678"
|
20
|
-
end
|
21
|
-
|
22
|
-
context "/listings/<listing_id>/shared/notes/contacts/<contact_id>", :support do
|
23
|
-
on_get_it "GET should get my notes" do
|
24
|
-
stub_api_get("#{@note.path}", 'notes/agent_shared.json')
|
25
|
-
ret = @note.get
|
26
|
-
ret.Note.should == "lorem ipsum dolor sit amet"
|
27
|
-
end
|
28
|
-
|
29
|
-
on_get_it "should return a nil when no shared notes exist" do
|
30
|
-
stub_api_get("#{@note.path}", 'notes/agent_shared_empty.json')
|
31
|
-
@note.get.should be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
on_delete_it "should allow you to delete an existing note" do
|
35
|
-
stub_api_delete("#{@note.path}", 'generic_delete.json')
|
36
|
-
@note.new.delete # test that no exceptions are raised
|
37
|
-
end
|
38
|
-
|
39
|
-
on_put_it "should raise an exception when adding a note fails" do
|
40
|
-
n = @note.new(:Note => "lorem ipsum dolor")
|
41
|
-
|
42
|
-
stub_api_put("#{@note.path}", 'notes/new.json') do |request|
|
43
|
-
request.to_return(:status => 500, :body => fixture('generic_failure.json'))
|
44
|
-
end
|
45
|
-
|
46
|
-
expect { n.save! }.to raise_error(FlexmlsApi::ClientError) { |e| e.status.should == 500 }
|
47
|
-
expect { n.save }.to raise_error(FlexmlsApi::ClientError) { |e| e.status.should == 500 }
|
48
|
-
end
|
49
|
-
|
50
|
-
on_put_it "should allow adding of a note" do
|
51
|
-
n = @note.new(:Note => "lorem ipsum dolor")
|
52
|
-
stub_api_put("#{@note.path}", 'notes/new.json', 'notes/add.json')
|
53
|
-
n.save
|
54
|
-
n.ResourceUri.should == '/v1/listings/20100909200152674436000000/shared/notes/contacts/20110407212043616271000000/'
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
after :each do
|
60
|
-
@note = nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
describe Notification do
|
4
|
-
before(:each) do
|
5
|
-
stub_auth_request
|
6
|
-
end
|
7
|
-
|
8
|
-
subject do
|
9
|
-
m = Notification.new
|
10
|
-
m.attributes['Type'] = 'OperationComplete'
|
11
|
-
m.attributes['Message'] = 'Your PDF generation has completed!'
|
12
|
-
m.attributes['BrowserUri'] = 'http://myapplication.com/cmas/19581825.pdf'
|
13
|
-
m.attributes['ResourceUri'] = 'http://myapplication.com/cmas/19581825.json'
|
14
|
-
m
|
15
|
-
end
|
16
|
-
|
17
|
-
context "/notifications", :support do
|
18
|
-
on_get_it "should get my notifications" do
|
19
|
-
stub_api_get('/notifications', 'notifications/notifications.json')
|
20
|
-
|
21
|
-
notifications = Notification.get
|
22
|
-
notifications.should be_an(Array)
|
23
|
-
notifications.count.should equal(3)
|
24
|
-
end
|
25
|
-
|
26
|
-
on_post_it "should create a new notification" do
|
27
|
-
stub_api_post("/notifications", 'notifications/new.json', 'notifications/post.json')
|
28
|
-
subject.save.should be(true)
|
29
|
-
end
|
30
|
-
|
31
|
-
on_post_it "should fail saving" do
|
32
|
-
stub_api_post("/notifications", 'notifications/new_empty.json') do |request|
|
33
|
-
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
34
|
-
end
|
35
|
-
m = subject.class.new
|
36
|
-
m.attributes['Message'] = 'Your PDF generation has completed!'
|
37
|
-
m.attributes['BrowserUri'] = 'http://myapplication.com/cmas/19581825.pdf'
|
38
|
-
m.attributes['ResourceUri'] = 'http://myapplication.com/cmas/19581825.json'
|
39
|
-
m.save.should be(false)
|
40
|
-
expect{ m.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "/notifications/<notification_id1>,<notification_id2>,...<notification_idN>", :support do
|
45
|
-
on_put_it "should mark notifications as read" do
|
46
|
-
to_mark = [12345678901234567890000001,12345678901234567890000002]
|
47
|
-
stub_api_put("/notifications/#{to_mark.join(',')}",
|
48
|
-
'notifications/mark_read.json', 'success.json')
|
49
|
-
|
50
|
-
Notification.mark_read(to_mark)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "/notifications/unread", :support do
|
55
|
-
on_get_it "should get a count of unread notifications" do
|
56
|
-
stub_api_get('/notifications/unread', 'notifications/unread.json', {:_pagination => 'count'})
|
57
|
-
|
58
|
-
notification_count = Notification.unread
|
59
|
-
notification_count.should equal(30)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
|
4
|
-
describe SharedListing do
|
5
|
-
before(:each) do
|
6
|
-
stub_auth_request
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should respond to the finders" do
|
10
|
-
SharedListing.should respond_to(:find)
|
11
|
-
end
|
12
|
-
|
13
|
-
context "/sharedlistings", :support do
|
14
|
-
on_post_it "should create shared listings" do
|
15
|
-
stub_api_post("/#{subject.class.element_name}", 'listings/shared_listing_new.json', 'listings/shared_listing_post.json')
|
16
|
-
subject.ListingIds = ["20110224152431857619000000","20110125122333785431000000"]
|
17
|
-
subject.ViewId = "20080125122333787615000000"
|
18
|
-
subject.save.should be(true)
|
19
|
-
subject.ResourceUri.should eq("http://www.flexmls.com/share/15Ar/3544-N-Olsen-Avenue-Tucson-AZ-85719")
|
20
|
-
end
|
21
|
-
|
22
|
-
on_post_it "should fail creating" do
|
23
|
-
stub_api_post("/#{subject.class.element_name}",'empty.json') do |request|
|
24
|
-
request.to_return(:status => 400, :body => fixture('errors/failure.json'))
|
25
|
-
end
|
26
|
-
subject
|
27
|
-
subject.save.should be(false)
|
28
|
-
expect{ subject.save! }.to raise_error(FlexmlsApi::ClientError){ |e| e.status.should == 400 }
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "/sharedlistings/<shared_listing_id>", :support do
|
33
|
-
on_get_it "should get shared listing" do
|
34
|
-
shared_id = '15Ar'
|
35
|
-
stub_api_get("/#{subject.class.element_name}/#{shared_id}",
|
36
|
-
'listings/shared_listing_get.json')
|
37
|
-
|
38
|
-
shared = SharedListing.find(shared_id)
|
39
|
-
shared.should respond_to('SharedUri')
|
40
|
-
shared.Mode.should eq('Public')
|
41
|
-
shared.ListingIds.should be_an(Array)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
# Test client implemenations for multi client switching
|
4
|
-
module FlexmlsApi
|
5
|
-
def self.test_client_a
|
6
|
-
Thread.current[:test_client_a] ||= Client.new(:api_key => "a")
|
7
|
-
end
|
8
|
-
def self.test_client_b
|
9
|
-
Client.new(:api_key => "b")
|
10
|
-
end
|
11
|
-
def self.test_client_c
|
12
|
-
Client.new(:api_key => "c")
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe FlexmlsApi::MultiClient do
|
17
|
-
it "should activate a client implemenation when activate()" do
|
18
|
-
FlexmlsApi.activate(:test_client_a)
|
19
|
-
FlexmlsApi.client.api_key.should eq('a')
|
20
|
-
FlexmlsApi.activate(:test_client_b)
|
21
|
-
FlexmlsApi.client.api_key.should eq('b')
|
22
|
-
FlexmlsApi.activate(:test_client_c)
|
23
|
-
FlexmlsApi.client.api_key.should eq('c')
|
24
|
-
FlexmlsApi.activate(:test_client_a)
|
25
|
-
FlexmlsApi.client.api_key.should eq('a')
|
26
|
-
end
|
27
|
-
it "should fail to activate symbols that do not have implementations" do
|
28
|
-
expect { FlexmlsApi.activate(:test_client_d) }.to raise_error(ArgumentError)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should temporarily activate a client implemenation when activate() block" do
|
32
|
-
FlexmlsApi.activate(:test_client_a)
|
33
|
-
FlexmlsApi.client.api_key.should eq('a')
|
34
|
-
FlexmlsApi.activate(:test_client_b) do
|
35
|
-
FlexmlsApi.client.api_key.should eq('b')
|
36
|
-
end
|
37
|
-
FlexmlsApi.client.api_key.should eq('a')
|
38
|
-
expect do
|
39
|
-
FlexmlsApi.activate(:test_client_c) do
|
40
|
-
FlexmlsApi.client.api_key.should eq('c')
|
41
|
-
raise "OH MY GOODNESS I BLEW UP!!!"
|
42
|
-
end
|
43
|
-
end.to raise_error
|
44
|
-
FlexmlsApi.client.api_key.should eq('a')
|
45
|
-
end
|
46
|
-
|
47
|
-
context "yaml" do
|
48
|
-
it "should activate a client implemenation when activate()" do
|
49
|
-
FlexmlsApi::Configuration::YamlConfig.stub(:config_path) { "spec/config/flexmls_api" }
|
50
|
-
FlexmlsApi.activate(:test_key)
|
51
|
-
FlexmlsApi.client.api_key.should eq('demo_key')
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
@@ -1,224 +0,0 @@
|
|
1
|
-
require './spec/spec_helper'
|
2
|
-
|
3
|
-
class PaginateResponseTester
|
4
|
-
include FlexmlsApi::PaginateHelper
|
5
|
-
end
|
6
|
-
|
7
|
-
class PaginateModelTester < FlexmlsApi::Models::Base
|
8
|
-
@tester = PaginateResponseTester.new
|
9
|
-
attr_accessor :val
|
10
|
-
def initialize (val)
|
11
|
-
@val = val
|
12
|
-
end
|
13
|
-
class << self
|
14
|
-
attr_accessor :options
|
15
|
-
def get(options)
|
16
|
-
@options = options
|
17
|
-
json = "{#{paginate_json}}"
|
18
|
-
hash = JSON.parse(json)
|
19
|
-
results = @tester.paginate_response([1,2,3,4,5,6,7,8,9,10], hash["Pagination"])
|
20
|
-
collect(results)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class PaginateModelTester50 < PaginateModelTester
|
26
|
-
@tester = PaginateResponseTester.new
|
27
|
-
def self.per_page
|
28
|
-
50
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
describe FlexmlsApi::PaginateResponse do
|
34
|
-
|
35
|
-
describe "paginate_response" do
|
36
|
-
subject { PaginateResponseTester.new }
|
37
|
-
it "should give me the first page" do
|
38
|
-
json = "{#{paginate_json}}"
|
39
|
-
hash = JSON.parse(json)
|
40
|
-
results = subject.paginate_response([1,2,3,4,5,6,7,8,9,10], hash["Pagination"])
|
41
|
-
results.offset.should eq(0)
|
42
|
-
results.next_page.should eq(2)
|
43
|
-
results.previous_page.should eq(nil)
|
44
|
-
results.current_page.should eq(1)
|
45
|
-
results.per_page.should eq(10)
|
46
|
-
results.total_pages.should eq(4)
|
47
|
-
results.total_entries.should eq(38)
|
48
|
-
results[0].should eq(1)
|
49
|
-
end
|
50
|
-
it "should give me the second page" do
|
51
|
-
json = "{#{paginate_json(2)}}"
|
52
|
-
hash = JSON.parse(json)
|
53
|
-
results = subject.paginate_response([11,12,13,14,15,16,17,18,19,20], hash["Pagination"])
|
54
|
-
results.offset.should eq(10)
|
55
|
-
results.next_page.should eq(3)
|
56
|
-
results.previous_page.should eq(1)
|
57
|
-
results.current_page.should eq(2)
|
58
|
-
results.per_page.should eq(10)
|
59
|
-
results.total_pages.should eq(4)
|
60
|
-
results.total_entries.should eq(38)
|
61
|
-
results[0].should eq(11)
|
62
|
-
end
|
63
|
-
it "should give me the third page" do
|
64
|
-
json = "{#{paginate_json(3)}}"
|
65
|
-
hash = JSON.parse(json)
|
66
|
-
results = subject.paginate_response([21,22,23,24,25,26,27,28,29,30], hash["Pagination"])
|
67
|
-
results.offset.should eq(20)
|
68
|
-
results.next_page.should eq(4)
|
69
|
-
results.previous_page.should eq(2)
|
70
|
-
results.current_page.should eq(3)
|
71
|
-
results.per_page.should eq(10)
|
72
|
-
results.total_pages.should eq(4)
|
73
|
-
results.total_entries.should eq(38)
|
74
|
-
results[0].should eq(21)
|
75
|
-
end
|
76
|
-
it "should give me the last page" do
|
77
|
-
json = "{#{paginate_json(4)}}"
|
78
|
-
hash = JSON.parse(json)
|
79
|
-
results = subject.paginate_response([31,32,33,34,35,36,37,38], hash["Pagination"])
|
80
|
-
results.offset.should eq(30)
|
81
|
-
results.next_page.should eq(nil)
|
82
|
-
results.previous_page.should eq(3)
|
83
|
-
results.current_page.should eq(4)
|
84
|
-
results.per_page.should eq(10)
|
85
|
-
results.total_pages.should eq(4)
|
86
|
-
results.total_entries.should eq(38)
|
87
|
-
results[0].should eq(31)
|
88
|
-
results[-1].should eq(38)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe FlexmlsApi::Paginate do
|
94
|
-
describe "paginate" do
|
95
|
-
it "should give me a will paginate collection" do
|
96
|
-
results = PaginateModelTester.paginate(:page => 1)
|
97
|
-
results.should be_a(WillPaginate::Collection)
|
98
|
-
results.offset.should eq(0)
|
99
|
-
results.next_page.should eq(2)
|
100
|
-
results.previous_page.should eq(nil)
|
101
|
-
results.current_page.should eq(1)
|
102
|
-
results.per_page.should eq(10)
|
103
|
-
results.total_pages.should eq(4)
|
104
|
-
results.total_entries.should eq(38)
|
105
|
-
|
106
|
-
results[0].should be_a(PaginateModelTester)
|
107
|
-
results[0].val.should eq(1)
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should give me pagination options" do
|
112
|
-
PaginateModelTester.paginate(:page => 1)
|
113
|
-
opts = PaginateModelTester.options
|
114
|
-
opts["_pagination"].should eq(1)
|
115
|
-
opts["_limit"].should eq(25)
|
116
|
-
opts["_page"].should eq(1)
|
117
|
-
opts.has_key?(:page).should eq(false)
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe "per_page" do
|
122
|
-
it "should set the default model max results per page" do
|
123
|
-
results = PaginateModelTester50.paginate(:page => 1)
|
124
|
-
opts = PaginateModelTester50.options
|
125
|
-
opts["_limit"].should eq(50)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
# non unit-y real world test of paginations with listings
|
130
|
-
context "paginating listings" do
|
131
|
-
before do
|
132
|
-
stub_auth_request
|
133
|
-
end
|
134
|
-
|
135
|
-
subject { FlexmlsApi::Models::Listing }
|
136
|
-
it "gives me page one of listings" do
|
137
|
-
json = <<-JSON
|
138
|
-
{"D": {
|
139
|
-
"Success": true,
|
140
|
-
"Results": [#{ListingJson.create_all(10)}],
|
141
|
-
#{paginate_json}
|
142
|
-
}
|
143
|
-
JSON
|
144
|
-
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
|
145
|
-
with(:query => {
|
146
|
-
:ApiSig => "4a00ca0e657c824d85a5fe1007d9c52d",
|
147
|
-
:ApiUser => "foobar",
|
148
|
-
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
149
|
-
:_limit => '10',
|
150
|
-
:_page => '1',
|
151
|
-
:_pagination => '1'
|
152
|
-
}).
|
153
|
-
to_return(:body => json)
|
154
|
-
results = subject.paginate(:page=>1, :per_page=>10)
|
155
|
-
results.should be_a(WillPaginate::Collection)
|
156
|
-
results.offset.should eq(0)
|
157
|
-
results.next_page.should eq(2)
|
158
|
-
results.previous_page.should eq(nil)
|
159
|
-
results.current_page.should eq(1)
|
160
|
-
results.per_page.should eq(10)
|
161
|
-
results.total_pages.should eq(4)
|
162
|
-
results.total_entries.should eq(38)
|
163
|
-
results.length.should eq(10)
|
164
|
-
|
165
|
-
results[0].should be_a(subject)
|
166
|
-
results[0].ListPrice.should eq(50000.0)
|
167
|
-
|
168
|
-
end
|
169
|
-
it "gives me page two of listings" do
|
170
|
-
json = <<-JSON
|
171
|
-
{"D": {
|
172
|
-
"Success": true,
|
173
|
-
"Results": [#{ListingJson.create_all(10)}],
|
174
|
-
#{paginate_json(2)}
|
175
|
-
}
|
176
|
-
JSON
|
177
|
-
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
|
178
|
-
with(:query => {
|
179
|
-
:ApiSig => "094d3851a0c4c4563baf70ca45087e30",
|
180
|
-
:ApiUser => "foobar",
|
181
|
-
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
182
|
-
:_limit => '10',
|
183
|
-
:_page => '2',
|
184
|
-
:_pagination => '1'
|
185
|
-
}).
|
186
|
-
to_return(:body => json)
|
187
|
-
results = subject.paginate(:page=>2, :per_page=>10)
|
188
|
-
results.next_page.should eq(3)
|
189
|
-
results.previous_page.should eq(1)
|
190
|
-
results.current_page.should eq(2)
|
191
|
-
end
|
192
|
-
it "gives me page four of listings" do
|
193
|
-
json = <<-JSON
|
194
|
-
{"D": {
|
195
|
-
"Success": true,
|
196
|
-
"Results": [#{ListingJson.create_all(8)}],
|
197
|
-
#{paginate_json(4)}
|
198
|
-
}
|
199
|
-
JSON
|
200
|
-
stub_request(:get, "#{FlexmlsApi.endpoint}/#{FlexmlsApi.version}/listings").
|
201
|
-
with(:query => {
|
202
|
-
:ApiSig => "dcfce1fe9289c905f8d2d01cbb850edc",
|
203
|
-
:ApiUser => "foobar",
|
204
|
-
:AuthToken => "c401736bf3d3f754f07c04e460e09573",
|
205
|
-
:_limit => '10',
|
206
|
-
:_page => '4',
|
207
|
-
:_pagination => '1'
|
208
|
-
}).
|
209
|
-
to_return(:body => json)
|
210
|
-
results = subject.paginate(:page=>4, :per_page=>10)
|
211
|
-
results.next_page.should eq(nil)
|
212
|
-
results.previous_page.should eq(3)
|
213
|
-
results.current_page.should eq(4)
|
214
|
-
results.per_page.should eq(10)
|
215
|
-
results.total_pages.should eq(4)
|
216
|
-
results.total_entries.should eq(38)
|
217
|
-
|
218
|
-
results.length.should eq(8)
|
219
|
-
results[0].should be_a(subject)
|
220
|
-
results[0].ListPrice.should eq(50000.0)
|
221
|
-
end
|
222
|
-
|
223
|
-
end
|
224
|
-
end
|