View
@@ -1,19 +1,15 @@
<li id="story_<%= story.short_id %>" data-shortid="<%= story.short_id %>"
class="story <%= story.vote == 1 ? "upvoted" : (story.vote == -1 ?
"downvoted" : "") %> <%= story.is_expired? ? "expired" : "" %>">
class="story <%= story.vote == 1 ? "upvoted" : "" %> <%= story.vote == -1 ?
"downvoted" : "" %> <%= story.vote == 0 ? "hidden" : "" %> <%= story.is_expired? ?
"expired" : "" %>">
<div class="story_liner">
<div class="voters">
<% if @user %>
<a class="upvoter"></a>
<% else %>
<%= link_to "", login_url, :class => "upvoter" %>
<% end %>
<div class="score"><%= story.upvotes - story.downvotes %></div>
<% if @user && @user.can_downvote?(story) %>
<a class="downvoter"></a>
<% else %>
<span class="downvoter downvoter_stub"></span>
<% end %>
<div class="score"><%= story.score %></div>
</div>
<div class="details">
<span class="link">
@@ -67,6 +63,15 @@ class="story <%= story.vote == 1 ? "upvoted" : (story.vote == -1 ?
<% end %>
<% end %>
<% end %>
<% if !story.is_gone? && @user %>
<% if story.vote == 0 %>
| <%= link_to "unhide", story_unhide_url(story.short_id),
:class => "hider" %>
<% else %>
| <%= link_to "hide", story_hide_url(story.short_id),
:class => "hider" %>
<% end %>
<% end %>
<% if !story.is_gone? && (@user || story.comments_count > 0) %>
<span class="comments_label">
|
@@ -75,12 +80,6 @@ class="story <%= story.vote == 1 ? "upvoted" : (story.vote == -1 ?
(story.comments_count == 1 ? "" : "s") %></a>
</span>
<% end %>
<% if defined?(single_story) && single_story %>
<% if story.downvotes > 0 %>
| <%= story.vote_summary_for(@user).downcase %>
<% end %>
<% end %>
<% end %>
</div>
</div>
View
@@ -14,6 +14,8 @@
get "/newest/:user/page/:page" => "home#newest_by_user"
get "/recent" => "home#recent"
get "/recent/page/:page" => "home#recent"
get "/hidden" => "home#hidden"
get "/hidden/page/:page" => "home#hidden"
get "/threads" => "comments#threads"
get "/threads/:user" => "comments#threads"
@@ -40,9 +42,10 @@
resources :stories do
post "upvote"
post "downvote"
post "unvote"
post "undelete"
post "hide"
post "unhide"
end
post "/stories/fetch_url_title", :format => "json"
post "/stories/preview" => "stories#preview"
View
@@ -0,0 +1,98 @@
require "spec_helper"
describe Vote do
it "applies a story upvote and karma properly" do
s = Story.make!
s.upvotes.should == 1
s.downvotes.should == 0
s.user.karma.should == 0
u = User.make!
Vote.vote_thusly_on_story_or_comment_for_user_because(1, s.id,
nil, u.id, nil)
s.reload
s.upvotes.should == 2
s.user.karma.should == 1
end
it "does nothing when upvoting an existing upvote" do
s = Story.make!
u = User.make!
2.times do
Vote.vote_thusly_on_story_or_comment_for_user_because(1, s.id,
nil, u.id, nil)
s.reload
s.upvotes.should == 2
s.user.karma.should == 1
end
end
it "has no effect on a story score when casting a hide vote" do
s = Story.make!
s.upvotes.should == 1
u = User.make!
Vote.vote_thusly_on_story_or_comment_for_user_because(0, s.id,
nil, u.id, "H")
s.reload
s.user.karma.should == 0
s.upvotes.should == 1
s.downvotes.should == 0
end
it "removes karma and upvote when downvoting an upvote" do
s = Story.make!
c = Comment.make!(:story_id => s.id)
c.user.karma.should == 0
u = User.make!
Vote.vote_thusly_on_story_or_comment_for_user_because(1, s.id,
c.id, u.id, nil)
c.reload
c.user.karma.should == 1
# initial poster upvote plus new user's vote
c.upvotes.should == 2
c.downvotes.should == 0
# flip vote
Vote.vote_thusly_on_story_or_comment_for_user_because(-1, s.id,
c.id, u.id, Vote::COMMENT_REASONS.keys.first)
c.reload
c.user.karma.should == -1
c.upvotes.should == 1
c.downvotes.should == 1
end
it "neutralizes karma and upvote when unvoting an upvote" do
s = Story.make!
c = Comment.make!(:story_id => s.id)
u = User.make!
Vote.vote_thusly_on_story_or_comment_for_user_because(1, s.id,
c.id, u.id, nil)
c.reload
c.user.karma.should == 1
c.upvotes.should == 2
c.downvotes.should == 0
Vote.vote_thusly_on_story_or_comment_for_user_because(0, s.id,
c.id, u.id, nil)
c.reload
c.user.karma.should == 0
c.upvotes.should == 1
c.downvotes.should == 0
end
end