Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain Context in Sets Pages #153

Merged
merged 6 commits into from
Jun 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class CatalogController < ApplicationController
self.search_params_logic += [:add_access_controls_to_solr_params]

def blacklight_config
@blacklight_config ||= BlacklightConfig.new(GenericAsset, self.class.blacklight_config).configuration
@blacklight_config ||= config_builder.configuration
end

def config_builder
@config_builder ||= BlacklightConfig.new(GenericAsset, self.class.blacklight_config)
end
end
6 changes: 6 additions & 0 deletions app/controllers/sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def find_set(set_id)
GenericSet.load_instance_from_solr(set_id)
end

def config_builder
@set_config ||= super.tap do |t|
t.set = find_set(params[:set_id])
end
end

def set_not_found
flash[:error] = t("sets.set_not_found")
redirect_to root_path
Expand Down
7 changes: 6 additions & 1 deletion app/models/blacklight_config.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
class BlacklightConfig
attr_reader :metadata_class, :default_configuration
attr_reader :metadata_class, :default_configuration, :set
def initialize(metadata_class, default_configuration)
@metadata_class = metadata_class
@default_configuration = default_configuration
apply_configurations
end

def set=(set)
@set = set
ApplySet.new(configuration, set).run
end

def configuration
@configuration ||= default_configuration.deep_copy
end
Expand Down
15 changes: 15 additions & 0 deletions app/models/blacklight_config/apply_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BlacklightConfig
class ApplySet
pattr_initialize :configuration, :set

def run
update_show_route
end

private

def update_show_route
configuration.show.route = {:controller => "sets", :set_id => set.id.to_s}
end
end
end
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
resources :resource, :only => :show
mount HydraEditor::Engine => '/'

get 'sets/:set_id', :to => "sets#index"
get 'sets/:set_id', :to => "sets#index", :as => :sets_index
get 'sets/:set_id/:id', :to => "sets#show", :as => :sets
get 'sets/:set_id/facet/:id', :to => "sets#facet"
[:email, :sms, :citation].each do |export_type|
get "sets/:set_id/#{export_type}", :to => "sets##{export_type}", :as => :"#{export_type}_sets"
end
end
12 changes: 12 additions & 0 deletions spec/controllers/sets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
end
end

describe "#blacklight_config" do
it "should have a set configured" do
set = instance_double(GenericSet, :id => "test")
allow(GenericSet).to receive(:load_instance_from_solr).and_return(
set
)
# Set expectation.
expect_any_instance_of(BlacklightConfig).to receive(:set=).with(set).and_call_original
visit_set_index(set: set)
end
end

def visit_set_index(set:)
get :index, :set_id => set.id
end
Expand Down
12 changes: 12 additions & 0 deletions spec/features/sets_show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'rails_helper'

RSpec.describe "Sets show page" do
it "should be able to display an asset" do
set = GenericSet.create(:read_groups => ["public"])
asset = GenericAsset.create(:title => ["Test Title"], :read_groups => ["public"], :set => [set])

visit sets_path(:id => asset.id, :set_id => set.id)

expect(page).to have_content(asset.title.first)
end
end
9 changes: 9 additions & 0 deletions spec/models/blacklight_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
end
end

describe "#set=" do
let(:set) { instance_double(GenericSet, :id => "myset") }
it "should set a show route" do
subject.set = set

expect(subject.configuration.show.route).to eq({:controller => "sets", :set_id => "myset"})
end
end


describe "#configuration" do
subject { BlacklightConfig.new(resource, default_config).configuration }
Expand Down
39 changes: 39 additions & 0 deletions spec/views/catalog/_index_header_default.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require 'rails_helper'

RSpec.describe "catalog/_index_header_default" do
let :document do
SolrDocument.new :id => 'xyz', :format => 'a'
end

let :blacklight_config do
BlacklightConfig.new(GenericAsset, CatalogController.blacklight_config).tap do |c|
c.set = set
end.configuration
end

let(:set) do
instance_double(GenericSet, :id => "myset")
end

before do
assign :response, double(start: 0)
assign(:set, set)
stub_helper_methods
stub_blacklight_config(config: blacklight_config)
render :partial => "catalog/index_header_default", :locals => {:document => document, :document_counter => 1}
end
it "should display a link, but stay in the sets path" do
expect(rendered).to have_link document.id, :href => sets_path(:id => document.id, :set_id => set.id)
end

def stub_blacklight_config(config:)
allow(view).to receive(:blacklight_config).and_return(config)
end

def stub_helper_methods
allow(view).to receive(:render_grouped_response?).and_return false
allow(view).to receive(:current_search_session).and_return nil
allow(view).to receive(:search_session).and_return({})
allow(view).to receive(:render_index_doc_actions)
end
end