govuk-dummy_content_store 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +14 -0
- data/bin/dummy_content_store +19 -0
- data/config.ru +28 -0
- data/govuk-dummy_content_store.gemspec +31 -0
- data/jenkins.sh +9 -0
- data/lib/govuk/dummy_content_store/content.rb +45 -0
- data/lib/govuk/dummy_content_store/example_content_item.rb +41 -0
- data/lib/govuk/dummy_content_store/example_repository.rb +27 -0
- data/lib/govuk/dummy_content_store/index.rb +52 -0
- data/lib/govuk/dummy_content_store/templates/index.html.erb +37 -0
- data/lib/govuk/dummy_content_store/version.rb +5 -0
- data/lib/govuk/dummy_content_store.rb +10 -0
- data/public/styles.css +2 -0
- data/spec/fixtures/govuk-content-schemas/formats/my-format/frontend/examples/my_example.json +83 -0
- data/spec/integration/dummy_content_store_spec.rb +68 -0
- data/spec/spec_helper.rb +21 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2762a2aa6d36574e3d4b80cb70c9253a4e72a554
|
4
|
+
data.tar.gz: 3d4755ecbe34070426103027466437c5a0fb769c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9941a3d83a234c02ebbd2d438474f53f97ba8ce5da2741c539a2dc744ed5fa0f0a9d452ea12d0841215e3ecdebbf0e97879aef3bf38252a61bff3c9cc0cad06e
|
7
|
+
data.tar.gz: dd5c4aa5409f4f9dfafce23e9bd3a6504ea7dcfc1e6f218d1ba448314f7ba5f54305dcff20c6dc69b54b9e87438af10177d379187f5b21e4c270331d266abdf4
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.4
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Crown copyright (Government Digital Service)
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Govuk::DummyContentStore
|
2
|
+
|
3
|
+
The dummy content store allows you to run a frontend using the examples from
|
4
|
+
the `govuk-content-schemas` repo. You will not need to run the content store
|
5
|
+
itself.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
The dummy content store is best installed as a stand-alone gem:
|
10
|
+
|
11
|
+
$ gem install govuk-dummy_content_store
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Start the server using:
|
16
|
+
|
17
|
+
$ dummy_content_store
|
18
|
+
|
19
|
+
By default it will look for the schemas:
|
20
|
+
|
21
|
+
1. at the path specified by the `GOVUK_CONTENT_SCHEMAS_PATH` environment variable
|
22
|
+
2. in the current directory
|
23
|
+
3. at the path specified in the first argument
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/alphagov/govuk-dummy_content_store/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
require "gem_publisher"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
desc "Publish gem to RubyGems.org"
|
9
|
+
task :publish_gem do |t|
|
10
|
+
gem = GemPublisher.publish_if_updated("govuk-dummy_content_store.gemspec", :rubygems)
|
11
|
+
puts "Published #{gem}" if gem
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :spec
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require "rack"
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: #{File.basename(__FILE__)} [<path/to/govuk-content-schemas>]"
|
8
|
+
|
9
|
+
opts.on_tail("-h", "-?", "--help", "Show this message") do
|
10
|
+
puts opts
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end.parse!
|
14
|
+
|
15
|
+
if ARGV.size == 1
|
16
|
+
ENV['GOVUK_CONTENT_SCHEMAS_PATH'] = ARGV.first
|
17
|
+
end
|
18
|
+
|
19
|
+
Rack::Server.start(config: File.dirname(__FILE__) + "/../config.ru")
|
data/config.ru
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#\ -p 3068
|
2
|
+
$LOAD_PATH << File.dirname(__FILE__) + "/lib"
|
3
|
+
require 'govuk/dummy_content_store'
|
4
|
+
|
5
|
+
govuk_content_schemas_path = ENV.fetch('GOVUK_CONTENT_SCHEMAS_PATH', ".")
|
6
|
+
repository = Govuk::DummyContentStore::ExampleRepository.new(govuk_content_schemas_path)
|
7
|
+
|
8
|
+
map '/' do
|
9
|
+
run Govuk::DummyContentStore::Index.new(repository)
|
10
|
+
end
|
11
|
+
|
12
|
+
# All /assets urls will serve files from the /public folder
|
13
|
+
map '/assets' do
|
14
|
+
use Rack::Static, :urls => [""], :root => File.dirname(__FILE__) + "/public"
|
15
|
+
|
16
|
+
# fallback always 404s
|
17
|
+
run ->(_) { [404, {}, []] }
|
18
|
+
end
|
19
|
+
|
20
|
+
# Serve examples
|
21
|
+
map '/content' do
|
22
|
+
run Govuk::DummyContentStore::Content.new(repository)
|
23
|
+
end
|
24
|
+
map '/api/content' do
|
25
|
+
run Govuk::DummyContentStore::Content.new(repository)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'govuk/dummy_content_store/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "govuk-dummy_content_store"
|
8
|
+
spec.version = Govuk::DummyContentStore::VERSION
|
9
|
+
spec.authors = ["David Heath"]
|
10
|
+
spec.email = ["david.heath@digital.cabinet-office.gov.uk"]
|
11
|
+
spec.summary = %q{Rack app which serves example files from govuk-content-schemas}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.0'
|
22
|
+
|
23
|
+
spec.add_dependency "rack"
|
24
|
+
spec.add_dependency "rack-contrib"
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "rack-test"
|
29
|
+
spec.add_development_dependency "gem_publisher"
|
30
|
+
spec.add_development_dependency "nokogiri"
|
31
|
+
end
|
data/jenkins.sh
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'json'
|
3
|
+
require 'govuk/dummy_content_store'
|
4
|
+
|
5
|
+
module Govuk
|
6
|
+
module DummyContentStore
|
7
|
+
class Content
|
8
|
+
attr_reader :repository
|
9
|
+
|
10
|
+
def initialize(repository)
|
11
|
+
@repository = repository
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
example = repository.find_by_base_path(env["PATH_INFO"])
|
16
|
+
if example
|
17
|
+
present_example(example)
|
18
|
+
else
|
19
|
+
present_not_found
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def present_example(example)
|
25
|
+
headers = {
|
26
|
+
'Content-Type' => 'application/json; charset=utf-8',
|
27
|
+
'Content-Length' => example.raw_data.bytesize.to_s,
|
28
|
+
'Cache-control' => 'no-cache'
|
29
|
+
}
|
30
|
+
|
31
|
+
[200, headers, [example.raw_data]]
|
32
|
+
end
|
33
|
+
|
34
|
+
def present_not_found
|
35
|
+
body = 'Not found'
|
36
|
+
headers = {
|
37
|
+
'Content-Type' => 'text/plain',
|
38
|
+
'Content-Length' => body.size.to_s,
|
39
|
+
'Cache-control' => 'no-cache'
|
40
|
+
}
|
41
|
+
[404, headers, [body]]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'govuk/dummy_content_store'
|
2
|
+
|
3
|
+
module Govuk
|
4
|
+
module DummyContentStore
|
5
|
+
class ExampleContentItem
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
@path = path
|
10
|
+
end
|
11
|
+
|
12
|
+
def filename
|
13
|
+
File.basename(path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def base_path
|
17
|
+
data["base_path"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def format
|
21
|
+
data["format"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def title
|
25
|
+
data["title"]
|
26
|
+
end
|
27
|
+
|
28
|
+
def view_url
|
29
|
+
"/content#{base_path}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def data
|
33
|
+
JSON.parse(raw_data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def raw_data
|
37
|
+
File.read(path, encoding: "UTF-8")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'govuk/dummy_content_store'
|
3
|
+
|
4
|
+
module Govuk
|
5
|
+
module DummyContentStore
|
6
|
+
class ExampleRepository
|
7
|
+
attr_reader :content_schemas_path
|
8
|
+
|
9
|
+
def initialize(content_schemas_path)
|
10
|
+
@content_schemas_path = Pathname.new(content_schemas_path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def find_by_base_path(base_path)
|
14
|
+
all.find { |item| item.base_path == base_path }
|
15
|
+
end
|
16
|
+
|
17
|
+
def all
|
18
|
+
all_example_paths.lazy.map { |path| ExampleContentItem.new(path) }
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def all_example_paths
|
23
|
+
Dir[content_schemas_path + "formats" + "**" + "examples" + "*.json"]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'govuk/dummy_content_store'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module Govuk
|
6
|
+
module DummyContentStore
|
7
|
+
class Index
|
8
|
+
attr_reader :example_repository
|
9
|
+
|
10
|
+
def initialize(example_repository)
|
11
|
+
@example_repository = example_repository
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
if env["PATH_INFO"] == "/"
|
16
|
+
render_index
|
17
|
+
else
|
18
|
+
[404, {}, ["Not found"]]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def render_index
|
24
|
+
status = 200
|
25
|
+
body = render_template("index.html.erb", examples: example_repository.all)
|
26
|
+
headers = {
|
27
|
+
'Content-Type' => 'text/html; charset=utf-8',
|
28
|
+
'Content-Length' => body.bytesize.to_s,
|
29
|
+
'Cache-control' => 'no-cache'
|
30
|
+
}
|
31
|
+
[status, headers, [body]]
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_template(name)
|
35
|
+
File.read(File.dirname(__FILE__) + "/templates/#{name}", encoding: "UTF-8")
|
36
|
+
end
|
37
|
+
|
38
|
+
class CleanBinding < OpenStruct
|
39
|
+
include ERB::Util
|
40
|
+
|
41
|
+
def binding
|
42
|
+
Kernel.binding
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def render_template(template_name, vars)
|
47
|
+
template = load_template(template_name)
|
48
|
+
ERB.new(template).result(CleanBinding.new(vars).binding)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html class="no-js" lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
6
|
+
<title>Dummy content store: examples list</title>
|
7
|
+
<meta name="description" content="">
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="assets/styles.css">
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<h1>Dummy content store: examples list</h1>
|
14
|
+
|
15
|
+
<table>
|
16
|
+
<thead>
|
17
|
+
<tr>
|
18
|
+
<th>Format</th>
|
19
|
+
<th>Filename</th>
|
20
|
+
<th>Title</th>
|
21
|
+
</tr>
|
22
|
+
</thead>
|
23
|
+
|
24
|
+
<tbody>
|
25
|
+
<% examples.each do |example| %>
|
26
|
+
<tr>
|
27
|
+
<td><%= h(example.format) %></a></td>
|
28
|
+
<td><%= h(example.filename) %></a></td>
|
29
|
+
<td><a href="<%= h(example.view_url) %>"><%= h(example.title) %></a></td>
|
30
|
+
</tr>
|
31
|
+
<% end %>
|
32
|
+
</tbody>
|
33
|
+
</table>
|
34
|
+
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "govuk/dummy_content_store/version"
|
2
|
+
|
3
|
+
module Govuk
|
4
|
+
module DummyContentStore
|
5
|
+
autoload :Content, "govuk/dummy_content_store/content"
|
6
|
+
autoload :ExampleContentItem, "govuk/dummy_content_store/example_content_item"
|
7
|
+
autoload :ExampleRepository, "govuk/dummy_content_store/example_repository"
|
8
|
+
autoload :Index, "govuk/dummy_content_store/index"
|
9
|
+
end
|
10
|
+
end
|
data/public/styles.css
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
{
|
2
|
+
"base_path": "/my-example",
|
3
|
+
"description": "Nearly 400 homes are set to be built on the site of a former tar distillery thanks to Gleeson Homes and HCA investment.",
|
4
|
+
"details": {
|
5
|
+
"body": "<div class=\"govspeak\"><p>A new community of nearly 400 homes is set to be built on the site of a former tar distillery thanks to Gleeson Homes and investment from the Homes and Communities Agency (<abbr title=\"Homes and Communities Agency\">HCA</abbr>).</p>\n\n<p>The Croda Tar Distillery, on the border between Kilnhurst and Swinton, closed in the early 1990s. Over the past 2 decades the 31 acre site has lain derelict with the heavily contaminated site proving a challenge for developers.</p>\n\n<p>However in 2010 Gleeson identified the site, which is adjacent to the Sheffield & South Yorkshire Navigation Canal, as having great potential for new low cost homes.</p>\n\n<p>Working with Rotherham Borough Council and remediation specialists, work is now underway to clean up the site. </p>\n\n<p>Once the clean-up has been completed Gleeson Homes will begin to transform the area into 381 new 2, 3 and 4 bedroom homes. The developer will be making use of \u00a32.2 million of investment from the Homes and Communities Agency\u2019s (<abbr title=\"Homes and Communities Agency\">HCA</abbr>) Get Britain Building programme to start the first phase of 125 homes.</p>\n\n<p>Craig Johns, Area Manager at the <abbr title=\"Homes and Communities Agency\">HCA</abbr> said: </p>\n\n<p>\u201cThe development at Carlisle Park offers a real choice of quality homes to local residents where they want to live at a price they can afford. Our investment will ensure that a local firm will provide these homes which will help safeguard jobs in South Yorkshire.\u201d</p>\n\n<p>The development will feature a mix of first time buyer and family homes, set among public open space and children\u2019s play areas.</p>\n\n<p>Steve Gamble, Gleeson Homes Group Land Director said: </p>\n\n<p>\u201cWe are delighted that Carlisle Park is part of the Get Britain Building programme. The programme will help us to deliver the first tranche of 125 new homes which are built and priced to suit local people. </p>\n\n<p>\u201cThe project will also have a positive effect of the wider community with the creation of new jobs, apprenticeship opportunities for local young people and investment back into the local area.\u201d</p>\n\n<p>A recoverable investment, the Get Britain Building programme helps developers access finance, and to help bring forward marginal sites by sharing risk. </p>\n\n<p>Up to 16,000 homes on stalled sites across England will be built by March 2015 thanks to this programme.</p></div>",
|
6
|
+
"change_note": null,
|
7
|
+
"first_public_at": "2012-12-17T15:45:44+00:00",
|
8
|
+
"image": {
|
9
|
+
"alt_text": "Carlisle Park",
|
10
|
+
"caption": "Carlisle Park",
|
11
|
+
"url": "http://static.dev.gov.uk/government/uploads/system/uploads/image_data/file/5693/s300_Carlisle_Park_1_960x640.jpg"
|
12
|
+
},
|
13
|
+
"tags": {
|
14
|
+
"browse_pages": [],
|
15
|
+
"topics": [],
|
16
|
+
"policies": []
|
17
|
+
},
|
18
|
+
"format_display_type":"case_study"
|
19
|
+
},
|
20
|
+
"format": "case_study",
|
21
|
+
"links": {
|
22
|
+
"lead_organisations": [
|
23
|
+
{
|
24
|
+
"title": "Department for International Development",
|
25
|
+
"base_path": "/government/organisations/department-for-international-development",
|
26
|
+
"api_url": "https://www.gov.uk/api/organisations/department-for-international-development",
|
27
|
+
"web_url": "https://www.gov.uk/government/organisations/department-for-international-development",
|
28
|
+
"locale": "en"
|
29
|
+
}
|
30
|
+
],
|
31
|
+
"related_policies": [],
|
32
|
+
"supporting_organisations": [],
|
33
|
+
"world_locations": [
|
34
|
+
{
|
35
|
+
"title": "Pakistan",
|
36
|
+
"base_path": "/government/world/pakistan",
|
37
|
+
"api_url": "https://www.gov.uk/api/content/government/world/pakistan",
|
38
|
+
"web_url": "https://www.gov.uk/government/world/pakistan",
|
39
|
+
"locale": "en"
|
40
|
+
}
|
41
|
+
],
|
42
|
+
"worldwide_organisations": [
|
43
|
+
{
|
44
|
+
"title": "DFID Pakistan",
|
45
|
+
"base_path": "/government/world/organisations/dfid-pakistan",
|
46
|
+
"api_url": "https://www.gov.uk/api/content/government/world/organisations/dfid-pakistan",
|
47
|
+
"web_url": "https://www.gov.uk/government/world/organisations/dfid-pakistan",
|
48
|
+
"locale": "en"
|
49
|
+
}
|
50
|
+
],
|
51
|
+
"worldwide_priorities": [],
|
52
|
+
"available_translations": [
|
53
|
+
{
|
54
|
+
"title": "Pakistan: In school for the first time",
|
55
|
+
"base_path": "/government/case-studies/pakistan-in-school-for-the-first-time",
|
56
|
+
"api_url": "https://www.gov.uk/api/content/government/case-studies/pakistan-in-school-for-the-first-time",
|
57
|
+
"web_url": "https://www.gov.uk/government/case-studies/pakistan-in-school-for-the-first-time",
|
58
|
+
"locale": "en"
|
59
|
+
},
|
60
|
+
{
|
61
|
+
"title": "پاکستان: اسکول میں پہلی بارداخلہ",
|
62
|
+
"base_path": "/government/case-studies/pakistan-in-school-for-the-first-time.ur",
|
63
|
+
"api_url": "https://www.gov.uk/api/content/government/case-studies/pakistan-in-school-for-the-first-time.ur",
|
64
|
+
"web_url": "https://www.gov.uk/government/case-studies/pakistan-in-school-for-the-first-time.ur",
|
65
|
+
"locale": "ur"
|
66
|
+
}
|
67
|
+
],
|
68
|
+
"document_collections": [
|
69
|
+
{
|
70
|
+
"title": "Work Programme real life stories",
|
71
|
+
"base_path": "/government/collections/work-programme-real-life-stories",
|
72
|
+
"api_url": "https://www.gov.uk/api/content/government/collections/work-programme-real-life-stories",
|
73
|
+
"web_url": "https://www.gov.uk/government/collections/work-programme-real-life-stories",
|
74
|
+
"locale": "en"
|
75
|
+
}
|
76
|
+
]
|
77
|
+
},
|
78
|
+
"locale": "en",
|
79
|
+
"need_ids": [],
|
80
|
+
"public_updated_at": "2012-12-17T15:45:44.000+00:00",
|
81
|
+
"title": "Get Britain Building: Carlisle Park",
|
82
|
+
"updated_at": "2014-11-17T14:19:42.460Z"
|
83
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
RSpec.describe "Dummy content store rack application" do
|
5
|
+
include Rack::Test::Methods
|
6
|
+
|
7
|
+
let(:schemas_path) { File.dirname(__FILE__) + "/../fixtures/govuk-content-schemas" }
|
8
|
+
let(:example_file_path) { schemas_path + "/formats/my-format/frontend/examples/my_example.json" }
|
9
|
+
let(:example_file_base_path) { "/my-example" }
|
10
|
+
let(:example_file_body) { File.read(example_file_path, encoding: "UTF-8") }
|
11
|
+
|
12
|
+
around(:each) do |example|
|
13
|
+
old_env = ENV['GOVUK_CONTENT_SCHEMAS_PATH']
|
14
|
+
ENV['GOVUK_CONTENT_SCHEMAS_PATH'] = schemas_path
|
15
|
+
example.run
|
16
|
+
ENV['GOVUK_CONTENT_SCHEMAS_PATH'] = old_env
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:app) {
|
20
|
+
Rack::Builder.parse_file('config.ru').first
|
21
|
+
}
|
22
|
+
|
23
|
+
it "serves the example from the /content/<base_path>" do
|
24
|
+
get "/content#{example_file_base_path}"
|
25
|
+
expect(last_response).to be_ok
|
26
|
+
expect(last_response.body).to eq(example_file_body)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "responds with 404 for unknown paths" do
|
30
|
+
get '/content/non-existent-example'
|
31
|
+
expect(last_response.status).to eq(404)
|
32
|
+
end
|
33
|
+
|
34
|
+
context "public api" do
|
35
|
+
it "serves the example from the /api/content/<base_path>" do
|
36
|
+
get "/api/content#{example_file_base_path}"
|
37
|
+
expect(last_response).to be_ok
|
38
|
+
expect(last_response.body).to eq(example_file_body)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "index page" do
|
43
|
+
before(:each) { get "/" }
|
44
|
+
|
45
|
+
it "responds with 200 OK" do
|
46
|
+
expect(last_response).to be_ok
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has content-type text/html charset utf8" do
|
50
|
+
expect(last_response.headers['content-type']).to eq('text/html; charset=utf-8')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "contains a list of all the examples" do
|
54
|
+
doc = Nokogiri::HTML(last_response.body)
|
55
|
+
|
56
|
+
bullets = doc.css('table tr td a').map { |elem| elem.content }
|
57
|
+
|
58
|
+
expect(bullets).to eq(["Get Britain Building: Carlisle Park"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "css" do
|
63
|
+
it "serves css" do
|
64
|
+
get "/assets/styles.css"
|
65
|
+
expect(last_response).to be_ok
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
4
|
+
end
|
5
|
+
|
6
|
+
config.mock_with :rspec do |mocks|
|
7
|
+
mocks.verify_partial_doubles = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.disable_monkey_patching!
|
11
|
+
|
12
|
+
config.warnings = true
|
13
|
+
|
14
|
+
if config.files_to_run.one?
|
15
|
+
config.default_formatter = 'doc'
|
16
|
+
end
|
17
|
+
|
18
|
+
config.order = :random
|
19
|
+
|
20
|
+
Kernel.srand config.seed
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: govuk-dummy_content_store
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Heath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-contrib
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem_publisher
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: nokogiri
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: ''
|
126
|
+
email:
|
127
|
+
- david.heath@digital.cabinet-office.gov.uk
|
128
|
+
executables:
|
129
|
+
- dummy_content_store
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- ".rspec"
|
135
|
+
- ".ruby-version"
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/dummy_content_store
|
141
|
+
- config.ru
|
142
|
+
- govuk-dummy_content_store.gemspec
|
143
|
+
- jenkins.sh
|
144
|
+
- lib/govuk/dummy_content_store.rb
|
145
|
+
- lib/govuk/dummy_content_store/content.rb
|
146
|
+
- lib/govuk/dummy_content_store/example_content_item.rb
|
147
|
+
- lib/govuk/dummy_content_store/example_repository.rb
|
148
|
+
- lib/govuk/dummy_content_store/index.rb
|
149
|
+
- lib/govuk/dummy_content_store/templates/index.html.erb
|
150
|
+
- lib/govuk/dummy_content_store/version.rb
|
151
|
+
- public/styles.css
|
152
|
+
- spec/fixtures/govuk-content-schemas/formats/my-format/frontend/examples/my_example.json
|
153
|
+
- spec/integration/dummy_content_store_spec.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
homepage: ''
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '2.0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.2.2
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: Rack app which serves example files from govuk-content-schemas
|
179
|
+
test_files:
|
180
|
+
- spec/fixtures/govuk-content-schemas/formats/my-format/frontend/examples/my_example.json
|
181
|
+
- spec/integration/dummy_content_store_spec.rb
|
182
|
+
- spec/spec_helper.rb
|