require 'spec_helper' describe CatalogController do before do session[:user]='bob' end it "should use CatalogController" do expect(controller).to be_an_instance_of CatalogController end describe "configuration" do let(:config) { CatalogController.blacklight_config } describe "search_builder_class" do subject {config.search_builder_class } it { is_expected.to eq Hydra::SearchBuilder } end end describe "Paths Generated by Custom Routes:" do # paths generated by custom routes it "should map {:controller=>'catalog', :action=>'index'} to GET /catalog" do expect(get: "/catalog").to route_to(controller: 'catalog', action: 'index') end it "should map {:controller=>'catalog', :action=>'show', :id=>'test:3'} to GET /catalog/test:3" do expect(get: "/catalog/test:3").to route_to(controller: 'catalog', action: 'show', id: 'test:3') end it "should map catalog_path" do expect(catalog_path("test:3")).to eq '/catalog/test:3' end end describe "index" do describe "access controls" do before(:all) do fq = "read_access_group_ssim:public OR edit_access_group_ssim:public OR discover_access_group_ssim:public" solr_opts = { fq: fq } response = ActiveFedora::SolrService.instance.conn.get('select', params: solr_opts) @public_only_results = Blacklight::SolrResponse.new(response, solr_opts) end it "should only return public documents if role does not have permissions" do allow(controller).to receive(:current_user).and_return(nil) get :index expect(assigns(:document_list).count).to eq @public_only_results.docs.count end it "should return documents if the group names need to be escaped" do allow(RoleMapper).to receive(:roles).and_return(["abc/123","cde/567"]) get :index expect(assigns(:document_list).count).to eq @public_only_results.docs.count end end end describe "filters" do describe "show" do it "should trigger enforce_show_permissions" do allow(controller).to receive(:current_user).and_return(nil) expect(controller).to receive(:enforce_show_permissions) get :show, id: 'test:3' end end end end