supplejack_api 1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SupplejackApi
|
4
|
+
describe MetricsApiController, type: :controller do
|
5
|
+
routes { SupplejackApi::Engine.routes }
|
6
|
+
|
7
|
+
def build_models
|
8
|
+
5.times do |n|
|
9
|
+
create(:daily_item_metric, date: Date.current - n.days)
|
10
|
+
create(:faceted_metrics, date: Date.current - n.days)
|
11
|
+
create(:usage_metrics, created_at: Date.current - n.days)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'GET root' do
|
16
|
+
context "succesful requests" do
|
17
|
+
after do
|
18
|
+
expect(response.body).to match_response_schema('metrics/extended_response')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'retrieves a range of extended metrics, filtered against the facet parameter' do
|
22
|
+
create(:faceted_metrics, name: 'dc1', date: Date.yesterday)
|
23
|
+
create(:faceted_metrics, name: 'dc2', date: Date.yesterday)
|
24
|
+
create(:usage_metrics, record_field_value: 'dc1', date: Date.yesterday)
|
25
|
+
create(:usage_metrics, date: Date.yesterday)
|
26
|
+
|
27
|
+
get :root, version: 'v3', facets: 'dc1', start_date: Date.yesterday, end_date: Date.yesterday
|
28
|
+
json = JSON.parse(response.body)
|
29
|
+
|
30
|
+
expect(json.first['record'].count).to eq(1)
|
31
|
+
expect(json.first['view'].count).to eq(1)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "failure requests" do
|
36
|
+
it 'responds with a 400 status if the facets parameter is missing' do
|
37
|
+
get :root, version: 'v3'
|
38
|
+
|
39
|
+
expect(response.status).to eq(400)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'responds with a 400 status if the number of facets requested is greater than 10' do
|
43
|
+
get :root, version: 'v3', facets: '1,2,3,4,5,6,7,8,9,10,11'
|
44
|
+
|
45
|
+
expect(response.status).to eq(400)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'GET facets' do
|
51
|
+
before do
|
52
|
+
allow(SupplejackApi::FacetsHelper).to receive(:get_list_of_facet_values).with(any_args).and_return([
|
53
|
+
'1', '2', '3', '4', '5'
|
54
|
+
])
|
55
|
+
end
|
56
|
+
|
57
|
+
after do
|
58
|
+
expect(response.body).to match_response_schema('metrics/facets_response')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'responds with a list of all facets' do
|
62
|
+
5.times{create(:faceted_metrics)}
|
63
|
+
|
64
|
+
get :facets, version: 'v3'
|
65
|
+
json = JSON.parse(response.body)
|
66
|
+
|
67
|
+
expect(json.length).to eq(5)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,77 @@
|
|
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 PartnersController, type: :controller do
|
12
|
+
routes { SupplejackApi::Engine.routes }
|
13
|
+
|
14
|
+
describe "POST 'create'" do
|
15
|
+
it "creates a new partner" do
|
16
|
+
expect(Partner).to receive(:create).with("name" => "Statistics New Zealand").and_call_original
|
17
|
+
post :create, partner: FactoryGirl.attributes_for(:partner)
|
18
|
+
expect(response).to be_success
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns the partner" do
|
22
|
+
post :create, partner: FactoryGirl.attributes_for(:partner)
|
23
|
+
expect(response.body).to include Partner.last.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
context "partner already exists" do
|
27
|
+
it "updates the partner" do
|
28
|
+
partner = FactoryGirl.create(:partner, name: 'partner1')
|
29
|
+
post :create, partner: {_id: partner.id, name: 'partner2'}
|
30
|
+
partner.reload
|
31
|
+
expect(partner.name).to eq 'partner2'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "GET 'show'" do
|
37
|
+
let(:partner) { FactoryGirl.create(:partner) }
|
38
|
+
|
39
|
+
it "finds the partner" do
|
40
|
+
expect(Partner).to receive(:find).with("1")
|
41
|
+
get :show, id: 1
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the partner" do
|
45
|
+
allow(Partner).to receive(:find) {partner}
|
46
|
+
get :show, id: 1
|
47
|
+
expect(response.body).to eq partner.to_json
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "GET 'index'" do
|
52
|
+
let(:partners) { [FactoryGirl.create(:partner),
|
53
|
+
FactoryGirl.create(:partner, name: "Down to the wire")] }
|
54
|
+
|
55
|
+
it "finds all partners" do
|
56
|
+
expect(Partner).to receive(:all) {partners}
|
57
|
+
get :index
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns the partners as a JSON array" do
|
61
|
+
allow(Partner).to receive(:all) {partners}
|
62
|
+
get :index
|
63
|
+
expect(response.body).to eq({partners: partners}.to_json)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "PUT 'update'" do
|
68
|
+
let(:partner) { FactoryGirl.create(:partner) }
|
69
|
+
|
70
|
+
it "finds and updates the partner" do
|
71
|
+
expect(Partner).to receive(:find).with(partner.id.to_s) {partner}
|
72
|
+
expect(partner).to receive(:update_attributes).with("name" => 'Down to the wire')
|
73
|
+
put :update, id: partner.id, partner: {name: 'Down to the wire'}
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,143 @@
|
|
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 RecordsController, type: :controller do
|
12
|
+
routes { SupplejackApi::Engine.routes }
|
13
|
+
|
14
|
+
before {
|
15
|
+
@user = FactoryGirl.create(:user, authentication_token: 'apikey', role: 'developer')
|
16
|
+
}
|
17
|
+
|
18
|
+
describe 'GET index' do
|
19
|
+
before {
|
20
|
+
@search = RecordSearch.new
|
21
|
+
allow(@search).to receive(:valid?) { true }
|
22
|
+
allow(RecordSearch).to receive(:new) {@search}
|
23
|
+
}
|
24
|
+
|
25
|
+
it 'should initialize a new search instance' do
|
26
|
+
allow_any_instance_of(RecordSearch).to receive(:valid?) { false }
|
27
|
+
expect(RecordSearch).to receive(:new).with(hash_including(text: 'dogs')).and_return(@search)
|
28
|
+
get :index, api_key: 'apikey', text: "dogs", format: "json"
|
29
|
+
expect(assigns(:search)).to eq(@search)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should set the request url on search object' do
|
33
|
+
allow_any_instance_of(RecordSearch).to receive(:valid?) { false }
|
34
|
+
allow(controller.request).to receive(:original_url).and_return('http://foo.com/blah')
|
35
|
+
expect(@search).to receive(:request_url=).with('http://foo.com/blah')
|
36
|
+
get :index, api_key: 'apikey', format: "json"
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should set the current_user on the search' do
|
40
|
+
allow_any_instance_of(RecordSearch).to receive(:valid?) { false }
|
41
|
+
expect(@search).to receive(:scope=).with(@user)
|
42
|
+
get :index, api_key: 'apikey', format: "json"
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'renders a the solr error when the query is invalid' do
|
46
|
+
allow(RecordSearchSerializer).to receive(:new).and_raise(RSolr::Error::Http.new({}, {}))
|
47
|
+
allow(controller).to receive(:solr_error_message).and_return('Error')
|
48
|
+
get :index, api_key: 'apikey', format: 'json'
|
49
|
+
expect(response.body).to eq({errors: 'Error'}.to_json)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "renders a error when the requested field doesn't exist" do
|
53
|
+
allow(RecordSearchSerializer).to receive(:new).and_raise(Sunspot::UnrecognizedFieldError.new('No field configured for Record with name "something"'))
|
54
|
+
get :index, api_key: 'apikey', format: 'json', and: {:something => true}
|
55
|
+
expect(response.body).to eq({:errors => 'No field configured for Record with name "something"'}.to_json)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return an error if the search request is invalid' do
|
59
|
+
allow(@search).to receive(:valid?) { false }
|
60
|
+
allow(@search).to receive(:errors) { ['The page parameter can not exceed 100,000'] }
|
61
|
+
get :index, api_key: 'apikey', page: 100001, format: 'json'
|
62
|
+
expect(response.body).to eq({errors: ['The page parameter can not exceed 100,000']}.to_json)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'GET show' do
|
67
|
+
let(:developer_restriction) { double(:developer_restriction).as_null_object }
|
68
|
+
|
69
|
+
before(:each) do
|
70
|
+
@record = create(:record)
|
71
|
+
allow(controller).to receive(:current_user) { @user }
|
72
|
+
allow(RecordSchema).to receive(:roles) { {developer: developer_restriction} }
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should find the record and assign it' do
|
76
|
+
expect(Record).to receive(:custom_find).with('123', @user, {}).and_return(@record)
|
77
|
+
get :show, id: 123, search: {}, api_key: 'apikey', format: 'json'
|
78
|
+
expect(assigns(:record)).to eq(@record)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'renders a error when records is not found' do
|
82
|
+
allow(Record).to receive(:custom_find).and_raise(Mongoid::Errors::DocumentNotFound.new(Record, ['123'], ['123']))
|
83
|
+
get :show, id: 123, search: {}, api_key: 'apikey', format: 'json'
|
84
|
+
expect(response.body).to eq({:errors => 'Record with ID 123 was not found'}.to_json)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'merges the scope in the options' do
|
88
|
+
expect(Record).to receive(:custom_find).with('123', @user, {'and' => {'category' => 'Books'}}).and_return(@record)
|
89
|
+
get :show, id: 123, search: {and: {category: 'Books'}}, api_key: 'apikey', format: 'json'
|
90
|
+
expect(assigns(:record)).to eq(@record)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'GET multiple' do
|
95
|
+
let(:developer_restriction) { double(:developer_restriction).as_null_object }
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
@record = create(:record)
|
99
|
+
allow(controller).to receive(:current_user) { @user }
|
100
|
+
allow(RecordSchema).to receive(:roles) { {developer: developer_restriction} }
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should find multiple records and assign them' do
|
104
|
+
@records = [create(:record), create(:record)]
|
105
|
+
allow(Record).to receive(:find_multiple) { @records }
|
106
|
+
get :multiple, record_ids: [123, 124, 456], api_key: 'apikey', format: 'json'
|
107
|
+
expect(assigns(:records)).to eq(@records)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#default_serializer_options' do
|
112
|
+
before(:each) do
|
113
|
+
@search = RecordSearch.new
|
114
|
+
allow(RecordSearch).to receive(:new) { @search }
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should return a hash with info for serialization' do
|
118
|
+
controller.default_serializer_options
|
119
|
+
expect(assigns(:search)).to eq(@search)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should merge in the search fields' do
|
123
|
+
allow(@search).to receive(:field_list).and_return([:title, :description])
|
124
|
+
allow(@search).to receive(:group_list).and_return([:verbose])
|
125
|
+
expect(controller.default_serializer_options).to eq({fields: [:title, :description], groups: [:verbose]})
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#set_concept_param' do
|
130
|
+
it 'adds concept_id in the parameter' do
|
131
|
+
controller.params = { concept_id: 3 }
|
132
|
+
controller.send(:set_concept_param)
|
133
|
+
expect(controller.params[:and]).to eq({'concept_id' => 3})
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'merges concept_id with existing "and" parameter' do
|
137
|
+
controller.params = { concept_id: 3, and: { category: 'Category A' } }
|
138
|
+
controller.send(:set_concept_param)
|
139
|
+
expect(controller.params[:and]).to eq({'concept_id' => 3, 'category' => 'Category A'})
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,78 @@
|
|
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 SetItemsController, type: :controller do
|
12
|
+
routes { SupplejackApi::Engine.routes }
|
13
|
+
|
14
|
+
before {
|
15
|
+
@user = FactoryGirl.create(:user, authentication_token: "abc123")
|
16
|
+
allow(controller).to receive(:authenticate_user!) { true }
|
17
|
+
allow(controller).to receive(:current_user) { @user }
|
18
|
+
@user_set = FactoryGirl.create(:user_set_with_set_item)
|
19
|
+
@set_item = @user_set.set_items.first
|
20
|
+
allow(controller.current_user.user_sets).to receive(:custom_find) { @user_set }
|
21
|
+
allow(RecordSchema).to receive(:roles) { { developer: double(:developer) } }
|
22
|
+
}
|
23
|
+
|
24
|
+
describe "POST 'create'" do
|
25
|
+
it 'creates the set item through the @user_set' do
|
26
|
+
create(:record_with_fragment, record_id: 12345)
|
27
|
+
expect(@user_set.set_items).to receive(:build).with({'record_id' => '12345'}) { @set_item }
|
28
|
+
expect(@user_set).to receive(:save).and_return(true)
|
29
|
+
post :create, user_set_id: @user_set.id, record: { record_id: '12345' }, format: :json
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'Set Interactions' do
|
33
|
+
before do
|
34
|
+
@user = FactoryGirl.create(:user, authentication_token: "abc123", role: 'admin')
|
35
|
+
allow(controller).to receive(:current_user) { @user }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "creates a new Set Interaction model to log the interaction" do
|
39
|
+
create(:record_with_fragment, record_id: 12, display_collection: 'test')
|
40
|
+
|
41
|
+
post :create, user_set_id: @user_set.id, record: {record_id: 12}
|
42
|
+
|
43
|
+
expect(InteractionModels::Set.first).to be_present
|
44
|
+
expect(InteractionModels::Set.first.facet).to eq('test')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "DELETE 'destroy'" do
|
50
|
+
before(:each) do
|
51
|
+
allow(@user_set.set_items).to receive(:find_by_record_id) { @set_item }
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'finds the @set_item through the user_set' do
|
55
|
+
expect(@user_set.set_items).to receive(:find_by_record_id).with('12')
|
56
|
+
delete :destroy, user_set_id: @user_set.id, id: '12', format: :json
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'destroys the @set_item' do
|
60
|
+
expect(@set_item).to receive(:destroy)
|
61
|
+
delete :destroy, user_set_id: @user_set.id, id: '12', format: :json
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'it doesn\'t find the set_item' do
|
65
|
+
before(:each) do
|
66
|
+
allow(@user_set.set_items).to receive(:find_by_record_id) { nil }
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns a 404' do
|
70
|
+
delete :destroy, user_set_id: @user_set.id, id: '12'
|
71
|
+
expect(response.code).to eq '404'
|
72
|
+
expect(response.body).to eq({errors: 'The record with id: 12 was not found.'}.to_json)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,161 @@
|
|
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 SourcesController, type: :controller do
|
12
|
+
routes { SupplejackApi::Engine.routes }
|
13
|
+
|
14
|
+
let(:partner) { FactoryGirl.create(:partner) }
|
15
|
+
|
16
|
+
describe 'POST "create"' do
|
17
|
+
it 'creates a new source' do
|
18
|
+
expect(Source).to receive(:create).with('name' => 'Sample source', 'source_id' => '1234', "partner_id" => partner.id.to_s)
|
19
|
+
post :create, partner_id: partner, source: FactoryGirl.attributes_for(:source)
|
20
|
+
expect(response).to be_success
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns the source' do
|
24
|
+
post :create, partner_id: partner, source: FactoryGirl.attributes_for(:source)
|
25
|
+
partner.reload
|
26
|
+
expect(response.body).to include Source.last.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
context "source all ready exists" do
|
30
|
+
it "updates the source" do
|
31
|
+
source = partner.sources.create(FactoryGirl.attributes_for(:source, name: "source_1"))
|
32
|
+
post :create, partner_id: partner, source: {_id: source.id, name: 'source2'}
|
33
|
+
source.reload
|
34
|
+
expect(source.name).to eq 'source2'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'GET "show"' do
|
40
|
+
before(:each )do
|
41
|
+
Source.create(FactoryGirl.attributes_for(:source))
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'assigns the source' do
|
45
|
+
get :show, id: Source.last
|
46
|
+
expect(assigns(:source)).to eq Source.last
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns the source' do
|
50
|
+
get :show, id: Source.last
|
51
|
+
expect(response.body).to include Source.last.to_json
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'GET "index"' do
|
56
|
+
let(:sources) { [FactoryGirl.build(:source)] }
|
57
|
+
|
58
|
+
it 'assigns all sources' do
|
59
|
+
expect(Source).to receive(:all) { sources }
|
60
|
+
get :index
|
61
|
+
expect(assigns(:sources)).to eq sources
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns all sources' do
|
65
|
+
expect(Source).to receive(:all) { sources }
|
66
|
+
get :index
|
67
|
+
expect(response.body).to include sources.to_json
|
68
|
+
end
|
69
|
+
|
70
|
+
context "search" do
|
71
|
+
|
72
|
+
let(:suppressed_source) { FactoryGirl.build(:source) }
|
73
|
+
|
74
|
+
it "searches the sources if params source is defined" do
|
75
|
+
expect(Source).to receive(:where).with("status" => "suppressed") { [suppressed_source] }
|
76
|
+
get :index, source: { status: "suppressed" }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'PUT "update"' do
|
82
|
+
let(:source) { FactoryGirl.create(:source) }
|
83
|
+
|
84
|
+
it 'finds and update source' do
|
85
|
+
put :update, id: source.id, source: {status: "suppressed"}
|
86
|
+
expect(assigns(:source).status).to eq 'suppressed'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns the source' do
|
90
|
+
put :update,id: source.id, source: {status: "suppressed"}
|
91
|
+
expect(response.body).to include 'suppressed'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'GET "reindex"' do
|
96
|
+
|
97
|
+
before(:each) do
|
98
|
+
@source = Source.create(FactoryGirl.attributes_for(:source))
|
99
|
+
end
|
100
|
+
|
101
|
+
it "enqueues the job with the source_id and date if given" do
|
102
|
+
date = Time.now
|
103
|
+
expect(Resque).to receive(:enqueue).with(IndexSourceWorker, @source.source_id, date.to_s)
|
104
|
+
get :reindex, id: @source.id, date: date
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
describe 'GET "link_check_records"' do
|
110
|
+
let(:records) { [ double(:record, source_url: 'http://1'),
|
111
|
+
double(:record, source_url: 'http://2'),
|
112
|
+
double(:record, source_url: 'http://3'),
|
113
|
+
double(:record, source_url: 'http://4')] }
|
114
|
+
|
115
|
+
let(:source) { FactoryGirl.build(:source) }
|
116
|
+
|
117
|
+
before do
|
118
|
+
allow(controller).to receive(:first_two_records).with(anything,:oldest) {records[0..1]}
|
119
|
+
allow(controller).to receive(:first_two_records).with(anything,:latest) {records[2..3]}
|
120
|
+
allow(Source).to receive(:find) { source }
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should asign the oldest two records by syndication_date" do
|
124
|
+
expect(controller).to receive(:first_two_records).with(source.source_id,:oldest) {records[0..1]}
|
125
|
+
get :link_check_records, id: source.id
|
126
|
+
expect(assigns(:records)).to include('http://1', 'http://2')
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should asign the latest two records by syndication_date" do
|
130
|
+
expect(controller).to receive(:first_two_records).with(source.source_id,:latest) {records[2..3]}
|
131
|
+
get :link_check_records, id: source.id
|
132
|
+
expect(assigns(:records)).to include('http://3', 'http://4')
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#first_two_records" do
|
137
|
+
let(:asc_relation) {double(:asc_relation)}
|
138
|
+
let(:sorted_relation) {double(:sorted_relation)}
|
139
|
+
|
140
|
+
let(:records) { [ double(:record, source_url: 'http://1'),
|
141
|
+
double(:record, source_url: 'http://2'),
|
142
|
+
double(:record, source_url: 'http://3'),
|
143
|
+
double(:record, source_url: 'http://4')] }
|
144
|
+
|
145
|
+
before do
|
146
|
+
expect(Record).to receive(:where).with({"fragments.source_id" => "tapuhi", :status => 'active'}) { asc_relation }
|
147
|
+
expect(sorted_relation).to receive(:limit).with(2) { records[0..1] }
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should get the oldest two records by syndication_date" do
|
151
|
+
expect(asc_relation).to receive(:sort).with("fragments.syndication_date" => 1) { sorted_relation }
|
152
|
+
expect(controller.send(:first_two_records, 'tapuhi', :oldest)).to eq (records[0..1])
|
153
|
+
end
|
154
|
+
|
155
|
+
it "should get the latest two records by syndication_date" do
|
156
|
+
expect(asc_relation).to receive(:sort).with("fragments.syndication_date" => -1) { sorted_relation }
|
157
|
+
expect(controller.send(:first_two_records, 'tapuhi', :latest)).to eq (records[0..1])
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|