Merge pull request #163 from walle/upvoted_fix
add /upvoted page to show a logged-in user's upvoted stories
This commit is contained in:
commit
e3f6a4edd8
|
@ -2,6 +2,7 @@ class HomeController < ApplicationController
|
|||
# for rss feeds, load the user's tag filters if a token is passed
|
||||
before_filter :find_user_from_rss_token, :only => [ :index, :newest ]
|
||||
before_filter { @page = page }
|
||||
before_filter :require_logged_in_user, :only => [:upvoted]
|
||||
|
||||
def about
|
||||
begin
|
||||
|
@ -163,6 +164,30 @@ class HomeController < ApplicationController
|
|||
render :action => "index"
|
||||
end
|
||||
|
||||
def upvoted
|
||||
@stories, @show_more = get_from_cache(upvoted: true, user: @user) {
|
||||
paginate @user.upvoted_stories.order('votes.id DESC')
|
||||
}
|
||||
|
||||
@heading = @title = "Upvoted"
|
||||
@cur_url = "/upvoted"
|
||||
|
||||
@rss_link = { :title => "RSS 2.0 - Upvoted Items",
|
||||
:href => "/upvoted.rss#{(@user ? "?token=#{@user.rss_token}" : "")}" }
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :action => "index" }
|
||||
format.rss {
|
||||
if @user && params[:token].present?
|
||||
@title += " - Private feed for #{@user.username}"
|
||||
end
|
||||
|
||||
render :action => "rss", :layout => false
|
||||
}
|
||||
format.json { render :json => @stories }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def filtered_tag_ids
|
||||
if @user
|
||||
|
|
|
@ -11,6 +11,10 @@ class Story < ActiveRecord::Base
|
|||
has_many :comments,
|
||||
:inverse_of => :story
|
||||
has_many :tags, :through => :taggings
|
||||
has_many :votes, -> { where(:comment_id => nil) }
|
||||
has_many :voters, -> { where('votes.comment_id' => nil) },
|
||||
:through => :votes,
|
||||
:source => :user
|
||||
|
||||
scope :unmerged, -> { where(:merged_story_id => nil) }
|
||||
|
||||
|
|
|
@ -20,6 +20,14 @@ class User < ActiveRecord::Base
|
|||
:class_name => "User"
|
||||
has_many :invitations
|
||||
has_many :weblogs
|
||||
has_many :votes
|
||||
has_many :voted_stories, -> { where('votes.comment_id' => nil) },
|
||||
:through => :votes,
|
||||
:source => :story
|
||||
has_many :upvoted_stories,
|
||||
-> { where('votes.comment_id' => nil, 'votes.vote' => 1) },
|
||||
:through => :votes,
|
||||
:source => :story
|
||||
|
||||
has_secure_password
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ Lobsters::Application.routes.draw do
|
|||
get "/hidden" => "home#hidden"
|
||||
get "/hidden/page/:page" => "home#hidden"
|
||||
|
||||
get "/upvoted(.format)" => "home#upvoted"
|
||||
get "/upvoted/page/:page" => "home#upvoted"
|
||||
|
||||
get "/top" => "home#top"
|
||||
get "/top/page/:page" => "home#top"
|
||||
get "/top/:length" => "home#top"
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
describe HomeController do
|
||||
before { Rails.cache.clear }
|
||||
before { StoriesPaginator.any_instance.should_receive(:get).and_return [scope, true] }
|
||||
before {
|
||||
unless example.metadata[:skip_before]
|
||||
StoriesPaginator.any_instance.should_receive(:get).and_return [scope, true]
|
||||
end
|
||||
}
|
||||
|
||||
describe 'GET index' do
|
||||
let(:scope) { double 'Hottest Scope' }
|
||||
|
@ -127,4 +131,9 @@ describe HomeController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'GET upvoted', skip_before: true do
|
||||
before { get 'upvoted' }
|
||||
it { should redirect_to(login_path) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue