Skip to content

Commit

Permalink
Randomize featured pitches for a network
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen Hiller and Veez (Matt Remsik) authored and veezus committed Apr 17, 2009
1 parent 18feb62 commit be0a32b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/pitch.rb
Expand Up @@ -112,7 +112,7 @@ def unapproved
after_save :check_if_funded_state, :dispatch_fact_checker

named_scope :most_funded, :order => 'news_items.current_funding DESC'
named_scope :featured, :conditions => {:feature => true}
named_scope :featured, :conditions => {:feature => true}, :order => 'RAND()'
named_scope :almost_funded, :select => "news_items.*, case when news_items.status = 'active' then (1.0 - (news_items.current_funding / news_items.requested_amount)) else news_items.created_at end as sort_value", :order => "sort_value ASC"
named_scope :sorted, lambda {|direction| { :order => "news_items.created_at #{direction}" } }
named_scope :without_a_story, :conditions => 'news_items.id NOT IN (SELECT news_item_id FROM news_items WHERE news_items.type = "Story" AND news_items.status = "published")'
Expand Down
6 changes: 6 additions & 0 deletions spec/models/pitch_spec.rb
Expand Up @@ -221,6 +221,12 @@
end
end

describe "featured" do
it "should be randomized" do
Pitch.featured.proxy_options[:order].should match(/rand\(\)/i)
end
end

describe "almost funded" do
before(:each) do
@p = active_pitch(:requested_amount => 50, :current_funding => 20) #40 %
Expand Down

0 comments on commit be0a32b

Please sign in to comment.