Skip to content

Commit

Permalink
Merge pull request #1918 from projectblacklight/expand-api-tests
Browse files Browse the repository at this point in the history
Add more tests to the API suite
  • Loading branch information
mjgiarlo committed Jun 29, 2018
2 parents c100a3f + c739da9 commit f4090f5
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 80 deletions.
2 changes: 1 addition & 1 deletion spec/models/blacklight/configurable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe "Blacklight::Configurable" do
RSpec.describe "Blacklight::Configurable", api: true do

describe "inheritence" do
before(:all) do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/configuration/context_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Configuration::Context do
RSpec.describe Blacklight::Configuration::Context, api: true do

subject { described_class.new(context) }
let(:context) { double }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe "Blacklight::Configuration" do
RSpec.describe "Blacklight::Configuration", api: true do

let(:config) do
Blacklight::Configuration.new
Expand Down
4 changes: 2 additions & 2 deletions spec/models/blacklight/document/active_model_shim_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe 'Blacklight::Document::ActiveModelShim' do
RSpec.describe 'Blacklight::Document::ActiveModelShim', api: true do

class MockDocument
include Blacklight::Document
Expand All @@ -23,7 +23,7 @@ def documents
before do
allow(MockDocument).to receive(:repository).and_return(double(find: MockResponse.new([{id: 1}], {})))
end

describe "#find" do
it "should return a document from the repository" do
expect(MockDocument.find(1)).to be_a MockDocument
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/document/cache_key_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Document::CacheKey do
RSpec.describe Blacklight::Document::CacheKey, api: true do
let(:attributes) { {} }
let(:subject) { SolrDocument.new(attributes) }
it 'SolrDocument includes the module' do
Expand Down
6 changes: 3 additions & 3 deletions spec/models/blacklight/document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Document do
RSpec.describe Blacklight::Document, api: true do
let(:data) { {} }
subject do
Class.new do
Expand All @@ -14,7 +14,7 @@
data[:x] = true
expect(subject).to have_field(:x)
end

it "does not have the field if the field is not in the data" do
expect(subject).not_to have_field(:x)
end
Expand All @@ -25,7 +25,7 @@
data[:x] = true
expect(subject).to have_field(:x, true)
end

it "does not have the field if the data does not have that value" do
data[:x] = false
expect(subject).not_to have_field(:x, true)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/facet_paginator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::FacetPaginator do
RSpec.describe Blacklight::FacetPaginator, api: true do

let(:f1) { Blacklight::Solr::Response::Facets::FacetItem.new(hits: '792', value: 'Book') }
let(:f2) { Blacklight::Solr::Response::Facets::FacetItem.new(hits: '65', value: 'Musical Score') }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/search_builder_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::SearchBuilder do
RSpec.describe Blacklight::SearchBuilder, api: true do
let(:processor_chain) { [] }
let(:blacklight_config) { Blacklight::Configuration.new }
let(:scope) { double blacklight_config: blacklight_config }
Expand Down
42 changes: 21 additions & 21 deletions spec/models/blacklight/solr/document_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe "Blacklight::Solr::Document" do
RSpec.describe "Blacklight::Solr::Document", api: true do
class MockDocument
include Blacklight::Solr::Document
end
Expand Down Expand Up @@ -33,7 +33,7 @@ def my_extension_method
end
end


context "Unique Key" do
before(:each) do
MockDocument.unique_key = 'my_unique_key'
Expand Down Expand Up @@ -73,7 +73,7 @@ def my_extension_method
#Clear extensions
MockDocument.registered_extensions = []
end

it "should let you register an extension" do
MockDocument.use_extension(MockExtension) { |doc| true }

Expand All @@ -98,35 +98,35 @@ def my_extension_method

without_extension = MockDocument.new(:other_key => "value")
expect(without_extension.methods.find {|name| name.to_s == "my_extension_method"}).to be_nil

end
it "should not apply an extension whose condition is not met" do
MockDocument.use_extension(MockExtension) {|doc| false}
doc = MockDocument.new()
expect(doc.methods.find {|name| name.to_s == "my_extension_method"}).to be_nil

expect(doc.methods.find {|name| name.to_s == "my_extension_method"}).to be_nil
end
it "should treat a nil condition as always applyable" do
MockDocument.use_extension(MockExtension)

doc = MockDocument.new()

expect(doc.methods.find {|name | name.to_s =="my_extension_method"}).not_to be_nil
expect(doc.my_extension_method).to eq "my_extension_results"
end
it "should let last extension applied override earlier extensions" do
MockDocument.use_extension(MockExtension)
MockDocument.use_extension(MockSecondExtension)

expect(MockDocument.new().my_extension_method.to_s).to eq "override"
expect(MockDocument.new().my_extension_method.to_s).to eq "override"
end

describe "extension_parameters class-level hash" do
it "should provide an extension_parameters hash at the class level" do
MockDocument.extension_parameters[:key] = "value"
expect(MockDocument.extension_parameters[:key]).to eq "value"
end

it "extension_parameters should not be shared between classes" do
class_one = Class.new do
include Blacklight::Solr::Document
Expand All @@ -141,7 +141,7 @@ def my_extension_method
expect(class_one.extension_parameters[:key]).to eq "class_one_value"
end
end

end

context "Will export as" do
Expand All @@ -163,15 +163,15 @@ def export_as_marc
it "looks up content-type from Mime::Type if not given in arg" do
doc = MockDocument.new
doc.will_export_as(:html)
expect(doc.export_formats).to have_key(:html)
expect(doc.export_formats).to have_key(:html)
end

context "format not registered with Mime::Type" do
before(:all) do
@doc = MockDocument.new
@doc.will_export_as(:mock2, "application/mock2" )
# Mime::Type doesn't give us a good way to clean up our new
# registration in an after, sorry.
# registration in an after, sorry.
end
it "registers format" do
expect(defined?("Mime::MOCK2")).to be_truthy
Expand All @@ -186,7 +186,7 @@ def export_as_marc
doc.will_export_as(:marc, "application/marc")
expect(doc.export_as(:marc)).to eq "fake_marc"
end

it "should know if a document is exportable" do
doc = MockDocument.new
doc.will_export_as(:marc, "application/marc")
Expand All @@ -196,7 +196,7 @@ def export_as_marc

context "to_semantic_fields" do
class MockDocument
include Blacklight::Solr::Document
include Blacklight::Solr::Document
end
before do
MockDocument.field_semantics.merge!(
Expand All @@ -205,18 +205,18 @@ class MockDocument
something: "something_field"
)

@doc1 = MockDocument.new(
@doc1 = MockDocument.new(
"title_field" => "doc1 title",
"other_title" => "doc1 title other",
"something_field" => ["val1", "val2"],
"not_in_list_field" => "weird stuff"
"not_in_list_field" => "weird stuff"
)
end

it "should return complete dictionary based on config'd fields" do
it "should return complete dictionary based on config'd fields" do
expect(@doc1.to_semantic_values)
.to eq title: ["doc1 title", "doc1 title other"], something: ["val1", "val2"]
end
end
it "should return empty array for a key without a value" do
expect(@doc1.to_semantic_values[:author]).to be_empty
expect(@doc1.to_semantic_values[:nonexistent_token]).to be_empty
Expand All @@ -225,9 +225,9 @@ class MockDocument
expect(@doc1.to_semantic_values[:title]).to be_kind_of(Array)
end
it "should return complete array for a multi-value field" do
expect(@doc1.to_semantic_values[:something]).to eq ["val1", "val2"]
expect(@doc1.to_semantic_values[:something]).to eq ["val1", "val2"]
end

end

context "highlighting" do
Expand Down
2 changes: 1 addition & 1 deletion spec/models/blacklight/solr/facet_paginator_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Solr::FacetPaginator do
RSpec.describe Blacklight::Solr::FacetPaginator, api: true do
let(:f1) { Blacklight::Solr::Response::Facets::FacetItem.new(hits: '792', value: 'Book') }
describe "#as_json" do
subject { described_class.new([f1], offset: 0, limit: nil).as_json }
Expand Down
6 changes: 3 additions & 3 deletions spec/models/blacklight/solr/repository_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Solr::Repository do
RSpec.describe Blacklight::Solr::Repository, api: true do

let :blacklight_config do
CatalogController.blacklight_config.deep_copy
Expand Down Expand Up @@ -94,12 +94,12 @@
allow(subject.connection).to receive(:send_and_receive).with('select', hash_including(params: { qt: 'abc'})).and_return(mock_response)
expect(subject.search({qt: 'abc'})).to be_a_kind_of Blacklight::Solr::Response
end

it "should preserve the class of the incoming params" do
search_params = ActiveSupport::HashWithIndifferentAccess.new
search_params[:q] = "query"
allow(subject.connection).to receive(:send_and_receive).with('select', anything).and_return(mock_response)

response = subject.search(search_params)
expect(response).to be_a_kind_of Blacklight::Solr::Response
expect(response.params).to be_a_kind_of ActiveSupport::HashWithIndifferentAccess
Expand Down
4 changes: 2 additions & 2 deletions spec/models/blacklight/solr/request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Solr::Request do
RSpec.describe Blacklight::Solr::Request, api: true do
before do
subject[:qt] = 'hey'
subject[:fq] = ["what's up.", "dood"]
Expand All @@ -15,7 +15,7 @@
subject['spellcheck'] = "a"
subject['spellcheck.q'] = "fleece"
subject['f.title_facet.facet.limit'] = "vest"
subject['facet.field'] = []
subject['facet.field'] = []
end
it "should accept valid parameters" do
expect(subject.to_hash).to eq({"defType" => "had",
Expand Down
22 changes: 11 additions & 11 deletions spec/models/blacklight/solr/response/facets_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

RSpec.describe Blacklight::Solr::Response::Facets do
RSpec.describe Blacklight::Solr::Response::Facets, api: true do
describe Blacklight::Solr::Response::Facets::FacetField do

describe "A field with default options" do
Expand Down Expand Up @@ -78,7 +78,7 @@
expect(subject.aggregations['my_field'].sort).to eq 'count'
expect(subject.aggregations['my_field'].count?).to eq true
end

it "should default to index if no value is found and the limit is unlimited" do
request_params['facet.limit'] = -1
expect(subject.aggregations['my_field'].sort).to eq 'index'
Expand Down Expand Up @@ -114,7 +114,7 @@
}
}
end

subject { Blacklight::Solr::Response.new(response, {}) }

it "should mark the facet.missing field with a human-readable label and fq" do
Expand All @@ -126,7 +126,7 @@
end

describe "query facets" do
let(:facet_config) {
let(:facet_config) {
double(
key: 'my_query_facet_field',
:query => {
Expand All @@ -140,7 +140,7 @@
let(:blacklight_config) { double(facet_fields: { 'my_query_facet_field' => facet_config } )}

let(:response) do
{
{
facet_counts: {
facet_queries: {
'field:search' => 10,
Expand Down Expand Up @@ -175,18 +175,18 @@
let(:facet_config) {
double(key: 'my_pivot_facet_field', query: nil, pivot: ['field_a', 'field_b'])
}

let(:blacklight_config) { double(facet_fields: { 'my_pivot_facet_field' => facet_config } )}

let(:response) do
{
{
facet_counts: {
facet_pivot: {
facet_pivot: {
'field_a,field_b' => [
{
field: 'field_a',
value: 'a',
count: 10,
field: 'field_a',
value: 'a',
count: 10,
pivot: [{field: 'field_b', value: 'b', count: 2}]
}]
}
Expand Down

0 comments on commit f4090f5

Please sign in to comment.