Skip to content

Commit

Permalink
Move general purpose models from ./app/models to ./lib to make them a…
Browse files Browse the repository at this point in the history
…vailable outside the Rails autoloading context
  • Loading branch information
cbeer committed Nov 6, 2015
1 parent f553899 commit 6212647
Show file tree
Hide file tree
Showing 27 changed files with 24 additions and 25 deletions.
7 changes: 0 additions & 7 deletions app/models/blacklight/solr/search_builder.rb

This file was deleted.

6 changes: 5 additions & 1 deletion lib/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
require 'blacklight/utils'

module Blacklight
autoload :AbstractRepository, 'blacklight/abstract_repository'
autoload :Configuration, 'blacklight/configuration'
autoload :Exceptions, 'blacklight/exceptions'
autoload :SearchState, 'blacklight/search_state'
autoload :Parameters, 'blacklight/parameters'
autoload :Routes, 'blacklight/routes'
autoload :SearchBuilder, 'blacklight/search_builder'
autoload :SearchState, 'blacklight/search_state'
autoload :Solr, 'blacklight/solr'

extend Deprecation

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Configuration < OpenStructWithHashAccess
# Using required_dependency to work around Rails autoloading
# problems when developing blacklight. Without this, any change
# to this class breaks other classes in this namespace


require_dependency 'blacklight/configuration/context'
require_dependency 'blacklight/configuration/view_config'
require_dependency 'blacklight/configuration/tool_config'
# XXX this isn't very pretty, but it works.
Expand Down Expand Up @@ -211,14 +212,6 @@ def search_builder_class

def locate_search_builder_class
::SearchBuilder
rescue NameError => e
# If the NameError is a result of the SearchBuilder having a
# NameError (e.g. NoMethodError) within it then raise the error.
raise e if Object.const_defined? "::SearchBuilder"

# Otherwise the NameError was a result of not being able to find SearchBuilder
Deprecation.warn(Configuration, "Your application is missing the SearchBuilder. Have you run `rails generate blacklight:search_builder`? Falling back to Blacklight::Solr::SearchBuilder")
Blacklight::Solr::SearchBuilder
end

def facet_paginator_class
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion lib/blacklight/solr.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Blacklight
module Solr
autoload :Repository, 'blacklight/solr/repository'
autoload :Request, 'blacklight/solr/request'
autoload :Response, 'blacklight/solr/response'
autoload :SearchBuilderBehavior, 'blacklight/solr/search_builder_behavior'
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 12 additions & 7 deletions spec/models/blacklight/solr/search_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Blacklight::Solr::SearchBuilder do
describe Blacklight::Solr::SearchBuilderBehavior do
let(:single_facet) { { format: 'Book' } }
let(:multi_facets) { { format: 'Book', language_facet: 'Tibetan' } }
let(:mult_word_query) { 'tibetan history' }
Expand All @@ -12,26 +12,31 @@

before { allow(context).to receive(:blacklight_config).and_return(blacklight_config) }

let(:search_builder) { described_class.new(context) }
let(:search_builder_class) do
Class.new(Blacklight::SearchBuilder) do
include Blacklight::Solr::SearchBuilderBehavior
end
end
let(:search_builder) { search_builder_class.new(context) }

subject { search_builder.with(user_params) }

context "with default processor chain" do
context "with two arguments" do
subject do
Deprecation.silence Blacklight::SearchBuilder do
described_class.new true, context
search_builder_class.new true, context
end
end
it "uses the class-level default_processor_chain" do
expect(subject.processor_chain).to eq described_class.default_processor_chain
expect(subject.processor_chain).to eq search_builder_class.default_processor_chain
end
end

context "with one arguments" do
subject { described_class.new context }
subject { search_builder }
it "uses the class-level default_processor_chain" do
expect(subject.processor_chain).to eq described_class.default_processor_chain
expect(subject.processor_chain).to eq search_builder_class.default_processor_chain
end
end
end
Expand Down Expand Up @@ -90,7 +95,7 @@
end

context "when search_params_logic is customized" do
let(:search_builder) { described_class.new(method_chain, context) }
let(:search_builder) { search_builder_class.new(method_chain, context) }
let(:method_chain) { [:add_foo_to_solr_params] }

it "allows customization of search_params_logic" do
Expand Down

0 comments on commit 6212647

Please sign in to comment.