slimmer 10.0.0 → 10.1.0
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +6 -31
- data/Rakefile +0 -6
- data/lib/slimmer.rb +12 -2
- data/lib/slimmer/app.rb +1 -4
- data/lib/slimmer/component_resolver.rb +2 -6
- data/lib/slimmer/govuk_components.rb +12 -0
- data/lib/slimmer/govuk_request_id.rb +0 -5
- data/lib/slimmer/headers.rb +42 -0
- data/lib/slimmer/http_client.rb +16 -0
- data/lib/slimmer/i18n_backend.rb +3 -10
- data/lib/slimmer/skin.rb +3 -7
- data/lib/slimmer/version.rb +1 -1
- metadata +20 -72
- data/lib/slimmer/cache.rb +0 -46
- data/test/cache_test.rb +0 -53
- data/test/changelog_test.rb +0 -10
- data/test/component_resolver_test.rb +0 -41
- data/test/fixtures/404.html.erb +0 -13
- data/test/fixtures/410.html.erb +0 -13
- data/test/fixtures/500.html.erb +0 -13
- data/test/fixtures/core_layout.html.erb +0 -19
- data/test/fixtures/proposition_menu.html.erb +0 -7
- data/test/fixtures/report_a_problem.raw.html.erb +0 -23
- data/test/headers_test.rb +0 -57
- data/test/processors/body_inserter_test.rb +0 -43
- data/test/processors/header_context_inserter_test.rb +0 -51
- data/test/processors/inside_header_inserter_test.rb +0 -35
- data/test/processors/metadata_inserter_test.rb +0 -86
- data/test/processors/navigation_mover_test.rb +0 -53
- data/test/processors/report_a_problem_inserter_test.rb +0 -75
- data/test/processors/search_parameter_inserter_test.rb +0 -39
- data/test/processors/search_path_setter_test.rb +0 -39
- data/test/processors/search_remover_test.rb +0 -62
- data/test/processors/tag_mover_test.rb +0 -95
- data/test/skin_test.rb +0 -99
- data/test/test_helper.rb +0 -136
- data/test/test_helpers/govuk_components_test.rb +0 -19
- data/test/test_template_dependency_on_static_test.rb +0 -25
- data/test/typical_usage_test.rb +0 -358
@@ -1,86 +0,0 @@
|
|
1
|
-
require_relative "../test_helper"
|
2
|
-
|
3
|
-
module MetadataInserterTest
|
4
|
-
|
5
|
-
GENERIC_DOCUMENT = <<-END
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
<title>The title of the page</title>
|
9
|
-
</head>
|
10
|
-
<body class="body_class">
|
11
|
-
<div id="wrapper">The body of the page</div>
|
12
|
-
</body>
|
13
|
-
</html>
|
14
|
-
END
|
15
|
-
|
16
|
-
module MetaTagAssertions
|
17
|
-
def assert_meta_tag(name, content)
|
18
|
-
template = Nokogiri::HTML(last_response.body)
|
19
|
-
assert_in template, "head meta[name='govuk:#{name}'][content='#{content}']"
|
20
|
-
end
|
21
|
-
|
22
|
-
def refute_meta_tag(name)
|
23
|
-
template = Nokogiri::HTML(last_response.body)
|
24
|
-
assert_not_in template, "head meta[name='govuk:#{name}']"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class WithHeadersTest < SlimmerIntegrationTest
|
29
|
-
include MetaTagAssertions
|
30
|
-
|
31
|
-
def setup
|
32
|
-
super
|
33
|
-
|
34
|
-
headers = {
|
35
|
-
Slimmer::Headers::FORMAT_HEADER => "custard",
|
36
|
-
Slimmer::Headers::RESULT_COUNT_HEADER => "3",
|
37
|
-
Slimmer::Headers::ORGANISATIONS_HEADER => "<P1><D422>",
|
38
|
-
Slimmer::Headers::WORLD_LOCATIONS_HEADER => "<WL3>"
|
39
|
-
}
|
40
|
-
|
41
|
-
given_response 200, GENERIC_DOCUMENT, headers
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_should_include_format_meta_tag
|
45
|
-
assert_meta_tag "format", "custard"
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_should_include_organisations_meta_tag
|
49
|
-
assert_meta_tag "analytics:organisations", "<P1><D422>"
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_should_include_world_locations_meta_tag
|
53
|
-
assert_meta_tag "analytics:world-locations", "<WL3>"
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_should_include_search_result_count_meta_tag
|
57
|
-
assert_meta_tag "search-result-count", "3"
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class WithoutHeadersTest < SlimmerIntegrationTest
|
62
|
-
include MetaTagAssertions
|
63
|
-
|
64
|
-
given_response 200, GENERIC_DOCUMENT, {}
|
65
|
-
|
66
|
-
def test_should_omit_section
|
67
|
-
refute_meta_tag "section"
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_should_omit_internal_format_name
|
71
|
-
refute_meta_tag "format"
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_should_omit_organisations
|
75
|
-
refute_meta_tag "analytics:organisations"
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_should_omit_world_locations
|
79
|
-
refute_meta_tag "analytics:world-locations"
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_should_omit_result_count
|
83
|
-
refute_meta_tag "search-result-count"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
class NavigationMoverTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
@proposition_header_block = File.read( File.dirname(__FILE__) + "/../fixtures/proposition_menu.html.erb" )
|
7
|
-
@skin = stub("Skin", :template => @proposition_header_block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_should_add_proposition_menu
|
11
|
-
source = as_nokogiri %{
|
12
|
-
<html>
|
13
|
-
<body>
|
14
|
-
<div id="proposition-menu"></div>
|
15
|
-
</body>
|
16
|
-
</html>
|
17
|
-
}
|
18
|
-
template = as_nokogiri %{
|
19
|
-
<html>
|
20
|
-
<body>
|
21
|
-
<div id="global-header"><div class="header-wrapper"></div></div>
|
22
|
-
<div id="wrapper"></div>
|
23
|
-
</body>
|
24
|
-
</html>
|
25
|
-
}
|
26
|
-
|
27
|
-
Slimmer::Processors::NavigationMover.new(@skin).filter(source, template)
|
28
|
-
assert_in template, "div#global-header.with-proposition"
|
29
|
-
assert_in template, "div#global-header #proposition-menu a", "Navigation item"
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_should_not_add_proposition_menu_if_not_in_source
|
33
|
-
source = as_nokogiri %{
|
34
|
-
<html>
|
35
|
-
<body>
|
36
|
-
<div id="wrapper"></div>
|
37
|
-
</body>
|
38
|
-
</html>
|
39
|
-
}
|
40
|
-
template = as_nokogiri %{
|
41
|
-
<html>
|
42
|
-
<body>
|
43
|
-
<div id="global_header"><div class="header-wrapper"></div></div>
|
44
|
-
<div id="wrapper"></div>
|
45
|
-
</body>
|
46
|
-
</html>
|
47
|
-
}
|
48
|
-
|
49
|
-
@skin.expects(:template).never # Shouldn't fetch template when not inserting block
|
50
|
-
Slimmer::Processors::NavigationMover.new(@skin).filter(source, template)
|
51
|
-
assert_not_in template, "div#proposition_menu"
|
52
|
-
end
|
53
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require_relative '../test_helper'
|
2
|
-
|
3
|
-
class ReportAProblemInserterTest < MiniTest::Test
|
4
|
-
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
@report_a_problem_template = File.read( File.dirname(__FILE__) + "/../fixtures/report_a_problem.raw.html.erb", :encoding => 'utf-8')
|
8
|
-
@skin = stub("Skin", :template => nil)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_should_add_report_a_problem_form_using_the_template_from_static
|
12
|
-
@skin.expects(:template).with('report_a_problem.raw').returns(@report_a_problem_template)
|
13
|
-
|
14
|
-
headers = { Slimmer::Headers::APPLICATION_NAME_HEADER => 'government' }
|
15
|
-
Slimmer::Processors::ReportAProblemInserter.new(
|
16
|
-
@skin,
|
17
|
-
"http://www.example.com/somewhere?foo=bar",
|
18
|
-
headers,
|
19
|
-
"wrapper"
|
20
|
-
).filter(:any_source, template)
|
21
|
-
|
22
|
-
assert_in template, "#wrapper div.report-a-problem-container"
|
23
|
-
assert_in template, "div.report-a-problem-container form input[name=url][value='http://www.example.com/somewhere?foo=bar']"
|
24
|
-
assert_in template, "div.report-a-problem-container form input[name=source][value='government']"
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_should_add_page_owner_if_provided_in_headers
|
28
|
-
@skin.expects(:template).with('report_a_problem.raw').returns(@report_a_problem_template)
|
29
|
-
headers = { Slimmer::Headers::PAGE_OWNER_HEADER => 'hmrc' }
|
30
|
-
Slimmer::Processors::ReportAProblemInserter.new(
|
31
|
-
@skin,
|
32
|
-
"http://www.example.com/somewhere",
|
33
|
-
headers,
|
34
|
-
"wrapper"
|
35
|
-
).filter(:any_source, template)
|
36
|
-
|
37
|
-
assert_in template, "#wrapper div.report-a-problem-container"
|
38
|
-
assert_in template, "div.report-a-problem-container form input[name=page_owner][value='hmrc']"
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_should_not_add_report_a_problem_form_if_wrapper_element_missing
|
42
|
-
template = as_nokogiri %{
|
43
|
-
<html>
|
44
|
-
<body class="mainstream">
|
45
|
-
</body>
|
46
|
-
</html>
|
47
|
-
}
|
48
|
-
|
49
|
-
@skin.expects(:template).never # Shouldn't fetch template when not inserting block
|
50
|
-
|
51
|
-
Slimmer::Processors::ReportAProblemInserter.new(@skin, "", {}, "wrapper").filter(:any_source, template)
|
52
|
-
assert_not_in template, "div.report-a-problem-container"
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_should_not_add_report_a_problem_form_if_app_opts_out_in_header
|
56
|
-
@skin.expects(:template).never
|
57
|
-
headers = { Slimmer::Headers::REPORT_A_PROBLEM_FORM => 'false' }
|
58
|
-
Slimmer::Processors::ReportAProblemInserter.new(@skin, "", headers, "wrapper").filter(:any_source, template)
|
59
|
-
assert_not_in template, "div.report-a-problem-container"
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def template
|
65
|
-
@template ||= as_nokogiri %{
|
66
|
-
<html>
|
67
|
-
<body">
|
68
|
-
<div id="wrapper">
|
69
|
-
<div id="content"></div>
|
70
|
-
</div>
|
71
|
-
</body>
|
72
|
-
</html>
|
73
|
-
}
|
74
|
-
end
|
75
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module SearchParameterInserterTest
|
4
|
-
|
5
|
-
DOCUMENT_WITH_SEARCH = <<-END
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
</head>
|
9
|
-
<body class="body_class">
|
10
|
-
<div id="wrapper">
|
11
|
-
<form id="search" action="/path/to/search">
|
12
|
-
</form>
|
13
|
-
</div>
|
14
|
-
</body>
|
15
|
-
</html>
|
16
|
-
END
|
17
|
-
|
18
|
-
class WithHeaderTest < SlimmerIntegrationTest
|
19
|
-
headers = {
|
20
|
-
"X-Slimmer-Search-Parameters" => '{"filter_organisations": ["land-registry"], "count": 20}',
|
21
|
-
}
|
22
|
-
|
23
|
-
given_response 200, DOCUMENT_WITH_SEARCH, headers
|
24
|
-
|
25
|
-
def test_should_add_hidden_input
|
26
|
-
hidden_inputs = Nokogiri::HTML.parse(last_response.body).css('#search input[type=hidden]')
|
27
|
-
assert_equal %{<input type="hidden" name="filter_organisations[]" value="land-registry"><input type="hidden" name="count" value="20">}, hidden_inputs.to_s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class WithoutHeaderTest < SlimmerIntegrationTest
|
32
|
-
given_response 200, DOCUMENT_WITH_SEARCH, {}
|
33
|
-
|
34
|
-
def test_should_leave_original_search_action
|
35
|
-
hidden_inputs = Nokogiri::HTML.parse(last_response.body).at_css('#search input[type=hidden]')
|
36
|
-
assert_equal nil, hidden_inputs
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
module SearchPathSetterTest
|
4
|
-
|
5
|
-
DOCUMENT_WITH_SEARCH = <<-END
|
6
|
-
<html>
|
7
|
-
<head>
|
8
|
-
</head>
|
9
|
-
<body class="body_class">
|
10
|
-
<div id="wrapper">
|
11
|
-
<form id="search" action="/path/to/search">
|
12
|
-
</form>
|
13
|
-
</div>
|
14
|
-
</body>
|
15
|
-
</html>
|
16
|
-
END
|
17
|
-
|
18
|
-
class WithHeaderTest < SlimmerIntegrationTest
|
19
|
-
headers = {
|
20
|
-
"X-Slimmer-Search-Path" => "/specialist/search",
|
21
|
-
}
|
22
|
-
|
23
|
-
given_response 200, DOCUMENT_WITH_SEARCH, headers
|
24
|
-
|
25
|
-
def test_should_rewrite_search_action
|
26
|
-
search_action = Nokogiri::HTML.parse(last_response.body).at_css('#search')["action"]
|
27
|
-
assert_equal "/specialist/search", search_action
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class WithoutHeaderTest < SlimmerIntegrationTest
|
32
|
-
given_response 200, DOCUMENT_WITH_SEARCH, {}
|
33
|
-
|
34
|
-
def test_should_leave_original_search_action
|
35
|
-
search_action = Nokogiri::HTML.parse(last_response.body).at_css('#search')["action"]
|
36
|
-
assert_equal "/path/to/search", search_action
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require_relative "../test_helper"
|
2
|
-
|
3
|
-
class SearchRemoverTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
@template = as_nokogiri %{
|
7
|
-
<html>
|
8
|
-
<head>
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
<div id='global-header'>
|
12
|
-
<a href='#search'></a>
|
13
|
-
<div id='search'></div>
|
14
|
-
</div>
|
15
|
-
<div id='search'></div>
|
16
|
-
</body>
|
17
|
-
</html>
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_should_remove_search_from_template_if_header_is_set
|
22
|
-
|
23
|
-
headers = { Slimmer::Headers::REMOVE_SEARCH_HEADER => true }
|
24
|
-
Slimmer::Processors::SearchRemover.new(
|
25
|
-
headers,
|
26
|
-
).filter(nil, @template)
|
27
|
-
|
28
|
-
assert_not_in @template, "#global-header #search"
|
29
|
-
assert_in @template, "#search"
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_should_not_remove_search_from_template_if_header_is_not_set
|
34
|
-
|
35
|
-
headers = {}
|
36
|
-
Slimmer::Processors::SearchRemover.new(
|
37
|
-
headers,
|
38
|
-
).filter(nil, @template)
|
39
|
-
|
40
|
-
assert_in @template, "#global-header #search"
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_should_remove_search_link_from_template_if_header_is_set
|
44
|
-
|
45
|
-
headers = { Slimmer::Headers::REMOVE_SEARCH_HEADER => true }
|
46
|
-
Slimmer::Processors::SearchRemover.new(
|
47
|
-
headers,
|
48
|
-
).filter(nil, @template)
|
49
|
-
|
50
|
-
assert_not_in @template, "#global-header a[href='#search']"
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_not_remove_search_link_from_template_if_header_is_not_set
|
54
|
-
|
55
|
-
headers = {}
|
56
|
-
Slimmer::Processors::SearchRemover.new(
|
57
|
-
headers,
|
58
|
-
).filter(nil, @template)
|
59
|
-
|
60
|
-
assert_in @template, "#global-header a[href='#search']"
|
61
|
-
end
|
62
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require_relative "../test_helper"
|
2
|
-
|
3
|
-
class TagMoverTest < MiniTest::Test
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
@source = as_nokogiri %{
|
7
|
-
<html>
|
8
|
-
<head>
|
9
|
-
<link rel="stylesheet" href="http://www.example.com/foo.css" />
|
10
|
-
<link rel="hrefless_link" />
|
11
|
-
<link rel="stylesheet" href="http://www.example.com/duplicate.css" />
|
12
|
-
<meta name="foo" content="bar" />
|
13
|
-
<meta name="no_content" />
|
14
|
-
<meta content="no_name" />
|
15
|
-
<meta name="duplicate" content="name and content" />
|
16
|
-
<meta property="p:baz" content="bat" />
|
17
|
-
<meta property="p:empty" />
|
18
|
-
<meta property="p:duplicate" content="name and content" />
|
19
|
-
</head>
|
20
|
-
<body class="mainstream">
|
21
|
-
<div id="wrapper"></div>
|
22
|
-
<script src="http://www.example.com/foo.js"></script>
|
23
|
-
<script src="http://www.example.com/duplicate.js"></script>
|
24
|
-
</body>
|
25
|
-
</html>
|
26
|
-
}
|
27
|
-
@template = as_nokogiri %{
|
28
|
-
<html>
|
29
|
-
<head>
|
30
|
-
<link rel="stylesheet" href="http://www.example.com/duplicate.css" />
|
31
|
-
<meta name="duplicate" content="name and content" />
|
32
|
-
<meta property="p:duplicate" content="name and content" />
|
33
|
-
</head>
|
34
|
-
<body class="mainstream">
|
35
|
-
<div id="wrapper"></div>
|
36
|
-
<div id="related-items"></div>
|
37
|
-
<script src="http://www.example.com/duplicate.js"></script>
|
38
|
-
<script src="http://www.example.com/existing.js"></script>
|
39
|
-
</body>
|
40
|
-
</html>
|
41
|
-
}
|
42
|
-
Slimmer::Processors::TagMover.new.filter(@source, @template)
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_should_move_script_tags_into_the_body
|
46
|
-
assert_in @template, "script[src='http://www.example.com/foo.js']", nil, "Should have moved the script tag with src 'http://www.example.com/foo.js'"
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_should_ignore_script_tags_already_in_the_destination_with_the_same_src_and_content
|
50
|
-
assert @template.css("script[src='http://www.example.com/duplicate.js']").length == 1, "Expected there to only be one script tag with src 'http://www.example.com/duplicate.js'"
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_should_place_source_script_tags_after_template_ones
|
54
|
-
assert @template.to_s.index("foo.js") > @template.to_s.index("existing.js"), "Expected foo.js to be after existing.js"
|
55
|
-
end
|
56
|
-
|
57
|
-
|
58
|
-
def test_should_move_link_tags_into_the_head
|
59
|
-
assert_in @template, "link[href='http://www.example.com/foo.css']", nil, "Should have moved the link tag with href 'http://www.example.com/foo.css'"
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_should_ignore_link_tags_with_no_href
|
63
|
-
assert_not_in @template, "link[rel='hrefless_link']"
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_should_ignore_link_tags_already_in_the_destination_with_the_same_href
|
67
|
-
assert @template.css("link[href='http://www.example.com/duplicate.css']").length == 1, "Expected there to only be one link tag with href 'http://www.example.com/duplicate.css'"
|
68
|
-
end
|
69
|
-
|
70
|
-
|
71
|
-
def test_should_move_meta_tags_into_the_head
|
72
|
-
assert_in @template, "meta[name='foo'][content='bar']", nil, "Should have moved the foo=bar meta tag"
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_should_ignore_meta_tags_with_no_name_or_content
|
76
|
-
assert_not_in @template, "meta[name='no_content']"
|
77
|
-
assert_not_in @template, "meta[content='no_name']"
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_should_move_meta_tags_with_property_into_the_head
|
81
|
-
assert_in @template, "meta[property='p:baz'][content='bat']", nil, "Should have moved the a:baz=bat meta (property) tag"
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_should_ignore_meta_tags_with_property_but_no_content
|
85
|
-
assert_not_in @template, "meta[property='p:empty']"
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_should_ignore_meta_tags_already_in_the_destination_with_the_same_name_and_content
|
89
|
-
assert @template.css("meta[name='duplicate'][content='name and content']").length == 1, "Expected there to only be one duplicate=name and content meta tag."
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_should_ignore_meta_tags_with_property_already_in_the_destination_with_the_same_name_and_content
|
93
|
-
assert @template.css("meta[property='p:duplicate'][content='name and content']").length == 1, "Expected there to only be one duplicate=name and content meta (property) tag."
|
94
|
-
end
|
95
|
-
end
|