Skip to content

Instantly share code, notes, and snippets.

@jgagne33
Created March 31, 2009 17:01
Show Gist options
  • Save jgagne33/88271 to your computer and use it in GitHub Desktop.
Save jgagne33/88271 to your computer and use it in GitHub Desktop.
sale_bikes_local_premium_rio:
title: 2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER RIO
body: With a racing pedigree that spans over 20 years, the GSXR range of motorcycles are the rio ultimate race replicas.\n This GSXR1000 is lighter, faster, more powerful than any other bike in it's class... it's that simple!\n For more information call 01782 861100 and ask for Neil Wilson the Sales Manager rio.
body_html: <p>With a racing pedigree that spans over 20 years, the GSXR range of motorcycles rio are the ultimate race replicas.\n This GSXR1000 is lighter, faster, more powerful than any other bike in it's class... it's that simple!\n For more information call 01782 861100 and ask for Neil Wilson the Sales Manager rio.</p>
user: quentin
category: bikes
city: rio
country_city_merge: 1827559498 # brasil id
country: brasil
ip_address: 127.0.0.1
expires_at: <%= Time.now.advance(:days => 8).to_s :db %>
banned_at:
permalink: 2004-suzuki-gsxr-r1000-blue-red-silver-rio-22
updated_at: <%= 1.days.ago.to_s :db %>
created_at: <%= (6.days.ago + 30.minutes).to_s :db %>
type: SalePost
views_count: 20
price: '2,000'
premium: 1
coverage: cov_25
sale_bikes_premium_national:
title: 2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER NATIONAL
body: With a racing pedigree that spans over 20 years, the GSXR range of motorcycles are the ultimate race replicas.\n This GSXR1000 is lighter, faster, more powerful than any other bike in it's class... it's that simple!\n For more information call 01782 861100 and ask for Neil Wilson the Sales Manager FOR NATIONAL.
body_html: <p>With a racing pedigree that spans over 20 years, the GSXR range of motorcycles are the ultimate race replicas.\n This GSXR1000 is lighter, faster, more powerful than any other bike in it's class... it's that simple!\n For more information call 01782 861100 and ask for Neil Wilson the Sales Manager FOR NATIONAL.</p>
user: quentin
category: bikes
city: brazil_national
country_city_merge: 1827559498 # brasil id
country: brasil
ip_address: 127.0.0.1
expires_at: <%= Time.now.advance(:days => 8).to_s :db %>
banned_at:
permalink: 2004-suzuki-gsxr-r1000-blue-red-silver-national-24
updated_at: <%= 1.days.ago.to_s :db %>
created_at: <%= (6.days.ago + 30.minutes).to_s :db %>
type: SalePost
views_count: 20
price: '2,000'
premium: 1
coverage: cov_300
sale_bikes_premium_international:
title: 2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER INTERNATIONAL
body: With a racing pedigree that spans over 20 years, the GSXR range of motorcycles are the ultimate race replicas.\n This GSXR1000 is lighter, faster, more powerful than any other bike in it's class... it's that simple!\n For more information call 01782 861100 and ask for Neil Wilson the Sales Manager international.
body_html: <p>With a racing pedigree that spans over 20 years, the GSXR range of motorcycles are the ultimate race replicas.\n This GSXR1000 is lighter, faster, more powerful than any other bike in it's class... it's that simple!\n For more information call 01782 861100 and ask for Neil Wilson the Sales Manager international.</p>
user: quentin
category: bikes
city: international
country_city_merge: 1827559498 # brasil id
country: brasil
ip_address: 127.0.0.1
expires_at: <%= Time.now.advance(:days => 8).to_s :db %>
banned_at:
permalink: 2004-suzuki-gsxr-r1000-blue-red-silver-international-25
updated_at: <%= 1.days.ago.to_s :db %>
created_at: <%= (6.days.ago + 30.minutes).to_s :db %>
type: SalePost
views_count: 20
price: '2,000'
premium: 1
coverage: cov_500
THE CODE:
def find_featured_for(category, city_or_country, limit=5)
options = city_or_country.is_a?(City) ? {:city => city_or_country} : {:country => city_or_country}
PostFinder.construct({
:premium => true,
:order_by => "id RAND()",
:limit=> 5,
:category => category,
}.merge(options)
).results
end
def find_featured_for_header(category, city, limit=5)
results = find_featured_for(category, city, limit)
if results.size < limit
results = results.concat( find_featured_for(category, city.country, limit))
end
results
end
THE SPEC:
describe "finding featured posts for header" do
it "should return premium posts in same category then country" do
result = Post.find_featured_for_header(categories(:bikes), cities(:aracaju), 10)
print result.to_s
result.collect(&:title).should == ["2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER", "2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER RIO", "2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER INTERNATIONAL", "2006 SUZUKI GSX-R1000K6 BLUE, RED & SILVER NATIONAL"]
result.should == [posts(:sale_bikes_local_premium), posts(:sale_bikes_local_premium_rio), posts(:sale_bikes_premium_national), posts(:sale_bikes_local_premium)]
end
it "should not return non-premium posts" do
result = Post.find_featured_for_header(categories(:activities), cities(:rio_de_janeiro), 10)
result.should be_empty
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment