File tree 5 files changed +50
-1
lines changed
5 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ class HomeController < ApplicationController
22 # for rss feeds, load the user's tag filters if a token is passed
33 before_filter :find_user_from_rss_token , :only => [ :index , :newest ]
44 before_filter { @page = page }
5+ before_filter :require_logged_in_user , :only => [ :upvoted ]
56
67 def about
78 begin
@@ -163,6 +164,30 @@ def top
163164 render :action => "index"
164165 end
165166
167+ def upvoted
168+ @stories , @show_more = get_from_cache ( upvoted : true , user : @user ) {
169+ paginate @user . upvoted_stories . order ( 'votes.id DESC' )
170+ }
171+
172+ @heading = @title = "Upvoted"
173+ @cur_url = "/upvoted"
174+
175+ @rss_link = { :title => "RSS 2.0 - Upvoted Items" ,
176+ :href => "/upvoted.rss#{ ( @user ? "?token=#{ @user . rss_token } " : "" ) } " }
177+
178+ respond_to do |format |
179+ format . html { render :action => "index" }
180+ format . rss {
181+ if @user && params [ :token ] . present?
182+ @title += " - Private feed for #{ @user . username } "
183+ end
184+
185+ render :action => "rss" , :layout => false
186+ }
187+ format . json { render :json => @stories }
188+ end
189+ end
190+
166191private
167192 def filtered_tag_ids
168193 if @user
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ class Story < ActiveRecord::Base
1111 has_many :comments ,
1212 :inverse_of => :story
1313 has_many :tags , :through => :taggings
14+ has_many :votes , -> { where ( :comment_id => nil ) }
15+ has_many :voters , -> { where ( 'votes.comment_id' => nil ) } ,
16+ :through => :votes ,
17+ :source => :user
1418
1519 scope :unmerged , -> { where ( :merged_story_id => nil ) }
1620
Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ class User < ActiveRecord::Base
2020 :class_name => "User"
2121 has_many :invitations
2222 has_many :weblogs
23+ has_many :votes
24+ has_many :voted_stories , -> { where ( 'votes.comment_id' => nil ) } ,
25+ :through => :votes ,
26+ :source => :story
27+ has_many :upvoted_stories ,
28+ -> { where ( 'votes.comment_id' => nil , 'votes.vote' => 1 ) } ,
29+ :through => :votes ,
30+ :source => :story
2331
2432 has_secure_password
2533
Original file line number Diff line number Diff line change 2828 get "/hidden" => "home#hidden"
2929 get "/hidden/page/:page" => "home#hidden"
3030
31+ get "/upvoted(.format)" => "home#upvoted"
32+ get "/upvoted/page/:page" => "home#upvoted"
33+
3134 get "/top" => "home#top"
3235 get "/top/page/:page" => "home#top"
3336 get "/top/:length" => "home#top"
Original file line number Diff line number Diff line change 11describe HomeController do
22 before { Rails . cache . clear }
3- before { StoriesPaginator . any_instance . should_receive ( :get ) . and_return [ scope , true ] }
3+ before {
4+ unless example . metadata [ :skip_before ]
5+ StoriesPaginator . any_instance . should_receive ( :get ) . and_return [ scope , true ]
6+ end
7+ }
48
59 describe 'GET index' do
610 let ( :scope ) { double 'Hottest Scope' }
127131 end
128132 end
129133 end
134+
135+ describe 'GET upvoted' , skip_before : true do
136+ before { get 'upvoted' }
137+ it { should redirect_to ( login_path ) }
138+ end
130139end
You can’t perform that action at this time.
0 commit comments