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,15 @@
|
|
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 Fragment do
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,103 @@
|
|
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 SiteActivity do
|
12
|
+
|
13
|
+
let(:user) { create(:user) }
|
14
|
+
|
15
|
+
context 'validations' do
|
16
|
+
it 'should be invalid when there is a existing site_activity with the same date' do
|
17
|
+
SupplejackApi::SiteActivity.create(date: Date.today)
|
18
|
+
expect(SupplejackApi::SiteActivity.new(date: Date.today)).to_not be_valid
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.generate_activity' do
|
23
|
+
['user_sets', 'search', 'records'].each do |field|
|
24
|
+
it 'agregates #{field} totals across all users' do
|
25
|
+
create(:user_activity, user_id: user.id, field.to_sym => {'total' => 10})
|
26
|
+
create(:user_activity, user_id: user.id, field.to_sym => {'total' => 5})
|
27
|
+
|
28
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity
|
29
|
+
expect(site_activity.send(field)).to eq 15
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'only agregates user activities from the last 12 hours' do
|
34
|
+
create(:user_activity, user_id: user.id, :search => {'total' => 10}, created_at: Time.now-14.hours)
|
35
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity
|
36
|
+
expect(site_activity.search).to eq 0
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'stores yesterday\'s date' do
|
40
|
+
Timecop.freeze(Time.now) do
|
41
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity
|
42
|
+
expect(site_activity.date).to eq Time.now.to_date
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'adds up a grand total' do
|
47
|
+
create(:user_activity, user_id: user.id, :records => {'total' => 10})
|
48
|
+
create(:user_activity, user_id: user.id, :user_sets => {'total' => 5})
|
49
|
+
|
50
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity
|
51
|
+
expect(site_activity.total).to eq 15
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'specify a date in the past' do
|
55
|
+
before do
|
56
|
+
create(:user_activity, user_id: user.id, :records => {'total' => 10}, created_at: Time.now - 26.hours)
|
57
|
+
create(:user_activity, user_id: user.id, :user_sets => {'total' => 5}, created_at: Time.now - 28.hours)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'generates the site activity for a day in the past' do
|
61
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity(Time.now-24.hours)
|
62
|
+
expect(site_activity.total).to eq 15
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should add up user activity created after the date' do
|
66
|
+
create(:user_activity, user_id: user.id, :records => {'total' => 2}, created_at: Time.now)
|
67
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity(Time.now-24.hours)
|
68
|
+
expect(site_activity.total).to eq 15
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should add source_clicks from SourceActivity to total and reset SourceActivity' do
|
72
|
+
allow(SourceActivity).to receive(:get_source_clicks) { 2 }
|
73
|
+
expect(SupplejackApi::SourceActivity).to receive(:reset)
|
74
|
+
site_activity = SupplejackApi::SiteActivity.generate_activity
|
75
|
+
expect(site_activity.total).to eq 2
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#activities' do
|
81
|
+
it 'should return only the custom fields' do
|
82
|
+
expect(SupplejackApi::SiteActivity.activities).to_not include '_id'
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should include date' do
|
86
|
+
expect(SupplejackApi::SiteActivity.activities).to include 'date'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '#calculate_total' do
|
91
|
+
let(:site_activity) { SupplejackApi::SiteActivity.new }
|
92
|
+
|
93
|
+
it 'adds up the totals from every activity' do
|
94
|
+
site_activity.search = 1
|
95
|
+
site_activity.records = 2
|
96
|
+
site_activity.user_sets = 3
|
97
|
+
site_activity.source_clicks = 3
|
98
|
+
site_activity.calculate_total
|
99
|
+
expect(site_activity.total).to eq 9
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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 SourceActivity do
|
12
|
+
describe '#increment' do
|
13
|
+
context 'SourceActivity doesn\'t exist' do
|
14
|
+
it 'creates a SourceActivity with source activity of 1' do
|
15
|
+
SupplejackApi::SourceActivity.increment
|
16
|
+
expect(SupplejackApi::SourceActivity.get_source_clicks).to eq 1
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'SourceActivity exists' do
|
21
|
+
before {
|
22
|
+
SupplejackApi::SourceActivity.create(source_clicks: 12)
|
23
|
+
}
|
24
|
+
|
25
|
+
it 'increments source activity' do
|
26
|
+
SupplejackApi::SourceActivity.increment
|
27
|
+
expect(SupplejackApi::SourceActivity.get_source_clicks).to eq 13
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#get_source_clicks' do
|
33
|
+
it 'returns the source_clicks count if SourceActive exists' do
|
34
|
+
SupplejackApi::SourceActivity.increment
|
35
|
+
expect(SupplejackApi::SourceActivity.get_source_clicks).to eq 1
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns nil if no SourceActivity' do
|
39
|
+
expect(SupplejackApi::SourceActivity.get_source_clicks).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#reset' do
|
44
|
+
it 'deletes first instance of SourceActivity if exists' do
|
45
|
+
SupplejackApi::SourceActivity.increment
|
46
|
+
SupplejackApi::SourceActivity.reset
|
47
|
+
expect(SupplejackApi::SourceActivity.count).to be 0
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'handles no source activity' do
|
51
|
+
2.times { SupplejackApi::SourceActivity.reset }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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 SourceAuthority do
|
12
|
+
let(:source_authority) { create(:source_authority) }
|
13
|
+
|
14
|
+
subject { source_authority }
|
15
|
+
|
16
|
+
it { should be_stored_in :source_authorities }
|
17
|
+
it { should be_timestamped_document }
|
18
|
+
it { should be_timestamped_document.with(:created) }
|
19
|
+
it { should be_timestamped_document.with(:updated) }
|
20
|
+
|
21
|
+
it { should belong_to(:concept) }
|
22
|
+
|
23
|
+
describe 'fields' do
|
24
|
+
context '.model fields' do
|
25
|
+
%w(concept_type internal_identifier concept_score source_id source_name url).each do |field|
|
26
|
+
it "responds to #{field} field" do
|
27
|
+
expect(source_authority.respond_to?(field)).to be_truthy
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '.schema fields' do
|
33
|
+
ConceptSchema.fields.each do |name, field|
|
34
|
+
it "sets the #{name} field from the schema" do
|
35
|
+
expect(source_authority.respond_to?(name)).to be_truthy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,189 @@
|
|
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 ApiConcept
|
12
|
+
describe ConceptFragment do
|
13
|
+
|
14
|
+
# let!(:concept) { FactoryGirl.build(:concept, concept_id: 1234) }
|
15
|
+
# let!(:fragment) { concept.fragments.build(priority: 0) }
|
16
|
+
# let(:fragment_class) { ConceptFragment }
|
17
|
+
|
18
|
+
# before { concept.save }
|
19
|
+
|
20
|
+
# describe 'schema_class' do
|
21
|
+
# it 'should return ConceptSchema' do
|
22
|
+
# expect(ConceptFragment.schema_class).to eq ConceptSchema
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
|
26
|
+
# describe 'build_mongoid_schema' do
|
27
|
+
# before do
|
28
|
+
# allow(ConceptSchema).to receive(:fields) do
|
29
|
+
# {
|
30
|
+
# title: double(:field, name: :title, type: :string).as_null_object,
|
31
|
+
# count: double(:field, name: :count, type: :integer).as_null_object,
|
32
|
+
# date: double(:field, name: :date, type: :datetime).as_null_object,
|
33
|
+
# is_active: double(:field, name: :is_active, type: :boolean).as_null_object,
|
34
|
+
# subject: double(:field, name: :subject, type: :string, multi_value: true).as_null_object,
|
35
|
+
# sort_date: double(:field, name: :sort_date, type: :string, store: false).as_null_object,
|
36
|
+
# }
|
37
|
+
# end
|
38
|
+
# allow(fragment_class).to receive(:field)
|
39
|
+
|
40
|
+
# allow(ConceptSchema).to receive(:mongo_indexes) do
|
41
|
+
# {
|
42
|
+
# count_date: double(:mongo_index, name: :count_date, fields: [{ count: 1, date: 1 }], index_options: {background: true}).as_null_object
|
43
|
+
# }
|
44
|
+
# end
|
45
|
+
# allow(fragment_class).to receive(:mongo_indexes)
|
46
|
+
# end
|
47
|
+
|
48
|
+
# after do
|
49
|
+
# fragment_class.build_mongoid_schema
|
50
|
+
# end
|
51
|
+
|
52
|
+
# context 'creating fields' do
|
53
|
+
# it 'defines a string field' do
|
54
|
+
# expect(fragment_class).to receive(:field).with(:title, type: String)
|
55
|
+
# end
|
56
|
+
|
57
|
+
# it 'defines a integer field' do
|
58
|
+
# expect(fragment_class).to receive(:field).with(:count, type: Integer)
|
59
|
+
# end
|
60
|
+
|
61
|
+
# it 'defines a datetime field' do
|
62
|
+
# expect(fragment_class).to receive(:field).with(:date, type: DateTime)
|
63
|
+
# end
|
64
|
+
|
65
|
+
# it 'defines a boolean field' do
|
66
|
+
# expect(fragment_class).to receive(:field).with(:is_active, type: Boolean)
|
67
|
+
# end
|
68
|
+
|
69
|
+
# it 'defines a multivalue field' do
|
70
|
+
# expect(fragment_class).to receive(:field).with(:subject, type: Array)
|
71
|
+
# end
|
72
|
+
|
73
|
+
# it 'does not define a field with stored false' do
|
74
|
+
# expect(fragment_class).to_not receive(:field).with(:sort_date, anything)
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
|
78
|
+
# context 'creating indexes' do
|
79
|
+
# it 'should create a single field index' do
|
80
|
+
# expect(fragment_class).to receive(:index).with({:count=>1, :date=>1}, {:background=>true})
|
81
|
+
# end
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
|
85
|
+
# describe '.mutable_fields' do
|
86
|
+
# {description: String, sameAs: Array, dateOfDeath: DateTime}.each do |name, type|
|
87
|
+
# it 'should return a hash that includes the key #{name} and value #{type}' do
|
88
|
+
# expect(fragment_class.mutable_fields[name.to_s]).to eq type
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
|
92
|
+
# it 'should not include the source_id' do
|
93
|
+
# expect(fragment_class.mutable_fields).to_not have_key('source_id')
|
94
|
+
# end
|
95
|
+
|
96
|
+
# it 'should memoize the mutable_fields' do
|
97
|
+
# fragment_class.class_variable_set('@@mutable_fields', nil)
|
98
|
+
# expect(fragment_class).to receive(:fields).once.and_return({})
|
99
|
+
# fragment_class.mutable_fields
|
100
|
+
# fragment_class.mutable_fields
|
101
|
+
# fragment_class.class_variable_set('@@mutable_fields', nil)
|
102
|
+
# end
|
103
|
+
# end
|
104
|
+
|
105
|
+
# context 'default scope' do
|
106
|
+
# it 'should order the fragments from lower to higher priority' do
|
107
|
+
# fragment3 = concept.fragments.create(priority: 3)
|
108
|
+
# fragment1 = concept.fragments.create(priority: 1)
|
109
|
+
# fragment_1 = concept.fragments.create(priority: -1)
|
110
|
+
# concept.reload
|
111
|
+
# expect(concept.fragments.map(&:priority)).to eq [-1, 0, 1, 3]
|
112
|
+
# end
|
113
|
+
# end
|
114
|
+
|
115
|
+
# describe '#primary?' do
|
116
|
+
# it 'returns true when priority is 0' do
|
117
|
+
# fragment.priority = 0
|
118
|
+
# expect(fragment.primary?).to be_truthy
|
119
|
+
# end
|
120
|
+
|
121
|
+
# it 'returns false when priority is 1' do
|
122
|
+
# fragment.priority = 1
|
123
|
+
# expect(fragment.primary?).to be_falsey
|
124
|
+
# end
|
125
|
+
# end
|
126
|
+
|
127
|
+
# describe '#clear_attributes' do
|
128
|
+
# let(:concept) { FactoryGirl.create(:concept) }
|
129
|
+
# let(:fragment) { concept.fragments.create(gender: 'male') }
|
130
|
+
|
131
|
+
# it 'clears the existing gender' do
|
132
|
+
# fragment.clear_attributes
|
133
|
+
# expect(fragment.gender).to be_nil
|
134
|
+
# end
|
135
|
+
# end
|
136
|
+
|
137
|
+
# describe '#update_from_harvest' do
|
138
|
+
# it 'updates the label with the value' do
|
139
|
+
# fragment.update_from_harvest({label: 'John Smith'})
|
140
|
+
# expect(fragment.label).to eq 'John Smith'
|
141
|
+
# end
|
142
|
+
|
143
|
+
# it 'handles nil values' do
|
144
|
+
# fragment.update_from_harvest(nil)
|
145
|
+
# end
|
146
|
+
|
147
|
+
# it 'ignores invalid fields' do
|
148
|
+
# fragment.update_from_harvest({invalid_field: 'http://yahoo.com'})
|
149
|
+
# expect(fragment['invalid_field']).to be_nil
|
150
|
+
# end
|
151
|
+
|
152
|
+
# it 'stores uniq values for each field' do
|
153
|
+
# fragment.update_from_harvest({isRelatedTo: ['Jim', 'Bob', 'Jim']})
|
154
|
+
# expect(fragment.isRelatedTo).to eq ['Jim', 'Bob']
|
155
|
+
# end
|
156
|
+
|
157
|
+
# it 'updates the updated_at even if the attributes didn\'t change' do
|
158
|
+
# new_time = Time.now + 1.day
|
159
|
+
# Timecop.freeze(new_time) do
|
160
|
+
# fragment.update_from_harvest({})
|
161
|
+
# expect(fragment.updated_at.to_i).to eq(new_time.to_i)
|
162
|
+
# end
|
163
|
+
# end
|
164
|
+
|
165
|
+
# it 'uses the attribute setters for strings' do
|
166
|
+
# expect(fragment).to receive('label=').with('John Smith')
|
167
|
+
# fragment.update_from_harvest({:label => 'John Smith'})
|
168
|
+
# end
|
169
|
+
|
170
|
+
# it 'uses the attribute setters for Arrays' do
|
171
|
+
# expect(fragment).to receive('isRelatedTo=').with(['Jim', 'Bob'])
|
172
|
+
# fragment.update_from_harvest({:isRelatedTo => ['Jim', 'Bob']})
|
173
|
+
# end
|
174
|
+
|
175
|
+
# it 'stores the first element in the array for non array fields' do
|
176
|
+
# fragment.update_from_harvest({label: ['John Smith', 'Jim Bob']})
|
177
|
+
# expect(fragment.label).to eq 'John Smith'
|
178
|
+
# end
|
179
|
+
|
180
|
+
# it 'should set the source_id' do
|
181
|
+
# fragment.update_from_harvest({source_id: ['census']})
|
182
|
+
# expect(fragment.source_id).to eq 'census'
|
183
|
+
# end
|
184
|
+
# end
|
185
|
+
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,189 @@
|
|
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 ApiRecord
|
12
|
+
describe RecordFragment do
|
13
|
+
|
14
|
+
let!(:record) { FactoryGirl.build(:record, record_id: 1234) }
|
15
|
+
let!(:fragment) { record.fragments.build(priority: 0) }
|
16
|
+
let(:fragment_class) { RecordFragment }
|
17
|
+
|
18
|
+
before { record.save }
|
19
|
+
|
20
|
+
describe 'schema_class' do
|
21
|
+
it 'should return RecordSchema' do
|
22
|
+
expect(RecordFragment.schema_class).to eq RecordSchema
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'build_mongoid_schema' do
|
27
|
+
before do
|
28
|
+
allow(RecordSchema).to receive(:fields) do
|
29
|
+
{
|
30
|
+
title: double(:field, name: :title, type: :string).as_null_object,
|
31
|
+
count: double(:field, name: :count, type: :integer).as_null_object,
|
32
|
+
date: double(:field, name: :date, type: :datetime).as_null_object,
|
33
|
+
is_active: double(:field, name: :is_active, type: :boolean).as_null_object,
|
34
|
+
subject: double(:field, name: :subject, type: :string, multi_value: true).as_null_object,
|
35
|
+
sort_date: double(:field, name: :sort_date, type: :string, store: false).as_null_object,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
allow(fragment_class).to receive(:field)
|
39
|
+
|
40
|
+
allow(RecordSchema).to receive(:mongo_indexes) do
|
41
|
+
{
|
42
|
+
count_date: double(:mongo_index, name: :count_date, fields: [{ count: 1, date: 1 }], index_options: {background: true}).as_null_object
|
43
|
+
}
|
44
|
+
end
|
45
|
+
allow(fragment_class).to receive(:mongo_indexes)
|
46
|
+
end
|
47
|
+
|
48
|
+
after do
|
49
|
+
fragment_class.build_mongoid_schema
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'creating fields' do
|
53
|
+
it 'defines a string field' do
|
54
|
+
expect(fragment_class).to receive(:field).with(:title, type: String)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'defines a integer field' do
|
58
|
+
expect(fragment_class).to receive(:field).with(:count, type: Integer)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'defines a datetime field' do
|
62
|
+
expect(fragment_class).to receive(:field).with(:date, type: DateTime)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'defines a boolean field' do
|
66
|
+
expect(fragment_class).to receive(:field).with(:is_active, type: Boolean)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'defines a multivalue field' do
|
70
|
+
expect(fragment_class).to receive(:field).with(:subject, type: Array)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not define a field with stored false' do
|
74
|
+
expect(fragment_class).to_not receive(:field).with(:sort_date, anything)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'creating indexes' do
|
79
|
+
it 'should create a single field index' do
|
80
|
+
expect(fragment_class).to receive(:index).with({:count=>1, :date=>1}, {:background=>true})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '.mutable_fields' do
|
86
|
+
{name: String, email: Array, nz_citizen: Boolean}.each do |name, type|
|
87
|
+
it 'should return a hash that includes the key #{name} and value #{type}' do
|
88
|
+
type = Mongoid::Boolean if type == Boolean
|
89
|
+
expect(fragment_class.mutable_fields[name.to_s]).to eq type
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should not include the source_id' do
|
94
|
+
expect(fragment_class.mutable_fields).to_not have_key('source_id')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should memoize the mutable_fields' do
|
98
|
+
fragment_class.class_variable_set('@@mutable_fields', nil)
|
99
|
+
allow(fragment_class).to receive(:fields).once.and_return({})
|
100
|
+
fragment_class.mutable_fields
|
101
|
+
fragment_class.mutable_fields
|
102
|
+
fragment_class.class_variable_set('@@mutable_fields', nil)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'default scope' do
|
107
|
+
it 'should order the fragments from lower to higher priority' do
|
108
|
+
fragment3 = record.fragments.create(priority: 3)
|
109
|
+
fragment1 = record.fragments.create(priority: 1)
|
110
|
+
fragment_1 = record.fragments.create(priority: -1)
|
111
|
+
record.reload
|
112
|
+
expect(record.fragments.map(&:priority)).to eq [-1, 0, 1, 3]
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#primary?' do
|
117
|
+
it 'returns true when priority is 0' do
|
118
|
+
fragment.priority = 0
|
119
|
+
expect(fragment.primary?).to be_truthy
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'returns false when priority is 1' do
|
123
|
+
fragment.priority = 1
|
124
|
+
expect(fragment.primary?).to be_falsey
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#clear_attributes' do
|
129
|
+
let(:record) { FactoryGirl.create(:record) }
|
130
|
+
let(:fragment) { record.fragments.create(nz_citizen: true) }
|
131
|
+
|
132
|
+
it 'clears the existing nz_citizen' do
|
133
|
+
fragment.clear_attributes
|
134
|
+
expect(fragment.nz_citizen).to be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
describe '#update_from_harvest' do
|
139
|
+
it 'updates the name with the value' do
|
140
|
+
fragment.update_from_harvest({name: 'John Smith'})
|
141
|
+
expect(fragment.name).to eq 'John Smith'
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'handles nil values' do
|
145
|
+
fragment.update_from_harvest(nil)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'ignores invalid fields' do
|
149
|
+
fragment.update_from_harvest({invalid_field: 'http://yahoo.com'})
|
150
|
+
expect(fragment['invalid_field']).to be_nil
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'stores uniq values for each field' do
|
154
|
+
fragment.update_from_harvest({children: ['Jim', 'Bob', 'Jim']})
|
155
|
+
expect(fragment.children).to eq ['Jim', 'Bob']
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'updates the updated_at even if the attributes didn\'t change' do
|
159
|
+
new_time = Time.now + 1.day
|
160
|
+
Timecop.freeze(new_time) do
|
161
|
+
fragment.update_from_harvest({})
|
162
|
+
expect(fragment.updated_at.to_i).to eq(new_time.to_i)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'uses the attribute setters for strings' do
|
167
|
+
allow(fragment).to receive('name=').with('John Smith')
|
168
|
+
fragment.update_from_harvest({:name => 'John Smith'})
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'uses the attribute setters for Arrays' do
|
172
|
+
allow(fragment).to receive('children=').with(['Jim', 'Bob'])
|
173
|
+
fragment.update_from_harvest({:children => ['Jim', 'Bob']})
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'stores the first element in the array for non array fields' do
|
177
|
+
fragment.update_from_harvest({name: ['John Smith', 'Jim Bob']})
|
178
|
+
expect(fragment.name).to eq 'John Smith'
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'should set the source_id' do
|
182
|
+
fragment.update_from_harvest({source_id: ['census']})
|
183
|
+
expect(fragment.source_id).to eq 'census'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|