supplejack_api 1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (291) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +80 -0
  3. data/Rakefile +42 -0
  4. data/app/assets/javascripts/supplejack_api/application.js +26 -0
  5. data/app/assets/stylesheets/supplejack_api/application.css +30 -0
  6. data/app/controllers/supplejack_api/admin/base_controller.rb +24 -0
  7. data/app/controllers/supplejack_api/admin/sessions_controller.rb +25 -0
  8. data/app/controllers/supplejack_api/admin/site_activities_controller.rb +21 -0
  9. data/app/controllers/supplejack_api/admin/users_controller.rb +55 -0
  10. data/app/controllers/supplejack_api/application_controller.rb +70 -0
  11. data/app/controllers/supplejack_api/concepts_controller.rb +52 -0
  12. data/app/controllers/supplejack_api/concerns/ignore_metrics.rb +14 -0
  13. data/app/controllers/supplejack_api/concerns/records_controller_metrics.rb +26 -0
  14. data/app/controllers/supplejack_api/concerns/set_items_controller_metrics.rb +20 -0
  15. data/app/controllers/supplejack_api/concerns/user_sets_controller_metrics.rb +26 -0
  16. data/app/controllers/supplejack_api/harvester/concepts_controller.rb +41 -0
  17. data/app/controllers/supplejack_api/harvester/fragments_controller.rb +30 -0
  18. data/app/controllers/supplejack_api/harvester/records_controller.rb +68 -0
  19. data/app/controllers/supplejack_api/metrics_api_controller.rb +44 -0
  20. data/app/controllers/supplejack_api/partners_controller.rb +39 -0
  21. data/app/controllers/supplejack_api/records_controller.rb +71 -0
  22. data/app/controllers/supplejack_api/schema_controller.rb +19 -0
  23. data/app/controllers/supplejack_api/set_items_controller.rb +38 -0
  24. data/app/controllers/supplejack_api/sources_controller.rb +67 -0
  25. data/app/controllers/supplejack_api/status_controller.rb +67 -0
  26. data/app/controllers/supplejack_api/user_sets_controller.rb +97 -0
  27. data/app/controllers/supplejack_api/users_controller.rb +49 -0
  28. data/app/helpers/supplejack_api/application_helper.rb +39 -0
  29. data/app/helpers/supplejack_api/facets_helper.rb +30 -0
  30. data/app/mailers/supplejack_api/request_limit_mailer.rb +43 -0
  31. data/app/models/supplejack_api/api_concept/concept_fragment.rb +31 -0
  32. data/app/models/supplejack_api/api_record/record_fragment.rb +15 -0
  33. data/app/models/supplejack_api/concept.rb +46 -0
  34. data/app/models/supplejack_api/concept_search.rb +86 -0
  35. data/app/models/supplejack_api/concerns/queryable_by_date.rb +31 -0
  36. data/app/models/supplejack_api/concerns/record.rb +108 -0
  37. data/app/models/supplejack_api/concerns/record_fragmentable.rb +24 -0
  38. data/app/models/supplejack_api/concerns/searchable.rb +430 -0
  39. data/app/models/supplejack_api/concerns/user_set.rb +219 -0
  40. data/app/models/supplejack_api/daily_metrics.rb +20 -0
  41. data/app/models/supplejack_api/faceted_metrics.rb +55 -0
  42. data/app/models/supplejack_api/fragment.rb +82 -0
  43. data/app/models/supplejack_api/interaction_models/record.rb +60 -0
  44. data/app/models/supplejack_api/interaction_models/set.rb +13 -0
  45. data/app/models/supplejack_api/interaction_updaters/all_usage_metric.rb +41 -0
  46. data/app/models/supplejack_api/interaction_updaters/set_metrics.rb +32 -0
  47. data/app/models/supplejack_api/interaction_updaters/usage_metrics.rb +73 -0
  48. data/app/models/supplejack_api/partner.rb +24 -0
  49. data/app/models/supplejack_api/preview_record.rb +30 -0
  50. data/app/models/supplejack_api/record.rb +18 -0
  51. data/app/models/supplejack_api/record_search.rb +12 -0
  52. data/app/models/supplejack_api/schema_definition.rb +147 -0
  53. data/app/models/supplejack_api/search.rb +14 -0
  54. data/app/models/supplejack_api/set_item.rb +57 -0
  55. data/app/models/supplejack_api/site_activity.rb +59 -0
  56. data/app/models/supplejack_api/source.rb +28 -0
  57. data/app/models/supplejack_api/source_activity.rb +36 -0
  58. data/app/models/supplejack_api/source_authority.rb +42 -0
  59. data/app/models/supplejack_api/supplejack_schema.rb +37 -0
  60. data/app/models/supplejack_api/support/concept/searchable.rb +79 -0
  61. data/app/models/supplejack_api/support/concept/storable.rb +59 -0
  62. data/app/models/supplejack_api/support/fragment_helpers.rb +96 -0
  63. data/app/models/supplejack_api/support/harvestable.rb +105 -0
  64. data/app/models/supplejack_api/support/searchable.rb +115 -0
  65. data/app/models/supplejack_api/support/status_logger.rb +23 -0
  66. data/app/models/supplejack_api/support/storable.rb +49 -0
  67. data/app/models/supplejack_api/support/validation_logger.rb +23 -0
  68. data/app/models/supplejack_api/usage_metrics.rb +25 -0
  69. data/app/models/supplejack_api/user.rb +211 -0
  70. data/app/models/supplejack_api/user_activity.rb +65 -0
  71. data/app/models/supplejack_api/user_set.rb +17 -0
  72. data/app/serializers/supplejack_api/application_serializer.rb +12 -0
  73. data/app/serializers/supplejack_api/concept_record_serializer.rb +23 -0
  74. data/app/serializers/supplejack_api/concept_search_serializer.rb +12 -0
  75. data/app/serializers/supplejack_api/concept_serializer.rb +100 -0
  76. data/app/serializers/supplejack_api/concerns/record_serializable.rb +119 -0
  77. data/app/serializers/supplejack_api/concerns/search_serializable.rb +24 -0
  78. data/app/serializers/supplejack_api/record_search_serializer.rb +64 -0
  79. data/app/serializers/supplejack_api/record_serializer.rb +13 -0
  80. data/app/serializers/supplejack_api/search_serializer.rb +13 -0
  81. data/app/serializers/supplejack_api/source_authority_serializer.rb +23 -0
  82. data/app/serializers/supplejack_api/user_serializer.rb +13 -0
  83. data/app/serializers/supplejack_api/user_set_record_serializer.rb +14 -0
  84. data/app/serializers/supplejack_api/user_set_serializer.rb +77 -0
  85. data/app/services/metrics_api/v3/api.rb +30 -0
  86. data/app/services/metrics_api/v3/endpoints/facets.rb +23 -0
  87. data/app/services/metrics_api/v3/endpoints/global.rb +26 -0
  88. data/app/services/metrics_api/v3/endpoints/helpers.rb +14 -0
  89. data/app/services/metrics_api/v3/endpoints/root.rb +97 -0
  90. data/app/services/metrics_api/v3/presenters/daily_metric.rb +23 -0
  91. data/app/services/metrics_api/v3/presenters/extended_metadata.rb +41 -0
  92. data/app/services/metrics_api/v3/presenters/record.rb +26 -0
  93. data/app/services/metrics_api/v3/presenters/view.rb +28 -0
  94. data/app/views/layouts/supplejack_api/_head.html.erb +17 -0
  95. data/app/views/layouts/supplejack_api/_top_nav.html.erb +33 -0
  96. data/app/views/layouts/supplejack_api/application.html.erb +33 -0
  97. data/app/views/supplejack_api/admin/sessions/new.html.erb +25 -0
  98. data/app/views/supplejack_api/admin/shared/_links.erb +34 -0
  99. data/app/views/supplejack_api/admin/site_activities/index.csv.erb +22 -0
  100. data/app/views/supplejack_api/admin/site_activities/index.html.erb +54 -0
  101. data/app/views/supplejack_api/admin/users/edit.html.erb +16 -0
  102. data/app/views/supplejack_api/admin/users/index.csv.erb +22 -0
  103. data/app/views/supplejack_api/admin/users/index.html.erb +57 -0
  104. data/app/views/supplejack_api/admin/users/show.html.erb +33 -0
  105. data/app/views/supplejack_api/request_limit_mailer/at100percent.text.erb +13 -0
  106. data/app/views/supplejack_api/request_limit_mailer/at100percent_admin.text.erb +1 -0
  107. data/app/views/supplejack_api/request_limit_mailer/at90percent.text.erb +13 -0
  108. data/app/views/supplejack_api/request_limit_mailer/at90percent_admin.text.erb +1 -0
  109. data/app/workers/supplejack_api/daily_metrics_worker.rb +112 -0
  110. data/app/workers/supplejack_api/interaction_metrics_worker.rb +45 -0
  111. data/config/cucumber.yml +16 -0
  112. data/config/initializers/force_eagerload.rb +11 -0
  113. data/config/initializers/interaction_updaters.rb +7 -0
  114. data/config/routes.rb +81 -0
  115. data/db/binding_records.development.json +7 -0
  116. data/db/binding_records.staging.json +7 -0
  117. data/db/concepts.json +33 -0
  118. data/db/concepts_data.json +569745 -0
  119. data/db/source_authorities.json +119 -0
  120. data/lib/generators/supplejack_api/install_generator.rb +124 -0
  121. data/lib/mongoid/paperclip.rb +53 -0
  122. data/lib/mongoid/string.rb +20 -0
  123. data/lib/sunspot/mongoid.rb +51 -0
  124. data/lib/sunspot/resque_session_proxy.rb +72 -0
  125. data/lib/sunspot/sunspot_spellcheck.rb +98 -0
  126. data/lib/supplejack_api.rb +13 -0
  127. data/lib/supplejack_api/admin/sortable.rb +40 -0
  128. data/lib/supplejack_api/engine.rb +46 -0
  129. data/lib/supplejack_api/harvester_constraint.rb +28 -0
  130. data/lib/supplejack_api/stylesheets.rb +36 -0
  131. data/lib/supplejack_api/utils.rb +75 -0
  132. data/lib/supplejack_api/version.rb +11 -0
  133. data/lib/tasks/resque.rake +22 -0
  134. data/lib/url_validator.rb +38 -0
  135. data/spec/controllers/supplejack_api/admin/base_controller_spec.rb +55 -0
  136. data/spec/controllers/supplejack_api/admin/site_activities_controller_spec.rb +43 -0
  137. data/spec/controllers/supplejack_api/admin/users_controller_spec.rb +79 -0
  138. data/spec/controllers/supplejack_api/application_controller_spec.rb +133 -0
  139. data/spec/controllers/supplejack_api/concepts_controller_spec.rb +83 -0
  140. data/spec/controllers/supplejack_api/concerns/records_controller_metrics_spec.rb +60 -0
  141. data/spec/controllers/supplejack_api/harvester/concepts_controller_spec.rb +57 -0
  142. data/spec/controllers/supplejack_api/harvester/records_controller_spec.rb +138 -0
  143. data/spec/controllers/supplejack_api/metrics_api_controller_spec.rb +71 -0
  144. data/spec/controllers/supplejack_api/partners_controller_spec.rb +77 -0
  145. data/spec/controllers/supplejack_api/records_controller_spec.rb +143 -0
  146. data/spec/controllers/supplejack_api/set_items_controller_spec.rb +78 -0
  147. data/spec/controllers/supplejack_api/sources_controller_spec.rb +161 -0
  148. data/spec/controllers/supplejack_api/status_controller_spec.rb +120 -0
  149. data/spec/controllers/supplejack_api/user_sets_controller_spec.rb +233 -0
  150. data/spec/controllers/supplejack_api/users_controller_spec.rb +61 -0
  151. data/spec/dummy/README.rdoc +268 -0
  152. data/spec/dummy/Rakefile +7 -0
  153. data/spec/dummy/app/assets/javascripts/application.js +23 -0
  154. data/spec/dummy/app/assets/stylesheets/application.css +22 -0
  155. data/spec/dummy/app/controllers/application_controller.rb +10 -0
  156. data/spec/dummy/app/helpers/application_helper.rb +9 -0
  157. data/spec/dummy/app/supplejack_api/concept_schema.rb +83 -0
  158. data/spec/dummy/app/supplejack_api/record_schema.rb +64 -0
  159. data/spec/dummy/app/supplejack_api/record_schema.txt +66 -0
  160. data/spec/dummy/app/views/layouts/application.html.erb +23 -0
  161. data/spec/dummy/app/workers/supplejack_api/clear_index_buffer.rb +32 -0
  162. data/spec/dummy/app/workers/supplejack_api/flush_old_records_worker.rb +17 -0
  163. data/spec/dummy/app/workers/supplejack_api/index_buffer.rb +49 -0
  164. data/spec/dummy/app/workers/supplejack_api/index_source_worker.rb +39 -0
  165. data/spec/dummy/app/workers/supplejack_api/index_worker.rb +82 -0
  166. data/spec/dummy/app/workers/supplejack_api/store_user_activity_worker.rb +24 -0
  167. data/spec/dummy/config.ru +11 -0
  168. data/spec/dummy/config/application.rb +76 -0
  169. data/spec/dummy/config/application.yml +31 -0
  170. data/spec/dummy/config/application.yml.example +36 -0
  171. data/spec/dummy/config/boot.rb +17 -0
  172. data/spec/dummy/config/environment.rb +12 -0
  173. data/spec/dummy/config/environments/development.rb +42 -0
  174. data/spec/dummy/config/environments/production.rb +76 -0
  175. data/spec/dummy/config/environments/test.rb +46 -0
  176. data/spec/dummy/config/initializers/backtrace_silencers.rb +14 -0
  177. data/spec/dummy/config/initializers/devise.rb +214 -0
  178. data/spec/dummy/config/initializers/inflections.rb +22 -0
  179. data/spec/dummy/config/initializers/kaminari_config.rb +17 -0
  180. data/spec/dummy/config/initializers/mime_types.rb +12 -0
  181. data/spec/dummy/config/initializers/mongoid.rb +9 -0
  182. data/spec/dummy/config/initializers/quiet_logger.rb +23 -0
  183. data/spec/dummy/config/initializers/resque.rb +18 -0
  184. data/spec/dummy/config/initializers/secret_token.rb +14 -0
  185. data/spec/dummy/config/initializers/session_store.rb +15 -0
  186. data/spec/dummy/config/initializers/simple_form.rb +149 -0
  187. data/spec/dummy/config/initializers/simple_form_foundation.rb +33 -0
  188. data/spec/dummy/config/initializers/state_machine.rb +8 -0
  189. data/spec/dummy/config/initializers/sunspot.rb +32 -0
  190. data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
  191. data/spec/dummy/config/locales/devise.en.yml +63 -0
  192. data/spec/dummy/config/locales/en.yml +66 -0
  193. data/spec/dummy/config/locales/simple_form.en.yml +33 -0
  194. data/spec/dummy/config/mongoid.travis.yml +34 -0
  195. data/spec/dummy/config/mongoid.yml +36 -0
  196. data/spec/dummy/config/resque-pool.yml +18 -0
  197. data/spec/dummy/config/resque_schedule.yml +12 -0
  198. data/spec/dummy/config/routes.rb +11 -0
  199. data/spec/dummy/config/secrets.yml +8 -0
  200. data/spec/dummy/config/sunspot.yml +38 -0
  201. data/spec/dummy/db/concepts.json +37 -0
  202. data/spec/dummy/db/source_authorities.json +116 -0
  203. data/spec/dummy/public/404.html +35 -0
  204. data/spec/dummy/public/422.html +35 -0
  205. data/spec/dummy/public/500.html +34 -0
  206. data/spec/dummy/public/favicon.ico +8 -0
  207. data/spec/dummy/script/rails +6 -0
  208. data/spec/dummy/solr/collection1/conf/elevate.xml +36 -0
  209. data/spec/dummy/solr/collection1/conf/mapping-FoldToASCII.txt +3813 -0
  210. data/spec/dummy/solr/collection1/conf/schema.xml +292 -0
  211. data/spec/dummy/solr/collection1/conf/solrconfig.xml +1780 -0
  212. data/spec/dummy/solr/collection1/conf/spellings.txt +2 -0
  213. data/spec/dummy/solr/collection1/conf/stopwords.txt +58 -0
  214. data/spec/dummy/solr/collection1/conf/synonyms.txt +31 -0
  215. data/spec/factories/concepts.rb +16 -0
  216. data/spec/factories/daily_metrics.rb +10 -0
  217. data/spec/factories/faceted_metrics.rb +25 -0
  218. data/spec/factories/fragment.rb +14 -0
  219. data/spec/factories/partners.rb +14 -0
  220. data/spec/factories/record_interaction.rb +17 -0
  221. data/spec/factories/records.rb +47 -0
  222. data/spec/factories/set_interaction.rb +15 -0
  223. data/spec/factories/source_authorities.rb +19 -0
  224. data/spec/factories/sources.rb +16 -0
  225. data/spec/factories/usage_metrics.rb +20 -0
  226. data/spec/factories/user_activities.rb +14 -0
  227. data/spec/factories/user_sets.rb +27 -0
  228. data/spec/factories/users.rb +23 -0
  229. data/spec/helpers/application_helper_spec.rb +35 -0
  230. data/spec/models/concept_spec.rb +163 -0
  231. data/spec/models/fragment_spec.rb +15 -0
  232. data/spec/models/site_activity_spec.rb +103 -0
  233. data/spec/models/source_activity_spec.rb +56 -0
  234. data/spec/models/source_authority_spec.rb +42 -0
  235. data/spec/models/supplejack_api/api_concept/concept_fragment_spec.rb +189 -0
  236. data/spec/models/supplejack_api/api_record/record_fragment_spec.rb +189 -0
  237. data/spec/models/supplejack_api/concept_spec.rb +0 -0
  238. data/spec/models/supplejack_api/interaction_updaters/all_usage_metric_spec.rb +41 -0
  239. data/spec/models/supplejack_api/interaction_updaters/set_metrics_spec.rb +32 -0
  240. data/spec/models/supplejack_api/interaction_updaters/usage_metrics_spec.rb +44 -0
  241. data/spec/models/supplejack_api/partner_spec.rb +20 -0
  242. data/spec/models/supplejack_api/record_search_spec.rb +429 -0
  243. data/spec/models/supplejack_api/record_spec.rb +280 -0
  244. data/spec/models/supplejack_api/schema_definition_spec.rb +272 -0
  245. data/spec/models/supplejack_api/search_spec.rb +243 -0
  246. data/spec/models/supplejack_api/set_item_spec.rb +123 -0
  247. data/spec/models/supplejack_api/source_spec.rb +22 -0
  248. data/spec/models/supplejack_api/support/fragment_helpers_spec.rb +216 -0
  249. data/spec/models/supplejack_api/support/harvestable_spec.rb +177 -0
  250. data/spec/models/supplejack_api/support/searchable_spec.rb +85 -0
  251. data/spec/models/supplejack_api/support/storable_spec.rb +18 -0
  252. data/spec/models/supplejack_api/user_activity_spec.rb +88 -0
  253. data/spec/models/supplejack_api/user_set_spec.rb +559 -0
  254. data/spec/models/supplejack_api/user_spec.rb +348 -0
  255. data/spec/routing/concepts_routing_spec.rb +22 -0
  256. data/spec/routing/harvester_constraint_spec.rb +66 -0
  257. data/spec/routing/harvester_routing_spec.rb +51 -0
  258. data/spec/routing/partner_routing_spec.rb +34 -0
  259. data/spec/routing/records_routing_spec.rb +26 -0
  260. data/spec/routing/sets_routing_spec.rb +44 -0
  261. data/spec/routing/source_routing_spec.rb +38 -0
  262. data/spec/routing/users_routing_spec.rb +18 -0
  263. data/spec/serializers/concept_record_serializer_spec.rb +30 -0
  264. data/spec/serializers/supplejack_api/application_serializer_spec.rb +14 -0
  265. data/spec/serializers/supplejack_api/concept_search_serializer_spec.rb +34 -0
  266. data/spec/serializers/supplejack_api/concept_serializer_spec.rb +92 -0
  267. data/spec/serializers/supplejack_api/record_search_serializer_spec.rb +34 -0
  268. data/spec/serializers/supplejack_api/record_serializer_spec.rb +271 -0
  269. data/spec/serializers/supplejack_api/search_serializer_spec.rb +90 -0
  270. data/spec/serializers/supplejack_api/user_serializer_spec.rb +22 -0
  271. data/spec/serializers/supplejack_api/user_set_serializer_spec.rb +96 -0
  272. data/spec/services/metrics_api/v3/api_spec.rb +23 -0
  273. data/spec/services/metrics_api/v3/endpoints/facets_spec.rb +25 -0
  274. data/spec/services/metrics_api/v3/endpoints/global_spec.rb +22 -0
  275. data/spec/services/metrics_api/v3/endpoints/root_spec.rb +49 -0
  276. data/spec/services/metrics_api/v3/presenters/extended_metadata_spec.rb +49 -0
  277. data/spec/spec_helper.rb +70 -0
  278. data/spec/support/api/schemas/metrics/daily_metrics_metadata.json +24 -0
  279. data/spec/support/api/schemas/metrics/extended_metrics.json +26 -0
  280. data/spec/support/api/schemas/metrics/extended_response.json +6 -0
  281. data/spec/support/api/schemas/metrics/facets_response.json +6 -0
  282. data/spec/support/api/schemas/metrics/record_metadata.json +33 -0
  283. data/spec/support/api/schemas/metrics/top_level_response.json +6 -0
  284. data/spec/support/api/schemas/metrics/view_metadata.json +33 -0
  285. data/spec/support/api_schema_matcher.rb +14 -0
  286. data/spec/support/devise.rb +10 -0
  287. data/spec/workers/supplejack_api/daily_metrics_worker_spec.rb +140 -0
  288. data/spec/workers/supplejack_api/flush_old_records_worker_spec.rb +20 -0
  289. data/spec/workers/supplejack_api/index_worker_spec.rb +52 -0
  290. data/spec/workers/supplejack_api/source_index_worker_spec.rb +61 -0
  291. metadata +1231 -0
