Skip to content

Commit

Permalink
Fix atom feed for paper search results page
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Jul 16, 2023
1 parent ddd0430 commit 0a7a585
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/views/content/layout/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<%= link_to image_tag("rss-sm.svg"), "#", class: "dropdown-toggle", size: "48", id: "dropdownMenuLink",
"data-toggle": "dropdown", "aria-haspopup": "true", "aria-expanded": "false" %>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownMenuLink">
<%= link_to "This Search", url_for(format: :atom), class: "dropdown-item" if @filtering %>
<%= link_to "This Search", url_for(q: params[:q].presence, format: :atom), class: "dropdown-item" if @filtering %>
<%= link_to "Active Papers", active_papers_path(format: :atom), class: "dropdown-item" %>
<%= link_to "Published Papers", published_papers_path(format: :atom), class: "dropdown-item" %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/papers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<%- placeholder_text = params[:q].nil? ? "Search by title, tag, author, or language":params[:q]%>
<%= f.text_field :q, placeholder:placeholder_text , class: "form-control", size: "35" %>
<div class="input-group-append">
<%= button_tag(type: 'submit', class: "btn btn-outline-secondary", name: "") do %>
<%= button_tag(type: 'submit', class: "btn btn-outline-secondary", name: "search_button") do %>
<%= octicon "search" %>
<% end %>
</div>
Expand Down
3 changes: 0 additions & 3 deletions spec/controllers/papers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@
expect(response.status).to eq(200)
end
end



end

describe "Paper lookup" do
Expand Down
75 changes: 75 additions & 0 deletions spec/system/papers/search_papers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require "rails_helper"

feature "Paper search" do
before do
paper_1 = create(:accepted_paper, title: "Astronomy paper")
paper_1.metadata['paper']['title'] = "Astronomy paper"
paper_1.metadata['paper']['authors'] = [{'given_name' => "Vera", 'last_name' => "Rubin"}]
paper_1.metadata['paper']['tags'] = ["Galaxy rotation curves"]
paper_1.save!

paper_2 = create(:accepted_paper, title: "Biodiversity study")
paper_2.metadata['paper']['title'] = "Biodiversity study"
paper_2.metadata['paper']['authors'] = [{'given_name' => "Jane", 'last_name' => "Goodall"}]
paper_2.metadata['paper']['tags'] = ["Wild chimpanzees"]
paper_2.save!

Paper.reindex
end

scenario "by title" do
visit published_papers_path
fill_in :q, with: "Astronomy"
click_button "search_button"

expect(page).to have_content("Astronomy paper")
expect(page).to_not have_content("Biodiversity")

fill_in :q, with: "Biodiversity"
click_button "search_button"

expect(page).to_not have_content("Astronomy")
expect(page).to have_content("Biodiversity study")
end

scenario "by author" do
visit published_papers_path
fill_in :q, with: "Vera Rubin"
click_button "search_button"

expect(page).to have_content("Astronomy paper")
expect(page).to_not have_content("Biodiversity")

fill_in :q, with: "Jane Goodall"
click_button "search_button"

expect(page).to_not have_content("Astronomy paper")
expect(page).to have_content("Biodiversity")
end

scenario "by tag" do
visit published_papers_path
fill_in :q, with: "rotation curves"
click_button "search_button"

expect(page).to have_content("Astronomy paper")
expect(page).to_not have_content("Biodiversity")

fill_in :q, with: "chimpanzees"
click_button "search_button"

expect(page).to_not have_content("Astronomy paper")
expect(page).to have_content("Biodiversity")
end

feature "Atom feed" do
scenario "keeps the query param" do
visit search_papers_path(q: "Vera Rubin")
click_link "This Search"

expect(page).to have_current_path(search_papers_path(q: "Vera Rubin", format: :atom))
expect(page).to have_content("Astronomy")
expect(page).to_not have_content("Biodiversity study")
end
end
end

0 comments on commit 0a7a585

Please sign in to comment.