Show merged stories on duplicate submission
This commit is contained in:
parent
9a9362f3bb
commit
a5a41e11f1
|
@ -2,7 +2,7 @@
|
||||||
<div class="form_errors_header">
|
<div class="form_errors_header">
|
||||||
<% if story.errors.any? %>
|
<% if story.errors.any? %>
|
||||||
<%= errors_for story %>
|
<%= errors_for story %>
|
||||||
<% elsif !story.errors.any? && story.public_similar_stories(@user).any? %>
|
<% elsif !story.errors.any? && story.similar_stories.any? %>
|
||||||
<div class="flash-notice">
|
<div class="flash-notice">
|
||||||
<h2>Note: This story was already submitted <%= time_ago_in_words_label(story.most_recent_similar.created_at) %></h2>
|
<h2>Note: This story was already submitted <%= time_ago_in_words_label(story.most_recent_similar.created_at) %></h2>
|
||||||
<p>
|
<p>
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if story.public_similar_stories(@user).any? %>
|
<% if story.similar_stories.any? %>
|
||||||
<p>Previous discussions for this story:</p>
|
<p>Previous discussions for this story:</p>
|
||||||
<%= render partial: "stories/similar", locals: { similar: story.similar_stories } %>
|
<%= render partial: "stories/similar", locals: { similar: story.similar_stories } %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
<% similar.each do |story| %>
|
<% similar.each do |story| %>
|
||||||
<li>
|
<li>
|
||||||
<a href="<%= story.url %>" target="_blank"><%= story.title %></a>
|
<a href="<%= story.url %>" target="_blank"><%= story.title %></a>
|
||||||
|
<% if story.merged_story_id %>
|
||||||
|
(merged into <a href="<%= story.merged_into_story.url %>" target="_blank"><%= story.merged_into_story.title %></a>)
|
||||||
|
<% end %>
|
||||||
<%= story.user_is_author? ? "authored by" : "via" %>
|
<%= story.user_is_author? ? "authored by" : "via" %>
|
||||||
<%= styled_user_link story.user, story %>
|
<%= styled_user_link story.user, story %>
|
||||||
<%= time_ago_in_words_label(story.created_at) %>
|
<%= time_ago_in_words_label(story.created_at) %>
|
||||||
|
|
|
@ -10,6 +10,42 @@ describe "stories", type: :request do
|
||||||
describe "#check_url_dupe" do
|
describe "#check_url_dupe" do
|
||||||
before { sign_in user }
|
before { sign_in user }
|
||||||
|
|
||||||
|
context "html" do
|
||||||
|
it "returns an error when story URL is missing" do
|
||||||
|
expect {
|
||||||
|
post "/stories/check_url_dupe.html", params: {story: {url: ""}}
|
||||||
|
}.to raise_error(ActionController::ParameterMissing)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns previous discussions for an existing story" do
|
||||||
|
post "/stories/check_url_dupe.html", params: {story: {url: story.url}}
|
||||||
|
|
||||||
|
expect(response).to be_successful
|
||||||
|
|
||||||
|
expect(response.body).to include("Previous discussions for this story")
|
||||||
|
expect(response.body).to include(story.title)
|
||||||
|
expect(response.body).to include(story.url)
|
||||||
|
|
||||||
|
expect(response.body).not_to include("merged into")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns a story merged into an existing one" do
|
||||||
|
merged_story = create(:story, merged_story_id: story.id)
|
||||||
|
|
||||||
|
post "/stories/check_url_dupe.html", params: {story: {url: merged_story.url}}
|
||||||
|
|
||||||
|
expect(response).to be_successful
|
||||||
|
|
||||||
|
expect(response.body).to include("Previous discussions for this story")
|
||||||
|
expect(response.body).to include(merged_story.title)
|
||||||
|
expect(response.body).to include(merged_story.url)
|
||||||
|
|
||||||
|
expect(response.body).to include("merged into")
|
||||||
|
expect(response.body).to include(story.title)
|
||||||
|
expect(response.body).to include(story.url)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "json" do
|
context "json" do
|
||||||
it "returns similar story matching URL" do
|
it "returns similar story matching URL" do
|
||||||
post "/stories/check_url_dupe.json",
|
post "/stories/check_url_dupe.json",
|
||||||
|
|
Loading…
Reference in New Issue