fix similar story display on submit form

This commit is contained in:
Peter Bhat Harkins 2019-01-17 23:22:32 -06:00
parent 1b6a0de73d
commit 9169b04fb6
2 changed files with 14 additions and 6 deletions

View File

@ -6,7 +6,7 @@
</div>
<% elsif story.errors.any? && !story.already_posted_recently? %>
<%= error_messages_for story %>
<% elsif !story.errors.any? && story.already_posted_recently? %>
<% elsif !story.errors.any? && story.public_similar_stories.any? %>
<div class="flash-notice">
<h2>Note: This story was already submitted <%= time_ago_in_words_label(story.most_recent_similar.created_at) %>, but may be submitted again.</h2>
<p>
@ -22,10 +22,10 @@
<% end %>
<% end %>
<% end %>
</div>
<% if story.already_posted_recently? %>
<p>Previous discussions for this story:</p>
<%= render partial: "stories/similar", locals: { similar: story.similar_stories } %>
<% end %>
<% if story.public_similar_stories.any? %>
<p>Previous discussions for this story:</p>
<%= render partial: "stories/similar", locals: { similar: story.similar_stories } %>
<% end %>
</div>
</div>

View File

@ -41,4 +41,12 @@ RSpec.feature "Submitting Stories", type: :feature do
expect(page).to have_content "Error: This story was submitted"
}.not_to(change { Story.count })
end
scenario "resubmitting an old link" do
s = create(:story, created_at: (Story::RECENT_DAYS + 1).days.ago)
visit "/stories/new?url=#{s.url}"
expect(page).to have_content "may be submitted again"
expect(page).to have_content "Previous discussions"
end
end