Skip to content

Commit 0826614

Browse files
committed
Merge pull request #103 from ryanhertz/listing-cart-methods
added a few methods to ListingCart
2 parents 4189492 + b1084f3 commit 0826614

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

lib/spark_api/models/listing_cart.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def initialize(attributes={})
1515
def ListingIds=(listing_ids)
1616
write_attribute("ListingIds", Array(listing_ids))
1717
end
18+
1819
def Name=(name)
1920
write_attribute("Name", name)
2021
end
@@ -27,6 +28,16 @@ def path
2728
end
2829
end
2930

31+
def filter
32+
"ListingCart Eq '#{self.Id}'"
33+
end
34+
35+
def listings(args = {})
36+
return [] if attributes["ListingIds"].nil?
37+
arguments = {:_filter => self.filter}.merge(args)
38+
Listing.collect(connection.get("/listingcarts/#{self.Id}/listings", arguments))
39+
end
40+
3041
def add_listing(listing)
3142
ids = listing.respond_to?(:Id) ? listing.Id : listing
3243
results = connection.post("#{self.resource_uri}", {"ListingIds" => Array(ids)})
@@ -52,6 +63,10 @@ def self.portal(arguments={})
5263
collect(connection.get("/#{self.element_name}/portal", arguments))
5364
end
5465

66+
def deletable?
67+
!attributes.has_key?("PortalCartType") || self.PortalCartType == "Custom"
68+
end
69+
5570
end
5671
end
5772
end

spec/unit/spark_api/models/listing_cart_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,44 @@
133133
end
134134
end
135135

136+
describe "#listings" do
137+
it "should return the listings in the cart" do
138+
resource = subject.class.new Id: 5, ListingIds: ["1234"]
139+
stub_api_get("/#{subject.class.element_name}/#{resource.Id}/listings", 'listings/multiple.json',
140+
:_filter => resource.filter)
141+
resource.listings.should be_a(Array)
142+
resource.listings.first.should be_a(Listing)
143+
end
144+
145+
it "should return an empty array if there aren't any listings" do
146+
resource = subject.class.new Id: 5
147+
resource.listings.should be_a(Array)
148+
resource.listings.count.should === 0
149+
end
150+
end
151+
152+
describe "filter" do
153+
it "should return a filter string for the cart" do
154+
resource = subject.class.new Id: 5
155+
resource.filter.should eq("ListingCart Eq '5'")
156+
end
157+
end
158+
159+
describe "#deletable?" do
160+
it "should return true for private custom carts" do
161+
resource = subject.class.new
162+
expect(resource.deletable?).to be_true
163+
end
164+
165+
it "should return true for custom vow carts" do
166+
resource = subject.class.new PortalCartType: "Custom"
167+
expect(resource.deletable?).to be_true
168+
end
169+
170+
it "should return false for vow carts" do
171+
resource = subject.class.new PortalCartType: "Favorites"
172+
expect(resource.deletable?).to be_false
173+
end
174+
end
175+
136176
end

0 commit comments

Comments
 (0)