Skip to content
Browse files

Filter by category now excludes rejected proposals and sorts by rating.

  • Loading branch information...
1 parent d5de5c5 commit 35b68d06b20785790576326a26936a480b542b99 @marioaquino marioaquino committed
View
2 vendor/engines/proposals/app/models/proposal.rb
@@ -44,7 +44,7 @@ def self.current_year
}
scope :by_current_track,
- lambda {|track_name| joins(:talk => :track).where('tracks.name' => track_name).where('proposals.created_at > ?', current_year ) }
+ lambda {|track_name| joins(:talk => :track).where('tracks.name' => track_name).where('proposals.created_at > ?', current_year ).where("proposals.status <> 'rejected'").joins('LEFT OUTER JOIN rates ON rates.rateable_id = proposals.id').order('rates.stars DESC') }
format_options.each {|format| scope format, :conditions => { :format => format } }
View
4 vendor/engines/proposals/spec/factories.rb
@@ -20,3 +20,7 @@
p.format 'talk'
p.talk { Factory(:talk) }
end
+
+Factory.define :rejected_proposal, :parent => :proposal do |rp|
+ rp.status 'rejected'
+end
View
31 vendor/engines/proposals/spec/models/proposal_spec.rb
@@ -304,8 +304,35 @@ def check_one_comment_list(comment_list, title, text)
before { Factory(:proposal, :talk => Factory(:big_data_talk)) }
- it 'returns proposals from the current year for a given track name' do
- described_class.by_current_track(track).should == [proposal]
+ describe 'filtering by track' do
+ it 'returns proposals from the current year for a given track name' do
+ described_class.by_current_track(track).should == [proposal]
+ end
+ end
+
+ describe 'handling rejected talks' do
+ let!(:rejected_proposal) { Factory(:rejected_proposal) }
+
+ it 'excludes rejected talks' do
+ described_class.by_current_track(track).should == [proposal]
+ end
+ end
+
+ def new_proposal(rating)
+ p = Factory(:proposal).tap do |p|
+ p.rate(rating, reviewer, :appeal)
+ end
+ p.reload
+ end
+
+ describe 'ordering by rating' do
+ let!(:proposal1) { new_proposal 1 }
+ let!(:proposal2) { new_proposal 5 }
+ let!(:proposal3) { new_proposal 3 }
+
+ it 'orders proposals by ratings first then without rating' do
+ described_class.by_current_track(track).should == [proposal2, proposal3, proposal1, proposal]
+ end
end
end
end

0 comments on commit 35b68d0

Please sign in to comment.
Something went wrong with that request. Please try again.