@@ -0,0 +1,34 @@
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 "Partner routes", type: :routing do
12
+ routes { SupplejackApi::Engine.routes }
13
+
14
+ before(:each) do
15
+ allow_any_instance_of(HarvesterConstraint).to receive(:matches?).and_return(true)
16
+ end
17
+
18
+ it "routes /partners to partners#create" do
19
+ expect(post("/partners")).to route_to(controller: 'supplejack_api/partners', action: 'create')
20
+ end
21
+
22
+ it "routes /partners/1 to partners#show" do
23
+ expect(get("/partners/1")).to route_to(controller: 'supplejack_api/partners', action: 'show', id: '1')
24
+ end
25
+
26
+ it "routes /partners to partners#index" do
27
+ expect(get("/partners")).to route_to(controller: 'supplejack_api/partners', action: 'index')
28
+ end
29
+
30
+ it "routes /partners/1 to partners#update" do
31
+ expect(put("/partners/1")).to route_to(controller: 'supplejack_api/partners', action: 'update', id: '1')
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
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 'Records route', type: :routing do
12
+ routes { SupplejackApi::Engine.routes }
13
+
14
+ it 'routes /records.format to records#index' do
15
+ expect(get '/records.json').to route_to(controller: 'supplejack_api/records', action: 'index', format: 'json', version: nil)
16
+ end
17
+
18
+ it 'routes /records/1.format to records#index' do
19
+ expect(get '/records/99.json').to route_to(controller: 'supplejack_api/records', action: 'show', id: '99', format: 'json', version: nil)
20
+ end
21
+
22
+ it 'routes /records/multiple.json records#multiple' do
23
+ expect(get: '/records/multiple.json').to route_to(controller: 'supplejack_api/records', action: 'multiple', format: 'json', version: nil)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,44 @@
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
+ describe 'Sets routes', type: :routing do
11
+ routes { SupplejackApi::Engine.routes }
12
+
13
+ it 'routes /sets.format to user_sets#index' do
14
+ expect({ get: '/sets.json' }).to route_to(controller: 'supplejack_api/user_sets', action: 'index', format: 'json', version: nil)
15
+ end
16
+
17
+ it 'routes /users/123/sets.format to user_sets#index' do
18
+ expect({ get: '/users/123/sets.json' }).to route_to(controller: 'supplejack_api/user_sets', action: 'admin_index', format: 'json', version: nil, user_id: '123')
19
+ end
20
+
21
+ it 'routes /sets/public.format to user_sets#public_index' do
22
+ expect({ get: '/sets/public.json' }).to route_to(controller: 'supplejack_api/user_sets', action: 'public_index', format: 'json', version: nil)
23
+ end
24
+
25
+ it 'routes /sets/1.format to user_sets#show' do
26
+ expect({ get: '/sets/10.json' }).to route_to(controller: 'supplejack_api/user_sets', action: 'show', format: 'json', version: nil, id: '10')
27
+ end
28
+
29
+ it 'routes /sets.format to user_sets#create' do
30
+ expect({post: '/sets.json' }).to route_to(controller: 'supplejack_api/user_sets', action: 'create', format: 'json', version: nil)
31
+ end
32
+
33
+ it 'routes /sets/123abc.json to user_sets#update' do
34
+ expect({ put: '/sets/123abc.json' }).to route_to(controller: 'supplejack_api/user_sets', action: 'update', format: 'json', version: nil, id: '123abc')
35
+ end
36
+
37
+ it 'routes /sets/123abc/records.json to set_items#create' do
38
+ expect({ post: '/sets/123abc/records.json' }).to route_to(controller: 'supplejack_api/set_items', action: 'create', format: 'json', version: nil, user_set_id: '123abc')
39
+ end
40
+
41
+ it 'routes /sets/123abc/records/666.json to set_items#destroy' do
42
+ expect({ delete: '/sets/123abc/records/666.json' }).to route_to(controller: 'supplejack_api/set_items', action: 'destroy', format: 'json', version: nil, user_set_id: '123abc', id: '666')
43
+ end
44
+ end
@@ -0,0 +1,38 @@
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 routes', type: :routing do
12
+ routes { SupplejackApi::Engine.routes }
13
+
14
+ before(:each) do
15
+ allow_any_instance_of(HarvesterConstraint).to receive(:matches?).and_return(true)
16
+ end
17
+
18
+ it 'routes /partners/123/sources to sources#create' do
19
+ expect(post('/partners/123/sources.json')).to route_to(controller: 'supplejack_api/sources', action: 'create', partner_id: '123', format: 'json')
20
+ end
21
+
22
+ it 'routes /sources/1234 to sources#show' do
23
+ expect(get('/sources/1234.json')).to route_to(controller: 'supplejack_api/sources', action: 'show', id: '1234', format: 'json')
24
+ end
25
+
26
+ it "routes /sources to sources#index" do
27
+ expect(get('/sources.json')).to route_to(controller: 'supplejack_api/sources', action: 'index', format: 'json')
28
+ end
29
+
30
+ it "routes /sources/1234 to sources#update" do
31
+ expect(put('/sources/1234.json')).to route_to(controller: 'supplejack_api/sources', action: 'update', id: '1234', format: 'json')
32
+ end
33
+
34
+ it "routes /sources/1234/reindex to sources#reindex" do
35
+ expect(get('/sources/1234/reindex.json')).to route_to(controller: 'supplejack_api/sources', action: 'reindex', id: '1234', format: 'json')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
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 "User routes", type: :routing do
12
+ routes { SupplejackApi::Engine.routes }
13
+
14
+ it "routes /users/1.format to users#show" do
15
+ expect(get('/users/1.json')).to route_to(controller: 'supplejack_api/users', action: 'show', format: 'json', id: '1', version: nil)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
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 ConceptRecordSerializer do
12
+ let(:record) { SupplejackApi::Record.new(title: 'Wellington', description: 'New Zealand', date: '2015-06-05',
13
+ display_content_partner: 'Television New Zealand', display_collection: 'TVNZ', thumbnail_url: 'http://example.com') }
14
+ let(:serializer) { ConceptRecordSerializer.new(record) }
15
+
16
+ it 'includes the basic record information' do
17
+ allow(record).to receive(:id) { 'abc' }
18
+ allow(record).to receive(:record_id) { '123' }
19
+ json = serializer.as_json[:concept_record]
20
+
21
+ expect(json['@id']).to eq 'http://test.host/records/123'
22
+ expect(json['title']).to eq record.title
23
+ expect(json['description']).to eq record.description
24
+ expect(json['date']).to eq record.date
25
+ expect(json['display_content_partner']).to eq record.display_content_partner
26
+ expect(json['display_collection']).to eq record.display_collection
27
+ expect(json['thumbnail_url']).to eq record.thumbnail_url
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,14 @@
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 ApplicationSerializer do
12
+
13
+ end
14
+ end
@@ -0,0 +1,34 @@
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 ConceptSearchSerializer do
12
+
13
+ # def serializer(options={}, attributes={})
14
+ # @user = FactoryGirl.build(:user, attributes)
15
+ # @serializer = ConceptSearchSerializer.new(@user, options)
16
+ # end
17
+
18
+ # describe '#default?' do
19
+ # it 'should return true when default is part of the groups' do
20
+ # expect(serializer(groups: [:default]).default?).to be_truthy
21
+ # end
22
+
23
+ # it 'should return false when the group is verbose' do
24
+ # expect(serializer(groups: [:verbose]).default?).to be_falsey
25
+ # end
26
+
27
+ # it 'should return false' do
28
+ # expect(serializer(groups: nil).default?).to be_falsey
29
+ # expect(serializer(groups: []).default?).to be_falsey
30
+ # end
31
+ # end
32
+ end
33
+
34
+ end
@@ -0,0 +1,92 @@
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 ConceptSerializer do
12
+ before { allow(ConceptSchema).to receive(:roles) { double(:developer).as_null_object } }
13
+
14
+ def serializer(options={}, attributes={})
15
+ concept_fields = Concept.fields.keys
16
+ concept_attributes = Hash[attributes.map {|k, v| [k, v] if concept_fields.include?(k.to_s)}.compact]
17
+ attributes.delete_if {|k, v| concept_fields.include?(k.to_s) }
18
+
19
+ @concept = FactoryGirl.build(:concept, concept_attributes)
20
+ @concept.id = "http://localhost/concepts/#{@concept.concept_id}"
21
+ @serializer = ConceptSerializer.new(@concept, options)
22
+ end
23
+
24
+ describe '#include_context_fields!' do
25
+ before {
26
+ @hash = {'@context' => {}, name: 'McCahon'}
27
+ }
28
+
29
+ it 'include inline context in concept' do
30
+ s = serializer({ inline_context: 'true'})
31
+ s.include_context_fields!(@hash)
32
+ concept = {
33
+ '@context'=>{
34
+ :foaf => 'http://xmlns.com/foaf/0.1/',
35
+ :dc => 'http://purl.org/dc/elements/1.1/',
36
+ :edm => 'http://www.europeana.eu/schemas/edm/',
37
+ :dcterms => 'http://purl.org/dc/terms/',
38
+ :concept_id => {
39
+ '@id' => 'dcterms:identifier'
40
+ },
41
+ :name => {
42
+ '@id' => 'foaf:name'
43
+ },
44
+ :title => {
45
+ '@id' => 'dc:title'
46
+ },
47
+ :date => {
48
+ '@id' => 'dc:date'
49
+ },
50
+ :description => {
51
+ '@id' => 'dc:description'
52
+ },
53
+ :agents => {
54
+ '@id'=>'edm:agents'
55
+ },
56
+ :source_authority=> {
57
+ '@id' => 'foaf:source_authority'
58
+ },
59
+ },
60
+ :name => 'McCahon'
61
+ }
62
+ expect(@hash).to eq concept
63
+ end
64
+
65
+ it 'show context document url' do
66
+ s = serializer()
67
+ s.include_context_fields!(@hash)
68
+ expect(@hash['@context']).to eq "#{ENV['HTTP_HOST']}/schema"
69
+ expect(@hash[:name]).to eq 'McCahon'
70
+ end
71
+ end
72
+
73
+ describe '#include_individual_fields!' do
74
+ it 'merges in the hash the requested fields' do
75
+ hash = {}
76
+ s = serializer({ fields: [:name] }, { name: 'McCahon' })
77
+ s.include_individual_fields!(hash)
78
+ expect(hash).to eq({ name: 'McCahon', concept_id: 1})
79
+ end
80
+ end
81
+
82
+ describe '#include_reverse_fields!' do
83
+ it 'includes reverse field' do
84
+ hash = {}
85
+ s = serializer({ fields: [:name] }, { name: 'McCahon' })
86
+ s.include_reverse_fields!(hash)
87
+ expect(hash['@reverse']).to include 'agents'
88
+ expect(hash['@reverse']['agents']).to eq []
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,34 @@
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 RecordSearchSerializer do
12
+
13
+ def serializer(options={}, attributes={})
14
+ @user = FactoryGirl.build(:user, attributes)
15
+ @serializer = RecordSearchSerializer.new(@user, options)
16
+ end
17
+
18
+ describe '#default?' do
19
+ it 'should return true when default is part of the groups' do
20
+ expect(serializer(groups: [:default]).default?).to be_truthy
21
+ end
22
+
23
+ it 'should return false when the group is verbose' do
24
+ expect(serializer(groups: [:verbose]).default?).to be_falsey
25
+ end
26
+
27
+ it 'should return false' do
28
+ expect(serializer(groups: nil).default?).to be_falsey
29
+ expect(serializer(groups: []).default?).to be_falsey
30
+ end
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,271 @@
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 RecordSerializer do
12
+
13
+ before(:each) do
14
+ allow(RecordSchema).to receive(:roles) { double(:developer).as_null_object }
15
+ end
16
+
17
+ def record_hash(attributes={}, method=nil, options={})
18
+ record_fields = Record.fields.keys
19
+ record_attributes = Hash[attributes.map {|k,v| [k,v] if record_fields.include?(k.to_s)}.compact]
20
+ attributes.delete_if {|k,v| record_fields.include?(k.to_s) }
21
+
22
+ @record = FactoryGirl.build(:record, record_attributes)
23
+ @record.fragments.build(attributes)
24
+ @serializer = RecordSerializer.new(@record, options)
25
+
26
+ if method
27
+ @serializer.send(method)
28
+ else
29
+ @serializer.as_json[:record]
30
+ end
31
+ end
32
+
33
+ def serializer(options={}, attributes={})
34
+ record_fields = Record.fields.keys
35
+ record_attributes = Hash[attributes.map {|k,v| [k,v] if record_fields.include?(k.to_s)}.compact]
36
+ attributes.delete_if {|k,v| record_fields.include?(k.to_s) }
37
+
38
+ @record = FactoryGirl.build(:record, record_attributes)
39
+ @record.fragments.build(attributes)
40
+ @serializer = RecordSerializer.new(@record, options)
41
+ end
42
+
43
+ describe '#as_json' do
44
+ let(:record) { FactoryGirl.build(:record) }
45
+ let(:serializer) { RecordSerializer.new(record) }
46
+
47
+ [:next_record, :previous_record, :next_page, :previous_page].each do |attribute|
48
+ it "should include #{attribute} when present" do
49
+ record.send("#{attribute}=", 2)
50
+ expect(serializer.as_json[:record][attribute]).to eq 2
51
+ end
52
+
53
+ it "should not include #{attribute} when null" do
54
+ record.send("#{attribute}=", nil)
55
+ expect(serializer.as_json[:record]).to_not have_key(attribute)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#include_individual_fields!' do
61
+ before { @hash = {} }
62
+
63
+ it 'merges in the hash the requested fields' do
64
+ s = serializer({ fields: [:age] }, { age: 22 })
65
+ s.include_individual_fields!(@hash)
66
+ expect(@hash).to eq({ age: 22 })
67
+ end
68
+ end
69
+
70
+ describe '#remove_restricted_fields!' do
71
+ let(:hash) { {name: 'John Doe', address: "Wellington", email: ["johndoe@example.com"], age: 30} }
72
+ let(:user) { User.new(role: "developer") }
73
+ let(:restrictions) { { address: {"Wellington"=>["name"], "Auckland"=>["email"]},
74
+ email: {/example.com/ => ["address", "age"]} } }
75
+ let(:developer_role) { double(:developer_role, field_restrictions: restrictions) }
76
+ let(:admin_role) { double(:admin_role, field_restrictions: nil) }
77
+
78
+ before(:each) do
79
+ allow(RecordSchema).to receive(:roles).and_return({ developer: developer_role, admin: admin_role })
80
+ end
81
+
82
+ context "string conditions" do
83
+ context "Wellington" do
84
+ let(:s) { serializer({scope: user}, {address: ["Wellington"]}) }
85
+
86
+ it "removes name field" do
87
+ s.remove_restricted_fields!(hash)
88
+ expect(hash[:name]).to be_nil
89
+ end
90
+
91
+ it "doesn't remove non-restriected fields" do
92
+ s.remove_restricted_fields!(hash)
93
+ expect(hash[:age]).to eq 30
94
+ end
95
+ end
96
+
97
+ context "Auckland" do
98
+ let(:s) { serializer({scope: user}, {address: ["Auckland"]}) }
99
+
100
+ it "removes email field" do
101
+ s.remove_restricted_fields!(hash)
102
+ expect(hash[:email]).to be_nil
103
+ end
104
+ end
105
+ end
106
+
107
+ context "regex conditions" do
108
+ let(:s) { serializer({scope: user}, {email: ["johndoe@example.com"]}) }
109
+
110
+ it "removes address field" do
111
+ s.remove_restricted_fields!(hash)
112
+ expect(hash[:address]).to be_nil
113
+ end
114
+ end
115
+
116
+ context "remove multiple fields" do
117
+ let(:s) { serializer({scope: user}, {email: ['johndoe@example.com']}) }
118
+
119
+ it "removes all fields that match the restrictions" do
120
+ s.remove_restricted_fields!(hash)
121
+ expect(hash[:large_thumbnail_url]).to be_nil
122
+ expect(hash[:thumbnail_url]).to be_nil
123
+ end
124
+ end
125
+
126
+ context "field value is empty" do
127
+ let(:s) { serializer({scope: user}, {address: nil}) }
128
+
129
+ it "doesn't fail when a string condition field value is empty" do
130
+ s.remove_restricted_fields!(hash)
131
+ expect(hash[:name]).to eq 'John Doe'
132
+ end
133
+
134
+ it "doesn't fail when a regex condition field value is empty" do
135
+ s.remove_restricted_fields!(hash)
136
+ expect(hash[:email]).to eq ['johndoe@example.com']
137
+ end
138
+ end
139
+
140
+ context "no restrictions for role" do
141
+ let(:admin_user) { User.new(role: "admin") }
142
+ let(:s) { serializer({scope: admin_user}) }
143
+
144
+ it "returns all fields" do
145
+ s.remove_restricted_fields!(hash)
146
+ expect(hash.keys).to eq [:name, :address, :email, :age]
147
+ end
148
+ end
149
+ end
150
+
151
+ describe '#serializable_hash' do
152
+ context 'include groups of fields' do
153
+ let(:default_group) { double(:default_group, fields: [:name, :email]) }
154
+ let(:details_group) { double(:details_group, fields: [:name, :email, :age]) }
155
+ let(:s) { serializer({groups: [:default]}) }
156
+ let(:record) { double(:record).as_null_object }
157
+
158
+ before(:each) do
159
+ @hash = {}
160
+ allow(RecordSchema).to receive(:groups) { {default: default_group, details: details_group} }
161
+ allow(s).to receive(:record) { record }
162
+ allow(s).to receive(:field_value)
163
+ end
164
+
165
+ context 'handling groups' do
166
+ it 'should include fields from given group' do
167
+ expect(default_group).to receive(:fields)
168
+ expect(details_group).to_not receive(:fields)
169
+ s.serializable_hash
170
+ end
171
+
172
+ it 'should handle non-existent groups' do
173
+ allow(s).to receive(:options) { { groups: [:dogs] } }
174
+ expect(s.serializable_hash.size).to eq 0
175
+ end
176
+
177
+ it 'should remove non-existent groups (or field names)' do
178
+ allow(s).to receive(:options) { { groups: [:default, :description] } }
179
+ allow(s).to receive(:field_value).with(:name, anything()) { 'John Doe' }
180
+ expect(s.serializable_hash[:name]).to eq 'John Doe'
181
+ end
182
+
183
+ it 'should include fields from multiple groups' do
184
+ allow(s).to receive(:options) { { groups: [:default, :details] } }
185
+ [:name, :email, :age].each do |field|
186
+ expect(s.serializable_hash.keys).to include field
187
+ end
188
+ end
189
+ end
190
+
191
+ it 'should remove restricted fields' do
192
+ expect(s).to receive(:remove_restricted_fields!)
193
+ s.serializable_hash
194
+ end
195
+
196
+ context 'field/group doesn\'t exist' do
197
+ it 'returns an empty record hash' do
198
+ allow(s).to receive(:options) { { groups: [:dogs] } }
199
+ expect(s.serializable_hash).to be_empty
200
+ end
201
+ end
202
+ end
203
+ end
204
+
205
+ describe '#field_restricted?' do
206
+ let(:s) { serializer({groups: [:default]}) }
207
+
208
+ it 'returns true if the field is restricted' do
209
+ allow(s).to receive(:field_value) { 'Wellington' }
210
+ expect(s.send(:field_restricted?, 'address', "Wellington")).to be_truthy
211
+ end
212
+
213
+ it 'returns false if the field is not restricted' do
214
+ allow(s).to receive(:field_value) { 'Auckland' }
215
+ expect(s.send(:field_restricted?, 'address', "Wellington")).to be_falsey
216
+ end
217
+
218
+ it 'handles multi-value fields' do
219
+ allow(s).to receive(:field_value) { ['jdoe@test.com', 'johndoe@example.com'] }
220
+ expect(s.send(:field_restricted?, 'email', /test.com/)).to be_truthy
221
+ end
222
+ end
223
+
224
+ describe "#format_date" do
225
+ let(:s) { serializer({groups: [:default]}) }
226
+
227
+ it "returns formated date for a date string" do
228
+ date_time = Time.now
229
+ expect(s.send(:format_date, date_time, "%y/%d/%m")).to eq (date_time.strftime("%y/%d/%m"))
230
+ end
231
+ end
232
+
233
+ describe "#field_value" do
234
+ let(:s) { serializer({groups: [:default]}) }
235
+ let(:record) { double(:record, name: 'John Doe', address: nil, email: ['johndoe@example.com', 'jdoe@test.com'], children: ['Sara', 'Bob']) }
236
+
237
+ before(:each) do
238
+ allow(s).to receive(:object) { record }
239
+ end
240
+
241
+ it "should return the single field value" do
242
+ expect(s.field_value(:name)).to eq 'John Doe'
243
+ end
244
+
245
+ it "should return the multipe field value" do
246
+ expect(s.field_value(:email)).to eq ['johndoe@example.com', 'jdoe@test.com']
247
+ end
248
+
249
+ it "return nil for nil value" do
250
+ expect(s.field_value(:address)).to be_nil
251
+ end
252
+
253
+ context 'search_value defined' do
254
+ context 'field not stored in mongo' do
255
+ it 'uses the value of the search_value block' do
256
+ allow(RecordSchema).to receive(:fields) { { age: double(:field, store: false, search_value: Proc.new{ 21 }) } }
257
+ expect(s.field_value(:age)).to eq 21
258
+ end
259
+ end
260
+
261
+ context 'field stored in mongo' do
262
+ it "uses the value from mongo" do
263
+ allow(RecordSchema).to receive(:fields) { {children: double(:field, search_value: Proc.new{1}).as_null_object} }
264
+ expect(s.field_value(:children)).to eq ['Sara', 'Bob']
265
+ end
266
+ end
267
+ end
268
+ end
269
+ end
270
+
271
+ end