Skip to content

Commit

Permalink
adds save search to results collection
Browse files Browse the repository at this point in the history
  • Loading branch information
mejackreed committed May 28, 2015
1 parent b05cba1 commit 3444587
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/stylesheets/blacklight/_blacklight_base.scss
Expand Up @@ -16,3 +16,4 @@
@import "blacklight/facets";
@import "blacklight/search_history";
@import "blacklight/modal";
@import 'blacklight/results';
10 changes: 10 additions & 0 deletions app/assets/stylesheets/blacklight/_results.scss
@@ -0,0 +1,10 @@
.search-widgets {
.form-inline {
display: inline;
position: relative;

div {
display: inline;
}
}
}
8 changes: 8 additions & 0 deletions app/views/catalog/_save_search.html.erb
@@ -0,0 +1,8 @@
<% search ||= @current_search_session %>
<% if search %>
<% if current_or_guest_user && search.saved? %>
<%= button_to t('blacklight.search_history.forget'), forget_search_path(search.id), class: 'btn btn-default', form_class: 'form-inline' %>
<% else %>
<%= button_to t('blacklight.search_history.save'), save_search_path(search.id), method: :put, :class => 'btn btn-default', form_class: 'form-inline' %>
<% end %>
<% end %>
3 changes: 3 additions & 0 deletions lib/generators/blacklight/templates/catalog_controller.rb
Expand Up @@ -176,6 +176,9 @@ class <%= controller_name.classify %>Controller < ApplicationController
# If there are more than this many search results, no spelling ("did you
# mean") suggestion is offered.
config.spell_max = 5

# Add the save search tool to a results collection
config.add_results_collection_tool :save_search
end

end
14 changes: 13 additions & 1 deletion spec/features/saved_searches_spec.rb
Expand Up @@ -10,6 +10,18 @@
click_link 'Saved Searches'
expect(page).to have_content 'You have no saved searches'
end

it 'can be saved and forgotten from a search result' do
visit catalog_index_path(q: 'book')
within '.search-widgets' do
click_button 'save'
end
expect(page).to have_content 'Successfully saved your search.'
within '.search-widgets' do
click_button 'forget'
end
expect(page).to have_content 'Successfully removed that saved search.'
end

describe "with a saved search 'book'" do
before do
Expand Down Expand Up @@ -37,7 +49,7 @@
click_button "save"
click_link 'Saved Searches'
end
it "should clear the searhes" do
it "should clear the searches" do
click_link "Clear Saved Searches"
expect(page).to have_content 'Cleared your saved searches.'
expect(page).to have_content 'You have no saved searches'
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Expand Up @@ -55,5 +55,6 @@
config.use_transactional_fixtures = true

config.include Devise::TestHelpers, type: :controller
config.include Devise::TestHelpers, type: :view
config.infer_spec_type_from_file_location!
end
43 changes: 43 additions & 0 deletions spec/views/catalog/_save_search.html.erb_spec.rb
@@ -0,0 +1,43 @@
require 'spec_helper'

describe "/catalog/_save_search.html.erb" do
describe 'a current user' do
before do
sign_in 'user1'
end
describe ' and a saved search' do
it 'renders a forget button' do
assign(:current_search_session, double('saved?' => true, id: 1))
render
within 'form[action="/saved_searches/forget/1"]' do
expect(rendered).to have_css 'input[value="forget"]'
end
end
end
describe ' and a search that is not saved' do
it 'renders a save button' do
assign(:current_search_session, double('saved?' => false, id: 1))
render
within 'form[action="/saved_searches/save/1"]' do
expect(rendered).to have_css 'input[value="save"]'
end
end
end
end
describe 'no current user and search that is not saved' do
it 'renders a save button' do
assign(:current_search_session, double('saved?' => false, id: 1))
render
within 'form[action="/saved_searches/save/1"]' do
expect(rendered).to have_css 'input[value="save"]'
end
end
end
describe 'no current search' do
it 'renders nothing' do
assign(:current_search_session, false)
render
expect(rendered).to_not have_css 'form'
end
end
end

0 comments on commit 3444587

Please sign in to comment.