Permalink
Browse files

Merge pull request #1 from jvanderhoof/master

Single Picture & YGL hard limit fixes
  • Loading branch information...
2 parents 1568db5 + 3821751 commit 0ffec414aae52224c8c2c8c74f9fd729cb0dcd9f @tcocca committed Dec 6, 2011
Showing with 12 additions and 3 deletions.
  1. +1 −0 lib/you_got_listed.rb
  2. +1 −1 lib/you_got_listed/listing.rb
  3. +2 −2 lib/you_got_listed/listings.rb
  4. +8 −0 spec/you_got_listed/listing_spec.rb
View
@@ -4,6 +4,7 @@
require 'rash'
require 'will_paginate/collection'
require 'active_support/core_ext/array/grouping'
+require 'active_support/core_ext/object/blank'
require 'you_got_listed/client'
require 'you_got_listed/resource'
@@ -50,7 +50,7 @@ def city_neighborhood
end
def pictures
- self.photos.photo unless self.photos.blank? || self.photos.photo.blank?
+ (self.photos.photo.is_a?(Array) ? self.photos.photo : [self.photos.photo]) unless self.photos.blank? || self.photos.photo.blank?
end
def main_picture
@@ -52,10 +52,10 @@ def find_all_by_ids(listing_ids, include_off_market = true)
if listing_ids.any?{|list_id| list_id !=~ /[A-Z]{3}-[0-9]{3}-[0-9]{3}/}
search_params[:include_mls] = 1
end
- listing_ids.in_groups_of(500, false).each_with_index do |group, index|
+ # YGL no longer allows you to pass page_count > 10, so we're stuck paging
+ listing_ids.in_groups_of(10, false).each_with_index do |group, index|
group.delete_if{|x| x.nil?}
search_params[:listing_ids] = group.join(',')
- search_params[:page_count] = 500
search_params[:page_index] = index + 1
all_listings << find_all(search_params)
end
@@ -81,6 +81,14 @@
@listing.stub!(:pictures).and_return(nil)
@listing.main_picture.should be_nil
end
+
+ it "should return an array if the property has only one photo" do
+ rash = valid_listing_rash
+ rash[:photos].merge!(:photo => 'http://ygl-photos.s3.amazonaws.com/1236380.jpg')
+ @listing = YouGotListed::Listing.new(rash, @ygl)
+ @listing.pictures.is_a?(Array).should be_true
+ @listing.main_picture.should == 'http://ygl-photos.s3.amazonaws.com/1236380.jpg'
+ end
end
context "latitude" do

0 comments on commit 0ffec41

Please sign in to comment.