supplejack_api 1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +80 -0
- data/Rakefile +42 -0
- data/app/assets/javascripts/supplejack_api/application.js +26 -0
- data/app/assets/stylesheets/supplejack_api/application.css +30 -0
- data/app/controllers/supplejack_api/admin/base_controller.rb +24 -0
- data/app/controllers/supplejack_api/admin/sessions_controller.rb +25 -0
- data/app/controllers/supplejack_api/admin/site_activities_controller.rb +21 -0
- data/app/controllers/supplejack_api/admin/users_controller.rb +55 -0
- data/app/controllers/supplejack_api/application_controller.rb +70 -0
- data/app/controllers/supplejack_api/concepts_controller.rb +52 -0
- data/app/controllers/supplejack_api/concerns/ignore_metrics.rb +14 -0
- data/app/controllers/supplejack_api/concerns/records_controller_metrics.rb +26 -0
- data/app/controllers/supplejack_api/concerns/set_items_controller_metrics.rb +20 -0
- data/app/controllers/supplejack_api/concerns/user_sets_controller_metrics.rb +26 -0
- data/app/controllers/supplejack_api/harvester/concepts_controller.rb +41 -0
- data/app/controllers/supplejack_api/harvester/fragments_controller.rb +30 -0
- data/app/controllers/supplejack_api/harvester/records_controller.rb +68 -0
- data/app/controllers/supplejack_api/metrics_api_controller.rb +44 -0
- data/app/controllers/supplejack_api/partners_controller.rb +39 -0
- data/app/controllers/supplejack_api/records_controller.rb +71 -0
- data/app/controllers/supplejack_api/schema_controller.rb +19 -0
- data/app/controllers/supplejack_api/set_items_controller.rb +38 -0
- data/app/controllers/supplejack_api/sources_controller.rb +67 -0
- data/app/controllers/supplejack_api/status_controller.rb +67 -0
- data/app/controllers/supplejack_api/user_sets_controller.rb +97 -0
- data/app/controllers/supplejack_api/users_controller.rb +49 -0
- data/app/helpers/supplejack_api/application_helper.rb +39 -0
- data/app/helpers/supplejack_api/facets_helper.rb +30 -0
- data/app/mailers/supplejack_api/request_limit_mailer.rb +43 -0
- data/app/models/supplejack_api/api_concept/concept_fragment.rb +31 -0
- data/app/models/supplejack_api/api_record/record_fragment.rb +15 -0
- data/app/models/supplejack_api/concept.rb +46 -0
- data/app/models/supplejack_api/concept_search.rb +86 -0
- data/app/models/supplejack_api/concerns/queryable_by_date.rb +31 -0
- data/app/models/supplejack_api/concerns/record.rb +108 -0
- data/app/models/supplejack_api/concerns/record_fragmentable.rb +24 -0
- data/app/models/supplejack_api/concerns/searchable.rb +430 -0
- data/app/models/supplejack_api/concerns/user_set.rb +219 -0
- data/app/models/supplejack_api/daily_metrics.rb +20 -0
- data/app/models/supplejack_api/faceted_metrics.rb +55 -0
- data/app/models/supplejack_api/fragment.rb +82 -0
- data/app/models/supplejack_api/interaction_models/record.rb +60 -0
- data/app/models/supplejack_api/interaction_models/set.rb +13 -0
- data/app/models/supplejack_api/interaction_updaters/all_usage_metric.rb +41 -0
- data/app/models/supplejack_api/interaction_updaters/set_metrics.rb +32 -0
- data/app/models/supplejack_api/interaction_updaters/usage_metrics.rb +73 -0
- data/app/models/supplejack_api/partner.rb +24 -0
- data/app/models/supplejack_api/preview_record.rb +30 -0
- data/app/models/supplejack_api/record.rb +18 -0
- data/app/models/supplejack_api/record_search.rb +12 -0
- data/app/models/supplejack_api/schema_definition.rb +147 -0
- data/app/models/supplejack_api/search.rb +14 -0
- data/app/models/supplejack_api/set_item.rb +57 -0
- data/app/models/supplejack_api/site_activity.rb +59 -0
- data/app/models/supplejack_api/source.rb +28 -0
- data/app/models/supplejack_api/source_activity.rb +36 -0
- data/app/models/supplejack_api/source_authority.rb +42 -0
- data/app/models/supplejack_api/supplejack_schema.rb +37 -0
- data/app/models/supplejack_api/support/concept/searchable.rb +79 -0
- data/app/models/supplejack_api/support/concept/storable.rb +59 -0
- data/app/models/supplejack_api/support/fragment_helpers.rb +96 -0
- data/app/models/supplejack_api/support/harvestable.rb +105 -0
- data/app/models/supplejack_api/support/searchable.rb +115 -0
- data/app/models/supplejack_api/support/status_logger.rb +23 -0
- data/app/models/supplejack_api/support/storable.rb +49 -0
- data/app/models/supplejack_api/support/validation_logger.rb +23 -0
- data/app/models/supplejack_api/usage_metrics.rb +25 -0
- data/app/models/supplejack_api/user.rb +211 -0
- data/app/models/supplejack_api/user_activity.rb +65 -0
- data/app/models/supplejack_api/user_set.rb +17 -0
- data/app/serializers/supplejack_api/application_serializer.rb +12 -0
- data/app/serializers/supplejack_api/concept_record_serializer.rb +23 -0
- data/app/serializers/supplejack_api/concept_search_serializer.rb +12 -0
- data/app/serializers/supplejack_api/concept_serializer.rb +100 -0
- data/app/serializers/supplejack_api/concerns/record_serializable.rb +119 -0
- data/app/serializers/supplejack_api/concerns/search_serializable.rb +24 -0
- data/app/serializers/supplejack_api/record_search_serializer.rb +64 -0
- data/app/serializers/supplejack_api/record_serializer.rb +13 -0
- data/app/serializers/supplejack_api/search_serializer.rb +13 -0
- data/app/serializers/supplejack_api/source_authority_serializer.rb +23 -0
- data/app/serializers/supplejack_api/user_serializer.rb +13 -0
- data/app/serializers/supplejack_api/user_set_record_serializer.rb +14 -0
- data/app/serializers/supplejack_api/user_set_serializer.rb +77 -0
- data/app/services/metrics_api/v3/api.rb +30 -0
- data/app/services/metrics_api/v3/endpoints/facets.rb +23 -0
- data/app/services/metrics_api/v3/endpoints/global.rb +26 -0
- data/app/services/metrics_api/v3/endpoints/helpers.rb +14 -0
- data/app/services/metrics_api/v3/endpoints/root.rb +97 -0
- data/app/services/metrics_api/v3/presenters/daily_metric.rb +23 -0
- data/app/services/metrics_api/v3/presenters/extended_metadata.rb +41 -0
- data/app/services/metrics_api/v3/presenters/record.rb +26 -0
- data/app/services/metrics_api/v3/presenters/view.rb +28 -0
- data/app/views/layouts/supplejack_api/_head.html.erb +17 -0
- data/app/views/layouts/supplejack_api/_top_nav.html.erb +33 -0
- data/app/views/layouts/supplejack_api/application.html.erb +33 -0
- data/app/views/supplejack_api/admin/sessions/new.html.erb +25 -0
- data/app/views/supplejack_api/admin/shared/_links.erb +34 -0
- data/app/views/supplejack_api/admin/site_activities/index.csv.erb +22 -0
- data/app/views/supplejack_api/admin/site_activities/index.html.erb +54 -0
- data/app/views/supplejack_api/admin/users/edit.html.erb +16 -0
- data/app/views/supplejack_api/admin/users/index.csv.erb +22 -0
- data/app/views/supplejack_api/admin/users/index.html.erb +57 -0
- data/app/views/supplejack_api/admin/users/show.html.erb +33 -0
- data/app/views/supplejack_api/request_limit_mailer/at100percent.text.erb +13 -0
- data/app/views/supplejack_api/request_limit_mailer/at100percent_admin.text.erb +1 -0
- data/app/views/supplejack_api/request_limit_mailer/at90percent.text.erb +13 -0
- data/app/views/supplejack_api/request_limit_mailer/at90percent_admin.text.erb +1 -0
- data/app/workers/supplejack_api/daily_metrics_worker.rb +112 -0
- data/app/workers/supplejack_api/interaction_metrics_worker.rb +45 -0
- data/config/cucumber.yml +16 -0
- data/config/initializers/force_eagerload.rb +11 -0
- data/config/initializers/interaction_updaters.rb +7 -0
- data/config/routes.rb +81 -0
- data/db/binding_records.development.json +7 -0
- data/db/binding_records.staging.json +7 -0
- data/db/concepts.json +33 -0
- data/db/concepts_data.json +569745 -0
- data/db/source_authorities.json +119 -0
- data/lib/generators/supplejack_api/install_generator.rb +124 -0
- data/lib/mongoid/paperclip.rb +53 -0
- data/lib/mongoid/string.rb +20 -0
- data/lib/sunspot/mongoid.rb +51 -0
- data/lib/sunspot/resque_session_proxy.rb +72 -0
- data/lib/sunspot/sunspot_spellcheck.rb +98 -0
- data/lib/supplejack_api.rb +13 -0
- data/lib/supplejack_api/admin/sortable.rb +40 -0
- data/lib/supplejack_api/engine.rb +46 -0
- data/lib/supplejack_api/harvester_constraint.rb +28 -0
- data/lib/supplejack_api/stylesheets.rb +36 -0
- data/lib/supplejack_api/utils.rb +75 -0
- data/lib/supplejack_api/version.rb +11 -0
- data/lib/tasks/resque.rake +22 -0
- data/lib/url_validator.rb +38 -0
- data/spec/controllers/supplejack_api/admin/base_controller_spec.rb +55 -0
- data/spec/controllers/supplejack_api/admin/site_activities_controller_spec.rb +43 -0
- data/spec/controllers/supplejack_api/admin/users_controller_spec.rb +79 -0
- data/spec/controllers/supplejack_api/application_controller_spec.rb +133 -0
- data/spec/controllers/supplejack_api/concepts_controller_spec.rb +83 -0
- data/spec/controllers/supplejack_api/concerns/records_controller_metrics_spec.rb +60 -0
- data/spec/controllers/supplejack_api/harvester/concepts_controller_spec.rb +57 -0
- data/spec/controllers/supplejack_api/harvester/records_controller_spec.rb +138 -0
- data/spec/controllers/supplejack_api/metrics_api_controller_spec.rb +71 -0
- data/spec/controllers/supplejack_api/partners_controller_spec.rb +77 -0
- data/spec/controllers/supplejack_api/records_controller_spec.rb +143 -0
- data/spec/controllers/supplejack_api/set_items_controller_spec.rb +78 -0
- data/spec/controllers/supplejack_api/sources_controller_spec.rb +161 -0
- data/spec/controllers/supplejack_api/status_controller_spec.rb +120 -0
- data/spec/controllers/supplejack_api/user_sets_controller_spec.rb +233 -0
- data/spec/controllers/supplejack_api/users_controller_spec.rb +61 -0
- data/spec/dummy/README.rdoc +268 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +23 -0
- data/spec/dummy/app/assets/stylesheets/application.css +22 -0
- data/spec/dummy/app/controllers/application_controller.rb +10 -0
- data/spec/dummy/app/helpers/application_helper.rb +9 -0
- data/spec/dummy/app/supplejack_api/concept_schema.rb +83 -0
- data/spec/dummy/app/supplejack_api/record_schema.rb +64 -0
- data/spec/dummy/app/supplejack_api/record_schema.txt +66 -0
- data/spec/dummy/app/views/layouts/application.html.erb +23 -0
- data/spec/dummy/app/workers/supplejack_api/clear_index_buffer.rb +32 -0
- data/spec/dummy/app/workers/supplejack_api/flush_old_records_worker.rb +17 -0
- data/spec/dummy/app/workers/supplejack_api/index_buffer.rb +49 -0
- data/spec/dummy/app/workers/supplejack_api/index_source_worker.rb +39 -0
- data/spec/dummy/app/workers/supplejack_api/index_worker.rb +82 -0
- data/spec/dummy/app/workers/supplejack_api/store_user_activity_worker.rb +24 -0
- data/spec/dummy/config.ru +11 -0
- data/spec/dummy/config/application.rb +76 -0
- data/spec/dummy/config/application.yml +31 -0
- data/spec/dummy/config/application.yml.example +36 -0
- data/spec/dummy/config/boot.rb +17 -0
- data/spec/dummy/config/environment.rb +12 -0
- data/spec/dummy/config/environments/development.rb +42 -0
- data/spec/dummy/config/environments/production.rb +76 -0
- data/spec/dummy/config/environments/test.rb +46 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +14 -0
- data/spec/dummy/config/initializers/devise.rb +214 -0
- data/spec/dummy/config/initializers/inflections.rb +22 -0
- data/spec/dummy/config/initializers/kaminari_config.rb +17 -0
- data/spec/dummy/config/initializers/mime_types.rb +12 -0
- data/spec/dummy/config/initializers/mongoid.rb +9 -0
- data/spec/dummy/config/initializers/quiet_logger.rb +23 -0
- data/spec/dummy/config/initializers/resque.rb +18 -0
- data/spec/dummy/config/initializers/secret_token.rb +14 -0
- data/spec/dummy/config/initializers/session_store.rb +15 -0
- data/spec/dummy/config/initializers/simple_form.rb +149 -0
- data/spec/dummy/config/initializers/simple_form_foundation.rb +33 -0
- data/spec/dummy/config/initializers/state_machine.rb +8 -0
- data/spec/dummy/config/initializers/sunspot.rb +32 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
- data/spec/dummy/config/locales/devise.en.yml +63 -0
- data/spec/dummy/config/locales/en.yml +66 -0
- data/spec/dummy/config/locales/simple_form.en.yml +33 -0
- data/spec/dummy/config/mongoid.travis.yml +34 -0
- data/spec/dummy/config/mongoid.yml +36 -0
- data/spec/dummy/config/resque-pool.yml +18 -0
- data/spec/dummy/config/resque_schedule.yml +12 -0
- data/spec/dummy/config/routes.rb +11 -0
- data/spec/dummy/config/secrets.yml +8 -0
- data/spec/dummy/config/sunspot.yml +38 -0
- data/spec/dummy/db/concepts.json +37 -0
- data/spec/dummy/db/source_authorities.json +116 -0
- data/spec/dummy/public/404.html +35 -0
- data/spec/dummy/public/422.html +35 -0
- data/spec/dummy/public/500.html +34 -0
- data/spec/dummy/public/favicon.ico +8 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/solr/collection1/conf/elevate.xml +36 -0
- data/spec/dummy/solr/collection1/conf/mapping-FoldToASCII.txt +3813 -0
- data/spec/dummy/solr/collection1/conf/schema.xml +292 -0
- data/spec/dummy/solr/collection1/conf/solrconfig.xml +1780 -0
- data/spec/dummy/solr/collection1/conf/spellings.txt +2 -0
- data/spec/dummy/solr/collection1/conf/stopwords.txt +58 -0
- data/spec/dummy/solr/collection1/conf/synonyms.txt +31 -0
- data/spec/factories/concepts.rb +16 -0
- data/spec/factories/daily_metrics.rb +10 -0
- data/spec/factories/faceted_metrics.rb +25 -0
- data/spec/factories/fragment.rb +14 -0
- data/spec/factories/partners.rb +14 -0
- data/spec/factories/record_interaction.rb +17 -0
- data/spec/factories/records.rb +47 -0
- data/spec/factories/set_interaction.rb +15 -0
- data/spec/factories/source_authorities.rb +19 -0
- data/spec/factories/sources.rb +16 -0
- data/spec/factories/usage_metrics.rb +20 -0
- data/spec/factories/user_activities.rb +14 -0
- data/spec/factories/user_sets.rb +27 -0
- data/spec/factories/users.rb +23 -0
- data/spec/helpers/application_helper_spec.rb +35 -0
- data/spec/models/concept_spec.rb +163 -0
- data/spec/models/fragment_spec.rb +15 -0
- data/spec/models/site_activity_spec.rb +103 -0
- data/spec/models/source_activity_spec.rb +56 -0
- data/spec/models/source_authority_spec.rb +42 -0
- data/spec/models/supplejack_api/api_concept/concept_fragment_spec.rb +189 -0
- data/spec/models/supplejack_api/api_record/record_fragment_spec.rb +189 -0
- data/spec/models/supplejack_api/concept_spec.rb +0 -0
- data/spec/models/supplejack_api/interaction_updaters/all_usage_metric_spec.rb +41 -0
- data/spec/models/supplejack_api/interaction_updaters/set_metrics_spec.rb +32 -0
- data/spec/models/supplejack_api/interaction_updaters/usage_metrics_spec.rb +44 -0
- data/spec/models/supplejack_api/partner_spec.rb +20 -0
- data/spec/models/supplejack_api/record_search_spec.rb +429 -0
- data/spec/models/supplejack_api/record_spec.rb +280 -0
- data/spec/models/supplejack_api/schema_definition_spec.rb +272 -0
- data/spec/models/supplejack_api/search_spec.rb +243 -0
- data/spec/models/supplejack_api/set_item_spec.rb +123 -0
- data/spec/models/supplejack_api/source_spec.rb +22 -0
- data/spec/models/supplejack_api/support/fragment_helpers_spec.rb +216 -0
- data/spec/models/supplejack_api/support/harvestable_spec.rb +177 -0
- data/spec/models/supplejack_api/support/searchable_spec.rb +85 -0
- data/spec/models/supplejack_api/support/storable_spec.rb +18 -0
- data/spec/models/supplejack_api/user_activity_spec.rb +88 -0
- data/spec/models/supplejack_api/user_set_spec.rb +559 -0
- data/spec/models/supplejack_api/user_spec.rb +348 -0
- data/spec/routing/concepts_routing_spec.rb +22 -0
- data/spec/routing/harvester_constraint_spec.rb +66 -0
- data/spec/routing/harvester_routing_spec.rb +51 -0
- data/spec/routing/partner_routing_spec.rb +34 -0
- data/spec/routing/records_routing_spec.rb +26 -0
- data/spec/routing/sets_routing_spec.rb +44 -0
- data/spec/routing/source_routing_spec.rb +38 -0
- data/spec/routing/users_routing_spec.rb +18 -0
- data/spec/serializers/concept_record_serializer_spec.rb +30 -0
- data/spec/serializers/supplejack_api/application_serializer_spec.rb +14 -0
- data/spec/serializers/supplejack_api/concept_search_serializer_spec.rb +34 -0
- data/spec/serializers/supplejack_api/concept_serializer_spec.rb +92 -0
- data/spec/serializers/supplejack_api/record_search_serializer_spec.rb +34 -0
- data/spec/serializers/supplejack_api/record_serializer_spec.rb +271 -0
- data/spec/serializers/supplejack_api/search_serializer_spec.rb +90 -0
- data/spec/serializers/supplejack_api/user_serializer_spec.rb +22 -0
- data/spec/serializers/supplejack_api/user_set_serializer_spec.rb +96 -0
- data/spec/services/metrics_api/v3/api_spec.rb +23 -0
- data/spec/services/metrics_api/v3/endpoints/facets_spec.rb +25 -0
- data/spec/services/metrics_api/v3/endpoints/global_spec.rb +22 -0
- data/spec/services/metrics_api/v3/endpoints/root_spec.rb +49 -0
- data/spec/services/metrics_api/v3/presenters/extended_metadata_spec.rb +49 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/support/api/schemas/metrics/daily_metrics_metadata.json +24 -0
- data/spec/support/api/schemas/metrics/extended_metrics.json +26 -0
- data/spec/support/api/schemas/metrics/extended_response.json +6 -0
- data/spec/support/api/schemas/metrics/facets_response.json +6 -0
- data/spec/support/api/schemas/metrics/record_metadata.json +33 -0
- data/spec/support/api/schemas/metrics/top_level_response.json +6 -0
- data/spec/support/api/schemas/metrics/view_metadata.json +33 -0
- data/spec/support/api_schema_matcher.rb +14 -0
- data/spec/support/devise.rb +10 -0
- data/spec/workers/supplejack_api/daily_metrics_worker_spec.rb +140 -0
- data/spec/workers/supplejack_api/flush_old_records_worker_spec.rb +20 -0
- data/spec/workers/supplejack_api/index_worker_spec.rb +52 -0
- data/spec/workers/supplejack_api/source_index_worker_spec.rb +61 -0
- metadata +1231 -0
@@ -0,0 +1,243 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe Search do
|
12
|
+
before {
|
13
|
+
@search = Search.new
|
14
|
+
Sunspot.session = SunspotMatchers::SunspotSessionSpy.new(Sunspot.session)
|
15
|
+
@session = Sunspot.session
|
16
|
+
|
17
|
+
allow(Search).to receive(:role_collection_restrictions) { [] }
|
18
|
+
}
|
19
|
+
|
20
|
+
describe '#facet_list' do
|
21
|
+
before {
|
22
|
+
@search = RecordSearch.new
|
23
|
+
allow(@search).to receive(:model_class) { Record }
|
24
|
+
}
|
25
|
+
|
26
|
+
it 'should return a array of facets' do
|
27
|
+
@search.options[:facets] = 'name, address'
|
28
|
+
expect(@search.facet_list).to eq [:name, :address]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should discard any fields not configured as facets' do
|
32
|
+
@search.options[:facets] = 'name, address, other_facet'
|
33
|
+
expect(@search.facet_list).to eq [:name, :address]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#field_list' do
|
38
|
+
before {
|
39
|
+
@search = RecordSearch.new
|
40
|
+
allow(@search).to receive(:schema_class) { RecordSchema }
|
41
|
+
}
|
42
|
+
|
43
|
+
it 'should return a array of fields' do
|
44
|
+
@search.options[:fields] = 'name, address'
|
45
|
+
expect(@search.field_list).to eq [:name, :address]
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should only return valid fields' do
|
49
|
+
@search.options[:fields] = 'name, something_else'
|
50
|
+
expect(@search.field_list).to eq [:name]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#group_list' do
|
55
|
+
before {
|
56
|
+
@search = RecordSearch.new
|
57
|
+
allow(@search).to receive(:model_class) { Record }
|
58
|
+
}
|
59
|
+
|
60
|
+
it 'gets the groups from the fields list' do
|
61
|
+
@search.options[:fields] = "content_partner, core"
|
62
|
+
expect(@search.group_list).to eq [:core]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#query_fields' do
|
67
|
+
it 'returns nil when no query fields were specified' do
|
68
|
+
@search = Search.new
|
69
|
+
expect(@search.query_fields).to be_nil
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns the query fields from the params' do
|
73
|
+
@search = Search.new(query_fields: [:collection])
|
74
|
+
expect(@search.query_fields).to eq([:collection])
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'supports the query_fields as comma separated string' do
|
78
|
+
@search = Search.new(query_fields: 'collection, creator, publisher')
|
79
|
+
expect(@search.query_fields).to eq([:collection, :creator, :publisher])
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'converts an array of strings to symbols' do
|
83
|
+
@search = Search.new(query_fields: ['collection','creator'])
|
84
|
+
expect(@search.query_fields).to eq([:collection, :creator])
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns nil when query_fields is an empty string' do
|
88
|
+
@search = Search.new(query_fields: '')
|
89
|
+
expect(@search.query_fields).to be_nil
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns nil when query_fields is an empty array' do
|
93
|
+
@search = Search.new(query_fields: [])
|
94
|
+
expect(@search.query_fields).to be_nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#extract_range' do
|
99
|
+
it 'extracts the dates from [1900 TO 2000] and return a range' do
|
100
|
+
expect(@search.extract_range('[1900 TO 2000]')).to eq(1900..2000)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'doesn\'t match non numbers' do
|
104
|
+
expect(@search.extract_range('[asdasd TO asdads]')).to eq '[asdasd TO asdads]'
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'returns the current value if is not a range and converts it to int' do
|
108
|
+
expect(@search.extract_range('1900')).to eq 1900
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#to_proper_value' do
|
113
|
+
it 'returns false for "false" string' do
|
114
|
+
expect(@search.to_proper_value('active?', 'false')).to be_falsey
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'returns true for "true" string' do
|
118
|
+
expect(@search.to_proper_value('active?', 'true')).to be_truthy
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'returns nil if is a "nil" string' do
|
122
|
+
expect(@search.to_proper_value('active?', 'nil')).to be_nil
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns nil if is a "null" string' do
|
126
|
+
expect(@search.to_proper_value('active?', 'null')).to be_nil
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'returns the value unchanged' do
|
130
|
+
expect(@search.to_proper_value('label', 'Black')).to eq('Black')
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'should strip any white space' do
|
134
|
+
expect(@search.to_proper_value('label', ' Black Label ')).to eq('Black Label')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#text' do
|
139
|
+
it 'downcases the text string' do
|
140
|
+
expect(Search.new(text: 'McDowall').text).to eq 'mcdowall'
|
141
|
+
end
|
142
|
+
|
143
|
+
['AND', 'OR', 'NOT'].each do |operator|
|
144
|
+
it "downcases everything except the #{operator} operators" do
|
145
|
+
expect(Search.new(text: "McDowall #{operator} Dogs").text).to eq "mcdowall #{operator} dogs"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#solr_search_object' do
|
151
|
+
it 'memoizes the solr search object' do
|
152
|
+
sunspot_mock = double(:solr).as_null_object
|
153
|
+
expect(@search).to receive(:execute_solr_search).once.and_return(sunspot_mock)
|
154
|
+
@search.solr_search_object
|
155
|
+
expect(@search.solr_search_object).to eq(sunspot_mock)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'sets the solr request parameters when debug=true' do
|
159
|
+
@search.options[:debug] = 'true'
|
160
|
+
allow(@search).to receive(:execute_solr_search) { double(:solr_request, query: double(:query, to_params: {param1: 1})) }
|
161
|
+
@search.solr_search_object
|
162
|
+
expect(@search.solr_request_params).to eq({:param1 => 1})
|
163
|
+
end
|
164
|
+
|
165
|
+
it "doesn't set the solr request parameters" do
|
166
|
+
allow(@search).to receive(:execute_solr_search) { double(:solr_request, query: double(:query, to_params: {param1: 1})) }
|
167
|
+
@search.solr_search_object
|
168
|
+
expect(@search.solr_request_params).to be_nil
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'returns a empty hash when solr request fails' do
|
172
|
+
@search.options[:debug] = 'true'
|
173
|
+
allow(@search).to receive(:execute_solr_search) { {} }
|
174
|
+
expect(@search.solr_search_object).to eq({})
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe '#solr_error_message' do
|
179
|
+
before {
|
180
|
+
@error = double(:error, response: {status: 400, body: 'Solr error'})
|
181
|
+
allow(@error).to receive(:parse_solr_error_response) { 'Solr error' }
|
182
|
+
}
|
183
|
+
|
184
|
+
it 'returns a hash with the solr error title and description' do
|
185
|
+
expect(@search.solr_error_message(@error)).to eq({title: '400 Bad Request', body: 'Solr error'})
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe '#method_missing' do
|
190
|
+
it 'delegates any missing method to the solr_search_object' do
|
191
|
+
sso = double(:sso, something_missing: [], hits: [])
|
192
|
+
allow(@search).to receive(:solr_search_object).and_return(sso)
|
193
|
+
expect(sso).to receive(:something_missing)
|
194
|
+
@search.something_missing
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'returns nil when solr request failed' do
|
198
|
+
allow(@search).to receive(:solr_search_object).and_return({})
|
199
|
+
expect(@search.something_missing).to be_nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe '#solr_error_message' do
|
204
|
+
before(:each) do
|
205
|
+
@error = double(:error, response: {status: 400, body: 'Solr error'})
|
206
|
+
allow(@error).to receive(:parse_solr_error_response) { 'Solr error' }
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'returns a hash with the solr error title and description' do
|
210
|
+
expect(@search.solr_error_message(@error)).to eq({:title => '400 Bad Request', :body => 'Solr error'})
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe '#solr_search_object' do
|
215
|
+
it 'memoizes the solr search object' do
|
216
|
+
sunspot_mock = double(:solr).as_null_object
|
217
|
+
expect(@search).to receive(:execute_solr_search).once.and_return(sunspot_mock)
|
218
|
+
@search.solr_search_object
|
219
|
+
expect(@search.solr_search_object).to eq(sunspot_mock)
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'sets the solr request parameters when debug=true' do
|
223
|
+
@search.options[:debug] = 'true'
|
224
|
+
allow(@search).to receive(:execute_solr_search) { double(:solr_request, query: double(:query, to_params: {param1: 1})) }
|
225
|
+
@search.solr_search_object
|
226
|
+
expect(@search.solr_request_params).to eq({:param1 => 1})
|
227
|
+
end
|
228
|
+
|
229
|
+
it "doesn't set the solr request parameters" do
|
230
|
+
allow(@search).to receive(:execute_solr_search) { double(:solr_request, query: double(:query, to_params: {param1: 1})) }
|
231
|
+
@search.solr_search_object
|
232
|
+
expect(@search.solr_request_params).to be_nil
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'returns a empty hash when solr request fails' do
|
236
|
+
@search.options[:debug] = 'true'
|
237
|
+
allow(@search).to receive(:execute_solr_search) { {} }
|
238
|
+
expect(@search.solr_search_object).to eq({})
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe SetItem do
|
12
|
+
|
13
|
+
let(:user_set) { FactoryGirl.build(:user_set) }
|
14
|
+
let(:set_item) { user_set.set_items.build(record_id: 10, position: 1) }
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
allow(user_set).to receive(:record) {double(:record, record_id: 4321)}
|
18
|
+
allow(user_set).to receive(:update_record)
|
19
|
+
end
|
20
|
+
|
21
|
+
context "validations" do
|
22
|
+
it "should not be valid without a record_id" do
|
23
|
+
set_item.record_id = nil
|
24
|
+
expect(set_item).to_not be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not be valid when record_id is not a number" do
|
28
|
+
set_item.record_id = "abc"
|
29
|
+
expect(set_item).to_not be_valid
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be valid when the record_id is a number in string format" do
|
33
|
+
set_item.record_id = "1234"
|
34
|
+
expect(set_item.record_id).to eq 1234
|
35
|
+
expect(set_item).to be_valid
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not be valid when the record_id already exists in another set item" do
|
39
|
+
user_set.set_items.build(record_id: 2, position: 1)
|
40
|
+
user_set.save
|
41
|
+
set_item = user_set.set_items.build(record_id: 2, position: 2)
|
42
|
+
expect(set_item).to_not be_valid
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not be valid when trying to add a set to itself" do
|
46
|
+
allow(user_set).to receive(:record) {double(:record, record_id: 1234)}
|
47
|
+
user_set.set_items.build(record_id: 1234, position: 1)
|
48
|
+
set_item = user_set.set_items.first
|
49
|
+
expect(set_item).to_not be_valid
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should allow set_item to be added to user_set without an associated Record" do
|
53
|
+
allow(user_set).to receive(:record)
|
54
|
+
user_set.set_items.build(record_id: 1234, position: 1)
|
55
|
+
set_item = user_set.set_items.first
|
56
|
+
expect(set_item).to be_valid
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "callbacks" do
|
61
|
+
it "calls set_position before_validation" do
|
62
|
+
set_item = user_set.set_items.build(record_id: 20)
|
63
|
+
expect(set_item).to receive(:set_position)
|
64
|
+
set_item.save
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "delegates record fields to the :record object" do
|
69
|
+
set_item.record = FactoryGirl.create(:record, record_id: 5)
|
70
|
+
set_item.record.fragments.create(name: "Ben", address: "Wellington")
|
71
|
+
set_item.record.save
|
72
|
+
|
73
|
+
expect(set_item.name).to eq "Ben"
|
74
|
+
expect(set_item.address).to eq "Wellington"
|
75
|
+
end
|
76
|
+
|
77
|
+
it "returns nil for any record field if the record doesn't exist" do
|
78
|
+
[:name, :address].each do |attr|
|
79
|
+
expect(set_item.send(attr)).to be_nil
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#set_position" do
|
84
|
+
context "with a set item" do
|
85
|
+
before(:each) do
|
86
|
+
user_set.set_items.build(record_id: 1, position: 1)
|
87
|
+
user_set.save
|
88
|
+
end
|
89
|
+
|
90
|
+
it "positions the set item at the end" do
|
91
|
+
set_item = user_set.set_items.build(record_id: 2)
|
92
|
+
set_item.set_position
|
93
|
+
expect(set_item.position).to eq 2
|
94
|
+
end
|
95
|
+
|
96
|
+
it "doesn't override the position when already set" do
|
97
|
+
set_item = user_set.set_items.build(record_id: 2, position: 4)
|
98
|
+
set_item.set_position
|
99
|
+
expect(set_item.position).to eq 4
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "without set items" do
|
104
|
+
it "sets the position to 1" do
|
105
|
+
set_item = user_set.set_items.build(record_id: 2)
|
106
|
+
set_item.set_position
|
107
|
+
expect(set_item.position).to eq 1
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#reindex_record" do
|
113
|
+
let(:record) {double(:record)}
|
114
|
+
|
115
|
+
it "finds the record and calls index" do
|
116
|
+
expect(Record).to receive(:custom_find).with(set_item.record_id) {record}
|
117
|
+
expect(record).to receive(:index)
|
118
|
+
set_item.reindex_record
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
describe Source do
|
12
|
+
|
13
|
+
describe '.suppressed' do
|
14
|
+
let!(:active_source) { FactoryGirl.create(:source, status: 'active') }
|
15
|
+
let!(:suppressed_source) { FactoryGirl.create(:source, status: 'suppressed') }
|
16
|
+
|
17
|
+
it 'should return all the suppressed sources' do
|
18
|
+
expect(Source.suppressed.to_a).to eq [suppressed_source]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,216 @@
|
|
1
|
+
# The majority of the Supplejack API code is Crown copyright (C) 2014, New Zealand Government,
|
2
|
+
# and is licensed under the GNU General Public License, version 3.
|
3
|
+
# One component is a third party component. See https://github.com/DigitalNZ/supplejack_api for details.
|
4
|
+
#
|
5
|
+
# Supplejack was created by DigitalNZ at the National Library of NZ and
|
6
|
+
# the Department of Internal Affairs. http://digitalnz.org/supplejack
|
7
|
+
|
8
|
+
require 'spec_helper'
|
9
|
+
|
10
|
+
module SupplejackApi
|
11
|
+
module Support
|
12
|
+
describe FragmentHelpers do
|
13
|
+
let(:record) { FactoryGirl.build(:record_with_fragment, record_id: 1234) }
|
14
|
+
|
15
|
+
describe '#before_save' do
|
16
|
+
it 'should call merge_fragments' do
|
17
|
+
expect(record).to receive(:merge_fragments)
|
18
|
+
record.save
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "valiations" do
|
23
|
+
it "should be valid" do
|
24
|
+
expect(record).to be_valid
|
25
|
+
end
|
26
|
+
|
27
|
+
context "duplicate source_ids" do
|
28
|
+
before do
|
29
|
+
record.fragments << FactoryGirl.build(:record_fragment, source_id: 'source_name')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not be valid" do
|
33
|
+
expect(record).to_not be_valid
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#source_ids" do
|
39
|
+
it "should return an array with a single source_id" do
|
40
|
+
expect(record.source_ids).to eq ['source_name']
|
41
|
+
end
|
42
|
+
|
43
|
+
context "multiple fragments" do
|
44
|
+
before do
|
45
|
+
record.fragments << FactoryGirl.build(:record_fragment, source_id: 'another_source')
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return an array with the source_ids" do
|
49
|
+
expect(record.source_ids).to eq ['source_name', "another_source"]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#duplicate_source_ids?" do
|
55
|
+
it "should return false" do
|
56
|
+
expect(record.duplicate_source_ids?).to be_falsey
|
57
|
+
end
|
58
|
+
|
59
|
+
context "duplicate source_ids" do
|
60
|
+
before do
|
61
|
+
record.fragments << FactoryGirl.build(:record_fragment, source_id: 'source_name')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return true" do
|
65
|
+
expect(record.duplicate_source_ids?).to be_truthy
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#primary_fragment' do
|
71
|
+
let(:record) { FactoryGirl.build(:record) }
|
72
|
+
before { record.save }
|
73
|
+
|
74
|
+
it 'returns the fragment with priority 0' do
|
75
|
+
fragment1 = record.fragments.create(name: 'John', priority: 1)
|
76
|
+
fragment0 = record.fragments.create(name: 'John', priority: 0)
|
77
|
+
expect(record.primary_fragment).to eq fragment0
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns a new fragment with priority 0' do
|
81
|
+
expect(record.primary_fragment).to be_a ApiRecord::RecordFragment
|
82
|
+
expect(record.primary_fragment.priority).to eq 0
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should build a primary fragment with default attributes' do
|
86
|
+
expect(record.primary_fragment(name: 'John').name).to eq 'John'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'merge_fragments' do
|
91
|
+
let(:record) { FactoryGirl.build(:record_with_fragment) }
|
92
|
+
let(:primary) { record.fragments.first }
|
93
|
+
let(:secondary) { record.fragments.last }
|
94
|
+
|
95
|
+
it 'should delete any existing merged fragment' do
|
96
|
+
record.merged_fragment = FactoryGirl.build(:record_fragment)
|
97
|
+
record.save
|
98
|
+
expect(record.merged_fragment).to be_nil
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'one fragment' do
|
102
|
+
it 'should not save the merged fragment' do
|
103
|
+
record.merge_fragments
|
104
|
+
expect(record.merged_fragment).to be_nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context 'multiple fragments' do
|
109
|
+
before(:each) do
|
110
|
+
record.fragments << FactoryGirl.build(:record_fragment, name: 'James Smith', email: ['jamessmith@example.com'], source_id: 'another_source')
|
111
|
+
record.save!
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'unsets the priority field' do
|
115
|
+
record.save
|
116
|
+
expect(record.merged_fragment.priority).to be_nil
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'single value fields' do
|
120
|
+
it 'should store the first non-nil value of the field' do
|
121
|
+
primary.name = nil
|
122
|
+
record.save
|
123
|
+
expect(record.merged_fragment.name).to eq 'James Smith'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context 'multi-value fields' do
|
128
|
+
it 'should store the merged values of the field' do
|
129
|
+
expect(record.merged_fragment.email).to eq ['johndoe@example.com', 'jamessmith@example.com']
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should not return duplicate values' do
|
133
|
+
primary.email = ['johndoe@example.com', 'jamessmith@example.com']
|
134
|
+
record.save
|
135
|
+
expect(record.merged_fragment.email).to eq ['johndoe@example.com', 'jamessmith@example.com']
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should not return nil values' do
|
139
|
+
secondary.email = nil
|
140
|
+
record.save
|
141
|
+
expect(record.merged_fragment.email).to eq ['johndoe@example.com']
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#method_missing' do
|
148
|
+
let(:record) { FactoryGirl.create(:record_with_fragment) }
|
149
|
+
|
150
|
+
context 'no fragments' do
|
151
|
+
let(:record) { FactoryGirl.create(:record) }
|
152
|
+
|
153
|
+
it 'should return nil' do
|
154
|
+
expect(record.nz_citizen).to be_nil
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'single fragment' do
|
159
|
+
it 'should return a single value field from merged_fragment' do
|
160
|
+
expect(record.name).to eq 'John Doe'
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'returns an array for an empty mutli-value field' do
|
164
|
+
expect(record.contact).to eq []
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'multiple fragments' do
|
169
|
+
before(:each) do
|
170
|
+
record.fragments << FactoryGirl.build(:record_fragment, email: ['jamessmith@example.com'], source_id: 'another_source')
|
171
|
+
record.save!
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should return a single value field from merged_fragment' do
|
175
|
+
expect(record.name).to eq 'John Doe'
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should return the multi-value field values from merged_fragment' do
|
179
|
+
expect(record.email).to eq ['johndoe@example.com', 'jamessmith@example.com']
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
# context "namespaced field names" do
|
184
|
+
# it "should translate namespaced field names into their stored field name" do
|
185
|
+
# record.fragments.first.stub(:dc_name) { 'Joe Bloggs' }
|
186
|
+
# record.public_send(:'dc:name')).to eq 'Joe Bloggs'
|
187
|
+
# end
|
188
|
+
# end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe '#sorted_fragments' do
|
192
|
+
it 'returns a list of fragments sorted by priority' do
|
193
|
+
record.fragments.build(priority: 10)
|
194
|
+
record.fragments.build(priority: -1)
|
195
|
+
record.fragments.build(priority: 5)
|
196
|
+
|
197
|
+
expect(record.sorted_fragments.map(&:priority)).to eq [-1,0,5,10]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '#find_fragment' do
|
202
|
+
before { record.save }
|
203
|
+
|
204
|
+
let!(:fragment) { record.fragments.create(source_id: 'thumbnails_enrichment') }
|
205
|
+
|
206
|
+
it 'should find a fragment by source_id' do
|
207
|
+
expect(record.find_fragment('thumbnails_enrichment')).to eq fragment
|
208
|
+
end
|
209
|
+
|
210
|
+
it "should return nil when it doesn't find a fragment" do
|
211
|
+
expect(record.find_fragment('nlnzcat')).to be_nil
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|