krikri 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7992c5e83183e808c661f664db976ad4c379383f
4
- data.tar.gz: 43342b61e3ceb3831407477a57f9c71f08249d76
3
+ metadata.gz: a6b203c78eb59c0ebe59c473df10e84eaaa6aba5
4
+ data.tar.gz: 9e1824d2badadd4a0aa6d2fcdbaa89ed6b650da7
5
5
  SHA512:
6
- metadata.gz: fede833912720a4b41ea53fd9968af56230ad69ae4895c28fe27f213511b4b00ec372759233f4ff6697eabe667c2980dc7ba7a81f33d2865201b62d2727b7105
7
- data.tar.gz: 44c09d19766ce62ff498e505891e2be8034d57a7bf42d9979db26c1b1ef5360a4ca9c1d64ff432b4aa60589eea076f1592bf90195316f07b8a4ce9473a780f14
6
+ metadata.gz: 0ecaf50ef5597d05994ffdf031145e661e0a4a8c23a90fcc3e29a5958f41e8523a27a75e9ba344484f4bdbdb9d6f5853d8b8c8b03aa9fe43629de20e64114ed9
7
+ data.tar.gz: e7dd24afa55cfa79efe78a5804725e0368bdcfa22721a779b9052290816f5a217980bddd7b6d559b4fe9623e9b65d8af5ea87fd120e7f2c57a37bdb5b327149b
@@ -10,9 +10,9 @@ module Krikri
10
10
  # for the specified provider.
11
11
  def index
12
12
  @current_provider = params[:provider]
13
- @validation_reports = Krikri::ValidationReport.new.all do
14
- self.provider_id = @current_provider
15
- end
13
+ report = Krikri::ValidationReport.new
14
+ report.provider_id = @current_provider
15
+ @validation_reports = report.all
16
16
 
17
17
  if @current_provider
18
18
  @qa_reports = Array(Krikri::QAReport.find_by(provider: @current_provider))
@@ -17,16 +17,29 @@ module Krikri
17
17
  # ApplicationController. It uses krikri's application layout:
18
18
  layout 'krikri/application'
19
19
 
20
+ ##
21
+ # Render the show view
22
+ #
23
+ # This differs from {Blacklight::CatalogController}'s normal handling of the
24
+ # index and show views, Giving a paginated list of response documents
25
+ # instead of showing a single document.
26
+ #
27
+ # @todo: consider bringing this in line with Blacklight's approach
20
28
  def show
21
29
  @current_provider = params[:provider]
22
- page = params[:page]
23
- per_page = params[:per_page]
24
- @response = ValidationReport.new.find(params[:id]) do
25
- self.provider_id = @current_provider
26
- self.start = page
27
- self.rows = per_page
28
- end
30
+
31
+ @response = build_report.find(params[:id])
29
32
  @documents = @response.documents
30
33
  end
34
+
35
+ private
36
+
37
+ def build_report
38
+ report = ValidationReport.new
39
+ report.provider_id = @current_provider
40
+ report.page = params[:page]
41
+ report.rows = params[:per_page]
42
+ report
43
+ end
31
44
  end
32
45
  end
@@ -1,23 +1,25 @@
1
1
  module Krikri
2
2
  class ValidationReport
3
- attr_accessor :provider_id, :start, :rows
3
+ attr_accessor :provider_id, :page, :rows
4
4
 
5
5
  REQUIRED_FIELDS = ['dataProvider_name', 'isShownAt_id', 'preview_id',
6
6
  'sourceResource_rights', 'sourceResource_title',
7
7
  'sourceResource_type_id']
8
8
 
9
9
  ##
10
- # @param &block may contain provider_id
11
- # Sample use:
12
- # ValidationReport.new.all do
13
- # self.provider_id = '0123'
14
- # end
10
+ # @example
11
+ # ValidationReport.new.all
12
+ # => [#<Blacklight::SolrResponse::Facets::FacetField:0x007fce32f46fe8 ...]
15
13
  #
