Skip to content

Commit

Permalink
tests for story merging
Browse files Browse the repository at this point in the history
  • Loading branch information
pushcx committed Jul 17, 2019
1 parent 4d377e9 commit 6c4bc0b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 8 deletions.
3 changes: 1 addition & 2 deletions app/views/stories/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
</div>
<% if @story.user_id != @user.id %>
<div class="boxline">
<%= f.label :moderation_reason, "Mod Reason:",
:class => "required" %>
<%= f.label :moderation_reason, "Mod Reason:", :class => "required" %>
<%= f.text_field :moderation_reason %>
</div>
<% end %>
Expand Down
49 changes: 43 additions & 6 deletions spec/controllers/stories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

describe StoriesController do
let(:user) { create(:user) }

before do
stub_login_as user
end
let(:story) { create(:story, user: user) }
let(:mod) { create(:user, :moderator) }

describe "#check_url_dupe" do
let(:story) { create(:story, user: user) }
before { stub_login_as user }

context "json" do
it "returns similar story matching URL" do
Expand Down Expand Up @@ -74,7 +72,7 @@
end

describe "#delete" do
let(:story) { create(:story, user: user) }
before { stub_login_as user }

it "increments the user's count of deleted stories" do
expect {
Expand All @@ -84,6 +82,7 @@
end

describe "#undelete" do
before { stub_login_as user }
let(:deleted_story) { create(:story, :deleted, user: user) }

it "decrements the user's count of deleted stories" do
Expand All @@ -92,4 +91,42 @@
end.to change { user.stories_deleted_count }.by(-1)
end
end

describe "merged stories" do
it "can be merged by mod" do
stub_login_as mod
s = create(:story)
post :update, params: {
id: s.short_id,
story: {
merge_story_short_id: story.short_id,
moderation_reason: 'cuz',
},
}
expect(response).to be_redirect

s.reload
expect(s.merged_into_story).to eq(story)

ml = Moderation.last
expect(ml.story).to eq(s)
expect(ml.reason).to eq('cuz')
end

it "can't be done by submitter" do
stub_login_as user

s = create(:story)
post :update, params: {
id: s.short_id,
story: {
merge_story_short_id: story.short_id,
moderation_reason: 'anarchy!',
},
}
expect(response).to be_redirect
s.reload
expect(s.merged_into_story).to be_nil
end
end
end
29 changes: 29 additions & 0 deletions spec/features/read_story_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,33 @@
expect(page).to have_content("New reply")
end
end

feature "reading merged stories" do
let!(:merged) { create(:story, merged_into_story: story) }

it "redirects links" do
visit merged.comments_path
expect(page.current_path).to eq(story.comments_path)
end

it "shows merged story at the top" do
visit story.comments_path
expect(page).to have_content(merged.title)
end

it "shows comments from merged_into story" do
visit story.comments_path
expect(page).to have_content(comment.comment)
end

it "shows comments from merged story" do
merged_comment = create(:comment, story: merged)
merged_reply = create(:comment, story: merged, parent_comment: merged_comment)
visit story.comments_path

expect(page).to have_content(merged_comment.comment)
expect(page).to have_content(merged_reply.comment)
expect(page).to have_selector('span.merge')
end
end
end

0 comments on commit 6c4bc0b

Please sign in to comment.