Skip to content

Commit

Permalink
Fix bug allowing users to vote on, hide or save merged stories. (lobs…
Browse files Browse the repository at this point in the history
  • Loading branch information
4io authored and pushcx committed Oct 1, 2019
1 parent 9d9c79d commit 1a34c6e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def upvote
return render :plain => "can't find story", :status => 400
end

if story.merged_into_story
return render :plain => "story has been merged", :status => 400
end

Vote.vote_thusly_on_story_or_comment_for_user_because(
1, story.id, nil, @user.id, nil
)
Expand Down Expand Up @@ -305,6 +309,10 @@ def hide
return render :plain => "can't find story", :status => 400
end

if story.merged_into_story
return render :plain => "story has been merged", :status => 400
end

HiddenStory.hide_story_for_user(story.id, @user.id)

render :plain => "ok"
Expand All @@ -325,6 +333,10 @@ def save
return render :plain => "can't find story", :status => 400
end

if story.merged_into_story
return render :plain => "story has been merged", :status => 400
end

SavedStory.save_story_for_user(story.id, @user.id)

render :plain => "ok"
Expand Down
46 changes: 46 additions & 0 deletions spec/controllers/merge_stories_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'rails_helper'

RSpec.describe StoriesController, type: :controller do
let(:user) { create(:user) }
let(:mod) { create(:user, :moderator) }
let(:merged_story) { create(:story) }
let(:story) { create(:story) }

describe 'merged stories do' do
context 'user votes on merged story' do
before {
stub_login_as user
stub_login_as mod
post :update, params: {
id: merged_story.short_id,
story: {
merge_story_short_id: story.short_id,
moderation_reason: 'cuz',
},
}
}

it "does nothing when upvoting merged story" do
post :upvote, params: { story_id: merged_story.short_id }

merged_story.reload
expect(merged_story.merged_into_story).to eq story
expect(merged_story.upvotes).to eq(1)
end

it "has no effect when hiding merged story" do
post :hide, params: { story_id: merged_story.short_id }

merged_story.reload
expect(merged_story.hider_count).to eq(0)
end

it "has no effect when saving merged story" do
post :save, params: { story_id: merged_story.short_id }

merged_story.reload
expect(merged_story.savings.count).to eq(0)
end
end
end
end

0 comments on commit 1a34c6e

Please sign in to comment.