16
- # @return [Array<Blacklight::SolrResponse::Facet>]
17
- def all(&block)
18
- # set values from block
19
- instance_eval &block if block_given?
20
-
14
+ # @example
15
+ # report = ValidationReport.new
16
+ # report.provider_id = '0123'
17
+ # report.all
18
+ # => [#<Blacklight::SolrResponse::Facets::FacetField:0x007fce32f46fe8 ...]
19
+ #
20
+ # @return [Array<Blacklight::SolrResponse::Facets::FacetField>] a report for
21
+ # missing values in each of the `REQUIRED_FIELDS`
22
+ def all
21
23
  query_params = { :rows => 0,
22
24
  'facet.field' => REQUIRED_FIELDS,
23
25
  'facet.mincount' => 10000000,
@@ -29,25 +31,32 @@ module Krikri
29
31
  end
30
32
 
31
33
  ##
32
- # @param id [String]
33
- # @param &block may contain provider_id, start, rows
34
- # Sample use:
35
- # ValidationReport.new.find('sourceResource_title') do
36
- # self.provider_id = '0123'
37
- # end
34
+ # @param id [String] a field to check for missing values
35
+ #
36
+ # @example
37
+ # ValidationReport.new.find('sourceResource_title')
38
+ # => {"responseHeader"=>{"status"=>0, "QTime"=>123},
39
+ # "response"=>{"numFound"=>2653, "start"=>0, "docs"=>[...]}}
40
+ #
41
+ # @example
42
+ # report = ValidationReport.new
43
+ # report.provider_id = '0123'
44
+ # report.rows = 100
45
+ # report.find('sourceResource_title')
38
46
  #
39
47
  # @raise [RSolr::Error::Http] for non-existant field requests
40
48
  # @return [Blacklight::SolrResponse]
41
- def find(id, &block)
42
- # set values from block
43
- instance_eval &block if block_given?
44
-
45
-
49
+ #
50
+ # @todo possibly make better use of blacklight controllers? This currently
51
+ # assumes that the default pagination is 10. Anything else will cause
52
+ # trouble.
53
+ def find(id)
46
54
  query_params = { :qt => 'standard', :q => "-#{id}:[* TO *]" }
47
55
  query_params[:rows] = @rows.present? ? @rows : '10'
48
- query_params[:fq] = "provider_id:\"#{provider_uri}\""
49
- query_params[:start] = @start if @start.present? if
56
+ query_params[:fq] = "provider_id:\"#{provider_uri}\"" if
50
57
  provider_id.present?
58
+ multiplier = @rows ? @rows.to_i : 10
59
+ query_params[:start] = ((@page.to_i - 1) * multiplier) if @page.present?
51
60
 
52
61
  Krikri::SolrResponseBuilder.new(query_params).response
53
62
  end
@@ -1,3 +1,3 @@
1
1
  module Krikri
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -7,10 +7,13 @@ describe Krikri::ReportsController, :type => :controller do
7
7
  login_user
8
8
 
9
9
  before do
10
- allow_any_instance_of(Krikri::ValidationReport)
11
- .to receive(:all).and_return(validation_reports)
10
+ # @todo: Krikri::ValidationReport should be refactored to avoid the need
11
+ # for all this mocking.
12
+ allow(Krikri::ValidationReport).to receive(:new).and_return(report)
13
+ allow(report).to receive(:provider_id=)
14
+ allow(report).to receive(:all).and_return(validation_reports)
12
15
 
13
- allow(Krikri::QAReport).to receive(:find_by).with(provider: 'moomin')
16
+ allow(Krikri::QAReport).to receive(:find_by).with(provider: provider_id)
14
17
  .and_return(qa_reports)
15
18
  end
16
19
 
@@ -20,30 +23,42 @@ describe Krikri::ReportsController, :type => :controller do
20
23
 
21
24
  let(:qa_reports) { [double('qa report 1'), double('qa report 2')] }
22
25
 
26
+ let(:provider_id) { 'moomin' }
27
+
28
+ # @todo: remove me; see other comments
29
+ let(:report) { instance_double(Krikri::ValidationReport) }
30
+
23
31
  it 'renders the index view' do
24
32
  get :index
25
33
  expect(response).to render_template('krikri/reports/index')
26
34
  end
27
35
 
28
36
  it 'sets current provider' do
29
- expect { get :index, provider: 'moomin' }
30
- .to change { assigns(:current_provider) }.to('moomin')
37
+ expect { get :index, provider: provider_id }
38
+ .to change { assigns(:current_provider) }.to(provider_id)
31
39
  end
32
40
 
33
41
  it 'populates the validation reports list' do
34
- expect { get :index, provider: 'moomin' }
42
+ expect { get :index, provider: provider_id }
35
43
  .to change { assigns(:validation_reports) }.to(validation_reports)
36
44
  end
37
45
 
46
+ # @todo: this specifies implementation, due to limitations of the
47
+ # Krikri::ValidationReport interface (see above). Refactor me!
48
+ it 'sets the provider' do
49
+ expect(report).to receive(:provider_id=).with(provider_id)
50
+ get :index, provider: provider_id
51
+ end
52
+
38
53
  it 'populates the QA reports list by provider' do
39
- expect { get :index, provider: 'moomin' }
54
+ expect { get :index, provider: provider_id }
40
55
  .to change { assigns(:qa_reports) }.to (qa_reports)
41
56
  end
42
57
 
43
58
  it 'populates the QA reports as an array when a there is a single item' do
44
- allow(Krikri::QAReport).to receive(:find_by).with(provider: 'moomin')
59
+ allow(Krikri::QAReport).to receive(:find_by).with(provider: provider_id)
45
60
  .and_return(qa_reports.first)
46
- expect { get :index, provider: 'moomin' }
61
+ expect { get :index, provider: provider_id }
47
62
  .to change { assigns(:qa_reports) }.to ([qa_reports.first])
48
63
  end
49
64
 
@@ -16,5 +16,61 @@ describe Krikri::ValidationReportsController, :type => :controller do
16
16
  expect { get :show, id: 'sourceResource_title', provider: 'nypl' }
17
17
  .to change { assigns(:current_provider) }.to('nypl')
18
18
  end
19
+
20
+ # @todo: these are integration tests, repeating coverage from the
21
+ # ValidationReport model specs. The interface of ValidationReports
22
+ # makes this hard to test any other way (short of really nasty)
23
+ # `allow_any_instance_of` chains.
24
+ context 'with saved items' do
25
+ include_context 'with missing values'
26
+
27
+ it 'sets documents for all providers' do
28
+ get :show, id: 'sourceResource_title'
29
+
30
+ expect(assigns[:documents].map(&:id))
31
+ .to contain_exactly(empty.rdf_subject.to_s,
32
+ empty_new_provider.rdf_subject.to_s)
33
+ end
34
+
35
+ it 'sets documents by provider' do
36
+ get :show, id: 'sourceResource_title', provider: provider.id
37
+
38
+ expect(assigns[:documents].map(&:id))
39
+ .to contain_exactly empty.rdf_subject.to_s
40
+ end
41
+
42
+ it 'gives docments with isShownAt' do
43
+ get :show, id: 'sourceResource_title', provider: provider.id
44
+
45
+ expect(assigns[:documents].first['isShownAt_id'])
46
+ .not_to be_empty
47
+ end
48
+
49
+ describe 'pagination' do
50
+ it 'finds all matching items' do
51
+ get :show, id: 'sourceResource_title', per_page: 1
52
+
53
+ expect(assigns[:response].count).to eq 2
54
+ end
55
+
56
+ it 'gets current page' do
57
+ get :show, id: 'sourceResource_title', per_page: 1
58
+
59
+ expect(assigns[:response].docs.count).to eq 1
60
+ end
61
+
62
+ it 'sets next page' do
63
+ get :show, id: 'sourceResource_title', per_page: 1
64
+
65
+ expect(assigns[:response].next_page).to eq 2
66
+ end
67
+
68
+ it 'knows when there are no more pages' do
69
+ get :show, id: 'sourceResource_title', per_page: 1, page: 2
70
+
71
+ expect(assigns[:response].next_page).to eq nil
72
+ end
73
+ end
74
+ end
19
75
  end
20
76
  end
@@ -1,9 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Krikri::ValidationReport do
4
- include_context 'with indexed item'
5
-
6
- # @todo: need more tests for ValidationReport#all
7
4
  describe `#all` do
8
5
  it 'returns facet for each required field' do
9
6
  count = described_class::REQUIRED_FIELDS.count
@@ -12,9 +9,20 @@ describe Krikri::ValidationReport do
12
9
 
13
10
  expect(subject.all).to contain_exactly(*fields)
14
11
  end
12
+
13
+ context 'with missing value in record' do
14
+ include_context 'with missing values'
15
+
16
+ it 'returns facets by provider' do
17
+ subject.provider_id = provider.id
18
+ hits = subject.all.select { |fct| fct.name == 'sourceResource_title' }
19
+ .first.items.first.hits
20
+
21
+ expect(hits).to eq 1
22
+ end
23
+ end
15
24
  end
16
25
 
17
- # @todo: need more tests for ValidationReport#find
18
26
  describe `#find` do
19
27
  it 'gives a blacklight solr response' do
20
28
  expect(subject.find('sourceResource_title'))
@@ -26,24 +34,53 @@ describe Krikri::ValidationReport do
26
34
  .to raise_error RSolr::Error::Http
27
35
  end
28
36
 
29
- it 'gets by provider_id' do
30
- provider_uri = RDF::URI(Krikri::Settings.prov.provider_base) / '123'
31
- params = { :qt => 'standard',
32
- :q => '-sourceResource_title:[* TO *]',
33
- :rows => '10',
34
- :fq => "provider_id:\"#{provider_uri}\"" }
37
+ context 'with missing values in record' do
38
+ include_context 'with missing values'
35
39
 
40
+ it 'gets docs for all providers' do
41
+ docs = subject.find('sourceResource_title').response['docs']
36
42
 
37
- response = double('solr response')
38
- allow(Krikri::SolrResponseBuilder).to receive(:new).with(params)
39
- .and_return(response)
40
- allow(response).to receive(:response).and_return(:result)
43
+ expect(docs.map { |d| d['id'] })
44
+ .to contain_exactly(empty.rdf_subject.to_s,
45
+ empty_new_provider.rdf_subject.to_s)
46
+ end
41
47
 
42
- result = subject.find('sourceResource_title') do
43
- self.provider_id = '123'
48
+ it 'allows limiting of rows per page' do
49
+ subject.rows = 1
50
+ expect(subject.find('sourceResource_title').docs.count).to eq 1
44
51
  end
45
52
 
46
- expect(result).to eq :result
53
+ it 'allows pagination' do
54
+ subject.rows = '1'
55
+ page_one_docs = subject.find('sourceResource_title').docs
56
+ subject.page = '2'
57
+ expect(subject.find('sourceResource_title').docs)
58
+ .not_to eq page_one_docs
59
+ end
60
+
61
+ it 'paginates based on a default number of rows' do
62
+ page_one_docs = subject.find('sourceResource_title').docs
63
+ subject.page = '4'
64
+ expect(subject.find('sourceResource_title').response['start'])
65
+ .to eq 30
66
+ end
67
+
68
+ context 'with provider set' do
69
+ before { subject.provider_id = provider.id }
70
+
71
+ it 'gets by provider_id' do
72
+ expect(subject.find('sourceResource_title').response['numFound'])
73
+ .to eq 1
74
+ end
75
+
76
+ it 'gets docs by provider_id' do
77
+ subject.provider_id = provider.id
78
+ docs = subject.find('sourceResource_title').response['docs']
79
+
80
+ expect(docs.map { |d| d['id'] })
81
+ .to contain_exactly empty.rdf_subject.to_s
82
+ end
83
+ end
47
84
  end
48
85
  end
49
86
  end
@@ -4,7 +4,7 @@ shared_context 'with indexed item' do
4
4
  before do
5
5
  clear_search_index
6
6
  indexer = Krikri::QASearchIndex.new
7
- indexer.add agg.to_jsonld['@graph'].first
7
+ records.each { |rec| indexer.add rec.to_jsonld['@graph'].first }
8
8
  indexer.commit
9
9
  end
10
10
 
@@ -12,6 +12,8 @@ shared_context 'with indexed item' do
12
12
  clear_search_index
13
13
  end
14
14
 
15
+ let(:records) { [agg] }
16
+
15
17
  let(:agg) do
16
18
  a = build(:aggregation)
17
19
  a.provider = provider
@@ -25,3 +27,23 @@ shared_context 'with indexed item' do
25
27
  label: 'moomin valley')
26
28
  end
27
29
  end
30
+
31
+ shared_context 'with missing values' do
32
+ include_context 'with indexed item' do
33
+ let(:records) { [agg, empty, empty_new_provider] }
34
+
35
+ let(:empty) do
36
+ aggregation = build(:aggregation, provider: provider, sourceResource: nil)
37
+ aggregation.set_subject! 'empty'
38
+ aggregation
39
+ end
40
+
41
+ let(:empty_new_provider) do
42
+ aggregation = build(:aggregation,
43
+ provider: RDF::URI('http://example.com/fake'),
44
+ sourceResource: nil)
45
+ aggregation.set_subject! 'empty_new_provider'
46
+ aggregation
47
+ end
48
+ end
49
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krikri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Audrey Altman
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-04-06 00:00:00.000000000 Z
14
+ date: 2015-04-07 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails