Skip to content
Browse files

Expose CuratedLists as JSON

  • Loading branch information...
1 parent 0500269 commit e5bf489ada6873885b0913d399633c00172adde8 @jamiecobbett jamiecobbett committed
View
2 Gemfile
@@ -35,7 +35,7 @@ gem "bson", "1.5.2"
if ENV['CONTENT_MODELS_DEV']
gem "govuk_content_models", :path => '../govuk_content_models'
else
- gem "govuk_content_models", "~> 0.0.13"
+ gem "govuk_content_models", "~> 0.0.14"
end
if ENV['BUNDLE_DEV']
View
4 Gemfile.lock
@@ -123,7 +123,7 @@ GEM
json
gherkin (2.7.3)
json (>= 1.4.6)
- govuk_content_models (0.0.13)
+ govuk_content_models (0.0.14)
bson_ext
differ
gds-api-adapters
@@ -284,7 +284,7 @@ DEPENDENCIES
gds-sso (~> 0.5)
gds-warmup-controller
gelf
- govuk_content_models (~> 0.0.13)
+ govuk_content_models (~> 0.0.14)
launchy
marples (~> 1.0)
minitest
View
11 app/controllers/curated_lists_controller.rb
@@ -0,0 +1,11 @@
+class CuratedListsController < ApplicationController
+ respond_to :json
+
+ def index
+ curated_lists = {}
+ CuratedList.all.map do |curated_list|
+ curated_lists[curated_list.slug] = curated_list.artefacts.map(&:slug)
+ end
+ respond_with(curated_lists)
+ end
+end
View
3 config/routes.rb
@@ -2,6 +2,9 @@
resources :artefacts
resources :tags, :defaults => {:format => 'json'}
+
+ resources :curated_lists, only: :index
+
match 'tags/:id' => 'tags#show', :id => /[^\.]+/, :defaults => {:format => 'json'}
match 'google_insight' => 'seo#show'
View
176 lib/tasks/migrate.rake
@@ -0,0 +1,176 @@
+namespace :migrate do
+ desc "Populate CuratedList with data extracted from text file in Rummager"
+ task :populate_curated_list do
+ Mongoid.load!("config/mongoid.yml")
+
+ class CuratedList
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field "slug", type: String
+ field "artefact_ids", type: Array, default: []
+
+ index "slug"
+
+ validates :slug, presence: true, uniqueness: true
+ end
+
+ class Artefact
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field "slug", type: String
+ end
+
+ curated_lists = {
+ "neighbourhoods" => [
+ "uk-online-centre-internet-access-computer-training",
+ "organise-fete-street-party",
+ "noise-pollution-road-train-plane",
+ "control-dog-public",
+ "report-litter",
+ "report-abandoned-vehicle",
+ "join-library",
+ "garden-bonfires-rules",
+ "find-out-about-local-park",
+ "book-computer-at-library",
+ "find-a-community-support-group-or-organisation",
+ "check-drinking-water-quality"
+ ],
+ "housing" => [
+ "housing-benefit",
+ "council-tax-benefit",
+ "council-housing",
+ "apply-for-council-housing",
+ "pay-council-tax",
+ "council-tax-bands",
+ "warm-front-scheme",
+ "mortgage-rescue-scheme",
+ "private-renting",
+ "affordable-home-ownership-schemes",
+ "tenancy-deposit-protection",
+ "rubbish-collection-day",
+ ],
+ "crime-and-justice" => [
+ "jury-service",
+ "report-crime-anti-social-behaviour",
+ "life-in-prison",
+ "become-magistrate",
+ "staying-in-touch-with-someone-in-prison",
+ "legal-aid",
+ "report-domestic-abuse",
+ "courts",
+ "pay-court-fine-online",
+ "get-support-as-a-victim-of-crime",
+ "arrested-your-rights",
+ "going-to-court-victim-witness"
+ ],
+ "education" => [
+ "apply-for-student-finance-2012-13",
+ "student-finance-calculator",
+ "school-term-holiday-dates",
+ "national-curriculum",
+ "find-nursery-school-place",
+ "apply-for-primary-school-place",
+ "apply-for-secondary-school-place",
+ "career-development-loans",
+ "1619-bursary-fund",
+ "courses-qualifications",
+ "grant-bursary-adult-learners",
+ ],
+ "work" =>[
+ "find-job",
+ "jobseekers-allowance",
+ "calculate-redundancy-pay",
+ "your-right-to-minimum-wage",
+ "taking-annual-leave-your-rights",
+ "employment-contracts-and-conditions",
+ "redundant-your-rights",
+ "statutory-sick-pay-ssp",
+ "crb-criminal-records-bureau-check",
+ "national-insurance-number",
+ "statutory-maternity-pay",
+ "looking-for-work-if-youre-disabled"
+ ],
+ "family" => [
+ "order-copy-birth-death-marriage-certificate",
+ "register-birth",
+ "divorce",
+ "after-a-death",
+ "register-offices",
+ "marriages-civil-partnerships",
+ "wills-probate-inheritance",
+ "maternity-allowance",
+ "carers-allowance",
+ "qualify-tax-credits-quick-questionnaire",
+ "paternityleave",
+ "find-before-after-school-childcare",
+ ],
+ "money-and-tax" => [
+ "benefits-calculator",
+ "income-support",
+ "national-insurance",
+ "claim-tax-credits",
+ "tax-credits-calculator",
+ "crisis-loans",
+ "dla-disability-living-allowance-guide",
+ "state-pension",
+ "file-your-self-assessment-tax-return",
+ "community-care-grant",
+ "income-tax-rates",
+ "pension-credit",
+ ],
+ "driving" => [
+ "car-tax-disc-vehicle-licence",
+ "calculate-vehicle-tax-rates",
+ "book-a-driving-theory-test",
+ "book-practical-driving-test",
+ "change-address-driving-licence",
+ "check-mot-status-vehicle",
+ "vehicle-tax-rate-tables",
+ "apply-online-to-replace-a-driving-licence",
+ "change-name-driving-licence",
+ "apply-first-provisional-driving-licence",
+ "change-photo-driving-licence",
+ "apply-blue-badge",
+ ],
+ "travel" => [
+ "apply-renew-passport",
+ "plan-your-journey",
+ "local-road-closures-diversions",
+ "passport-quick",
+ "hand-luggage-restrictions-at-uk-airports",
+ "apply-renew-european-health-insurance-card",
+ "free-bus-passes-in-england",
+ "transport-disabled",
+ "state-pension-if-you-retire-abroad",
+ "moving-abroad",
+ "bringing-food-animals-plants-into-uk"
+ ],
+ "life-in-the-uk" => [
+ "petition-government",
+ "search-local-archives",
+ "register-to-vote",
+ "bank-holidays",
+ "becoming-a-british-citizen",
+ "rights-disabled-person",
+ "make-will",
+ "volunteering",
+ "equality-act-2010",
+ "book-life-in-uk-test",
+ "power-of-attorney",
+ "organise-citizenship-ceremony-council",
+ ]
+ }
+ curated_lists.each do |list_slug, artefact_slugs|
+ curated_list = CuratedList.create(slug: list_slug)
+ # Do this the long-way-round to get ordering of items correct
+ artefact_slugs.each do |artefact_slug|
+ if artefact = Artefact.where(slug: artefact_slug).first
+ curated_list.artefact_ids << artefact.id
+ end
+ end
+ curated_list.save!
+ end
+ end
+end
View
42 test/functional/curated_lists_controller_test.rb
@@ -0,0 +1,42 @@
+require "test_helper"
+
+class CuratedListsControllerTest < ActionController::TestCase
+ setup do
+ login_as_stub_user
+ end
+
+ test "return a json representation of the lists" do
+ jury = Artefact.create(name: "Jury Service", slug: "jury-service",
+ kind: "guide", owning_app: "publisher")
+ crime = CuratedList.create(slug: "crime-and-justice")
+ crime.artefact_ids << jury.id
+ crime.save
+
+ expected = {
+ "crime-and-justice" => ["jury-service"]
+ }
+ get :index, format: :json
+ assert_equal 200, response.status
+ assert_equal expected, JSON.parse(response.body)
+ end
+
+ test "should retain the order of the IDs in artefact_ids" do
+ jury = Artefact.create(name: "Jury Service", slug: "jury-service",
+ kind: "guide", owning_app: "publisher")
+ to_court = Artefact.create(name: "Court", slug: "going-to-court-victim-witness", kind: "guide", owning_app: "publisher")
+ crime = CuratedList.create(slug: "crime-and-justice")
+ crime.artefact_ids << jury.id
+ crime.artefact_ids << to_court.id
+ crime.save
+
+ expected = {
+ "crime-and-justice" => [
+ "jury-service",
+ "going-to-court-victim-witness"
+ ]
+ }
+ get :index, format: :json
+ assert_equal 200, response.status
+ assert_equal expected, JSON.parse(response.body)
+ end
+end

0 comments on commit e5bf489

Please sign in to comment.
Something went wrong with that request. Please try again.