slimmer 1.2.5 → 2.0.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.
- data/CHANGELOG.md +14 -1
- data/lib/slimmer.rb +28 -17
- data/lib/slimmer/app.rb +9 -9
- data/lib/slimmer/headers.rb +32 -1
- data/lib/slimmer/{admin_title_inserter.rb → processors/admin_title_inserter.rb} +1 -1
- data/lib/slimmer/{body_class_copier.rb → processors/body_class_copier.rb} +1 -1
- data/lib/slimmer/{body_inserter.rb → processors/body_inserter.rb} +1 -1
- data/lib/slimmer/{conditional_comment_mover.rb → processors/conditional_comment_mover.rb} +1 -1
- data/lib/slimmer/{footer_remover.rb → processors/footer_remover.rb} +1 -1
- data/lib/slimmer/{google_analytics_configurator.rb → processors/google_analytics_configurator.rb} +3 -2
- data/lib/slimmer/{header_context_inserter.rb → processors/header_context_inserter.rb} +1 -1
- data/lib/slimmer/processors/logo_class_inserter.rb +20 -0
- data/lib/slimmer/processors/related_items_inserter.rb +20 -0
- data/lib/slimmer/{search_path_setter.rb → processors/search_path_setter.rb} +2 -4
- data/lib/slimmer/{section_inserter.rb → processors/section_inserter.rb} +1 -1
- data/lib/slimmer/{tag_mover.rb → processors/tag_mover.rb} +1 -1
- data/lib/slimmer/{title_inserter.rb → processors/title_inserter.rb} +1 -1
- data/lib/slimmer/skin.rb +28 -20
- data/lib/slimmer/template.rb +1 -1
- data/lib/slimmer/test.rb +5 -1
- data/lib/slimmer/test_template.rb +7 -1
- data/lib/slimmer/version.rb +1 -1
- data/test/fixtures/related.raw.html.erb +26 -22
- data/test/fixtures/wrapper.html.erb +2 -0
- data/test/headers_test.rb +56 -1
- data/test/processors/body_inserter_test.rb +4 -4
- data/test/{google_analytics_test.rb → processors/google_analytics_test.rb} +31 -0
- data/test/processors/header_context_inserter_test.rb +5 -5
- data/test/processors/logo_class_inserter_test.rb +55 -0
- data/test/processors/related_items_inserter_test.rb +61 -0
- data/test/{search_path_setter_test.rb → processors/search_path_setter_test.rb} +0 -0
- data/test/processors/section_inserter_test.rb +20 -5
- data/test/test_helper.rb +31 -22
- data/test/typical_usage_test.rb +101 -70
- metadata +60 -70
- data/lib/slimmer/related_items_inserter.rb +0 -36
- data/lib/slimmer/url_rewriter.rb +0 -40
@@ -1,31 +1,35 @@
|
|
1
|
-
<% if artefact
|
1
|
+
<% if artefact %>
|
2
2
|
|
3
3
|
<!-- related -->
|
4
4
|
<div class="related-positioning">
|
5
|
-
|
5
|
+
<div class="related-container">
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
<div class="related">
|
8
|
+
<div class="inner group">
|
9
|
+
<h2>Related topics</h2>
|
10
|
+
<nav role="navigation">
|
11
|
+
<ul>
|
12
|
+
<% if artefact["related_items"].any? %>
|
13
|
+
<% artefact["related_items"].each do |item| %>
|
14
|
+
<% if item["artefact"] %>
|
15
|
+
<li class="<%= h item["artefact"]["kind"] %>">
|
16
|
+
<a href="/<%= h item["artefact"]["slug"] %>"><%= h item["artefact"]["name"] %></a>
|
17
|
+
</li>
|
18
|
+
<% end %>
|
18
19
|
<% end %>
|
19
|
-
|
20
|
-
<li class="related-topic"><a href="/browse/<%= h(artefact.section.parameterize) %>"
|
21
|
-
>More from the <span><%= h(artefact.section) %></span> section</a></li>
|
22
|
-
<% end %>
|
23
|
-
</ul>
|
24
|
-
</nav>
|
25
|
-
</div>
|
26
|
-
</div>
|
20
|
+
<% end %>
|
27
21
|
|
28
|
-
|
22
|
+
<% if artefact["section"] %>
|
23
|
+
<% section, subsection = artefact["section"].split(':', 2) %>
|
24
|
+
<li class="related-topic"><a href="/browse/<%= h section.parameterize %>"
|
25
|
+
>More from the <span><%= h section %></span> section</a></li>
|
26
|
+
<% end %>
|
27
|
+
</ul>
|
28
|
+
</nav>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
</div>
|
29
33
|
</div>
|
30
34
|
<!-- end related -->
|
31
35
|
<% end %>
|
data/test/headers_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative "test_helper"
|
2
2
|
require "slimmer/headers"
|
3
3
|
|
4
4
|
class HeadersTest < MiniTest::Unit::TestCase
|
@@ -55,3 +55,58 @@ class HeadersTest < MiniTest::Unit::TestCase
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
describe Slimmer::Headers do
|
60
|
+
include Slimmer::Headers
|
61
|
+
attr_accessor :headers
|
62
|
+
|
63
|
+
before do
|
64
|
+
self.headers = {}
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "setting the artefact header" do
|
68
|
+
|
69
|
+
it "should convert a hash to JSON and insert into the header" do
|
70
|
+
artefact = {"foo" => "bar", "slug" => "vat-rates"}
|
71
|
+
self.set_slimmer_artefact(artefact)
|
72
|
+
assert_equal artefact.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should convert an OpenStruct to JSON and insert into the header" do
|
76
|
+
artefact = OpenStruct.new(section: 'missing', need_id: 'missing', kind: 'missing')
|
77
|
+
self.set_slimmer_artefact(artefact)
|
78
|
+
assert_equal artefact.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should handle an object that responds to :to_hash" do
|
82
|
+
hash = {"foo" => "bar", "slug" => "vat-rates"}
|
83
|
+
artefact = stub("Response", :to_hash => hash)
|
84
|
+
self.set_slimmer_artefact(artefact)
|
85
|
+
assert_equal hash.to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should strip the actions from the artefact" do
|
89
|
+
artefact = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
|
90
|
+
self.set_slimmer_artefact(artefact)
|
91
|
+
assert_equal ({"foo" => "bar", "slug" => "vat-rates"}).to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should strip the actions from any related items" do
|
95
|
+
artefact = {"slug" => "vat-rates", "related_items" => [
|
96
|
+
{"artefact" => {"slug" => 'a-thing', "actions" => "something"}},
|
97
|
+
{"artefact" => {"slug" => 'another-thing', "actions" => "something else"}}
|
98
|
+
]}
|
99
|
+
self.set_slimmer_artefact(artefact)
|
100
|
+
assert_equal ({"slug" => "vat-rates", "related_items" => [
|
101
|
+
{"artefact" => {"slug" => 'a-thing'}}, {"artefact" => {"slug" => 'another-thing'}}
|
102
|
+
]}).to_json, headers[Slimmer::Headers::ARTEFACT_HEADER]
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should not have side-effects on the passed in hash" do
|
106
|
+
artefact = {"foo" => "bar", "slug" => "vat-rates", "actions" => "some_actions"}
|
107
|
+
artefact_copy = artefact.dup
|
108
|
+
self.set_slimmer_artefact(artefact)
|
109
|
+
assert_equal artefact_copy, artefact
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -9,7 +9,7 @@ class BodyInserterTest < MiniTest::Unit::TestCase
|
|
9
9
|
<html><body><nav></nav><div id="wrapper"><p>this should be moved</p></div></body></html>
|
10
10
|
}
|
11
11
|
|
12
|
-
Slimmer::BodyInserter.new.filter(source, template)
|
12
|
+
Slimmer::Processors::BodyInserter.new.filter(source, template)
|
13
13
|
assert_in template, "#wrapper", %{<p>this should be moved</p>}
|
14
14
|
end
|
15
15
|
|
@@ -22,7 +22,7 @@ class BodyInserterTest < MiniTest::Unit::TestCase
|
|
22
22
|
<html><body><nav></nav><div id="wrapper"><p>#{unicode_endash}</p></div></body></html>
|
23
23
|
}
|
24
24
|
|
25
|
-
Slimmer::BodyInserter.new.filter(source, template)
|
25
|
+
Slimmer::Processors::BodyInserter.new.filter(source, template)
|
26
26
|
assert_equal unicode_endash, template.at_css("#wrapper p").inner_text
|
27
27
|
end
|
28
28
|
|
@@ -36,8 +36,8 @@ class BodyInserterTest < MiniTest::Unit::TestCase
|
|
36
36
|
<html><body><div id="some_other_id"><p>this should be moved</p></div></body></html>
|
37
37
|
}
|
38
38
|
|
39
|
-
Slimmer::BodyInserter.new("some_other_id").filter(source, template)
|
39
|
+
Slimmer::Processors::BodyInserter.new("some_other_id").filter(source, template)
|
40
40
|
assert_not_in template, "#wrapper"
|
41
41
|
assert_in template, "#some_other_id", %{<p>this should be moved</p>}
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
@@ -22,6 +22,13 @@ module GoogleAnalyticsTest
|
|
22
22
|
context.eval("_gaq");
|
23
23
|
end
|
24
24
|
|
25
|
+
def govuk
|
26
|
+
js = Nokogiri::HTML(last_response.body).at_css("#ga-params").text
|
27
|
+
context = V8::Context.new
|
28
|
+
context.eval(js)
|
29
|
+
context.eval("GOVUK.Analytics");
|
30
|
+
end
|
31
|
+
|
25
32
|
def assert_custom_var(slot, name, value, page_level)
|
26
33
|
# Ruby Racer JS arrays don't accept range indexing, so we must
|
27
34
|
# use a slightly longer workaround
|
@@ -30,6 +37,10 @@ module GoogleAnalyticsTest
|
|
30
37
|
assert_includes vars, [slot, name, value, page_level]
|
31
38
|
end
|
32
39
|
|
40
|
+
def assert_set_var(name, value, object)
|
41
|
+
assert_equal value, object.find { |each| each[0] == name }[1]
|
42
|
+
end
|
43
|
+
|
33
44
|
def refute_custom_var(name)
|
34
45
|
vars = gaq.select { |a| a[0] == "_setCustomVar" }.map { |a| a[2] }
|
35
46
|
refute_includes vars, name
|
@@ -54,21 +65,41 @@ module GoogleAnalyticsTest
|
|
54
65
|
assert_custom_var 1, "Section", "rhubarb", PAGE_LEVEL_EVENT
|
55
66
|
end
|
56
67
|
|
68
|
+
def test_should_set_section_in_GOVUK_object
|
69
|
+
assert_set_var "Section", "rhubarb", govuk
|
70
|
+
end
|
71
|
+
|
57
72
|
def test_should_pass_internal_format_name_to_GA
|
58
73
|
assert_custom_var 2, "Format", "custard", PAGE_LEVEL_EVENT
|
59
74
|
end
|
60
75
|
|
76
|
+
def test_should_set_section_in_GOVUK_object
|
77
|
+
assert_set_var "Format", "custard", govuk
|
78
|
+
end
|
79
|
+
|
61
80
|
def test_should_pass_need_ID_to_GA
|
62
81
|
assert_custom_var 3, "NeedID", "42", PAGE_LEVEL_EVENT
|
63
82
|
end
|
64
83
|
|
84
|
+
def test_should_set_section_in_GOVUK_object
|
85
|
+
assert_set_var "NeedID", "42", govuk
|
86
|
+
end
|
87
|
+
|
65
88
|
def test_should_pass_proposition_to_GA
|
66
89
|
assert_custom_var 4, "Proposition", "trifle", PAGE_LEVEL_EVENT
|
67
90
|
end
|
68
91
|
|
92
|
+
def test_should_set_section_in_GOVUK_object
|
93
|
+
assert_set_var "Proposition", "trifle", govuk
|
94
|
+
end
|
95
|
+
|
69
96
|
def test_should_pass_result_count_to_GA
|
70
97
|
assert_custom_var 5, "ResultCount", "3", PAGE_LEVEL_EVENT
|
71
98
|
end
|
99
|
+
|
100
|
+
def test_should_set_section_in_GOVUK_object
|
101
|
+
assert_set_var "ResultCount", "3", govuk
|
102
|
+
end
|
72
103
|
end
|
73
104
|
|
74
105
|
class WithoutHeadersTest < SlimmerIntegrationTest
|
@@ -9,7 +9,7 @@ class HeaderContextInserterTest < MiniTest::Unit::TestCase
|
|
9
9
|
<html><body><nav></nav><div class="header-context"><p>this should be moved</p></div></body></html>
|
10
10
|
}
|
11
11
|
|
12
|
-
Slimmer::HeaderContextInserter.new.filter(source, template)
|
12
|
+
Slimmer::Processors::HeaderContextInserter.new.filter(source, template)
|
13
13
|
assert_in template, ".header-context", %{<p>this should be moved</p>}
|
14
14
|
end
|
15
15
|
|
@@ -21,7 +21,7 @@ class HeaderContextInserterTest < MiniTest::Unit::TestCase
|
|
21
21
|
<html><body><nav></nav><div class="header-context app-class"><p>this should be moved</p></div></body></html>
|
22
22
|
}
|
23
23
|
|
24
|
-
Slimmer::HeaderContextInserter.new.filter(source, template)
|
24
|
+
Slimmer::Processors::HeaderContextInserter.new.filter(source, template)
|
25
25
|
assert_in template, ".header-context.app-class", %{<p>this should be moved</p>}
|
26
26
|
assert_not_in template, ".header-context.template-class"
|
27
27
|
end
|
@@ -34,7 +34,7 @@ class HeaderContextInserterTest < MiniTest::Unit::TestCase
|
|
34
34
|
<html><body><nav></nav></body></html>
|
35
35
|
}
|
36
36
|
|
37
|
-
Slimmer::HeaderContextInserter.new.filter(source, template)
|
37
|
+
Slimmer::Processors::HeaderContextInserter.new.filter(source, template)
|
38
38
|
assert_in template, ".header-context", %{should not be removed}
|
39
39
|
end
|
40
40
|
|
@@ -46,6 +46,6 @@ class HeaderContextInserterTest < MiniTest::Unit::TestCase
|
|
46
46
|
<html><body><div><div class="header-context">should be ignored</div></div></body></html>
|
47
47
|
}
|
48
48
|
|
49
|
-
Slimmer::HeaderContextInserter.new.filter(source, template) # should not raise
|
49
|
+
Slimmer::Processors::HeaderContextInserter.new.filter(source, template) # should not raise
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative "../test_helper.rb"
|
2
|
+
|
3
|
+
describe Slimmer::Processors::LogoClassInserter do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@artefact = {
|
7
|
+
"slug" => "vat",
|
8
|
+
"tag_ids" => ['businesslink']
|
9
|
+
}
|
10
|
+
@processor = Slimmer::Processors::LogoClassInserter.new(@artefact)
|
11
|
+
@template = as_nokogiri %{
|
12
|
+
<html><body><div><div id="wrapper"></div></div></body></html>
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should add businesslink class to the wrapper" do
|
17
|
+
@processor.filter(:any_source, @template)
|
18
|
+
assert_in @template, "div#wrapper.businesslink"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should add multiple classes to the wrapper" do
|
22
|
+
@artefact["tag_ids"] = ['businesslink', 'directgov']
|
23
|
+
@processor.filter(:any_source, @template)
|
24
|
+
assert_in @template, "div#wrapper.businesslink.directgov"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should ignore non-known tags" do
|
28
|
+
@artefact["tag_ids"] = ['businesslink', 'business', 'fooey']
|
29
|
+
@processor.filter(:any_source, @template)
|
30
|
+
assert_in @template, "div#wrapper.businesslink"
|
31
|
+
assert_not_in @template, "div#wrapper.business"
|
32
|
+
assert_not_in @template, "div#wrapper.fooey"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should do nothing if the #wrapper element doesn't exist" do
|
36
|
+
@template = as_nokogiri %{
|
37
|
+
<html><body><div><div id="not_wrapper"></div></div></body></html>
|
38
|
+
}
|
39
|
+
@processor.filter(:any_source, @template)
|
40
|
+
assert_in @template, "div#not_wrapper"
|
41
|
+
assert_not_in @template, "div#wrapper"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should do nothing if the artefact has no tag_ids" do
|
45
|
+
@artefact.delete("tag_ids")
|
46
|
+
@processor.filter(:any_source, @template)
|
47
|
+
assert_in @template, "div#wrapper"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should not blow up without an artefact" do
|
51
|
+
processor = Slimmer::Processors::LogoClassInserter.new(nil)
|
52
|
+
# assert_nothing_raised
|
53
|
+
processor.filter(:any_source, @template)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
class RelatedItemsInserterTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@related_template = File.read( File.dirname(__FILE__) + "/../fixtures/related.raw.html.erb" )
|
8
|
+
@artefact = {
|
9
|
+
'slug' => 'vat',
|
10
|
+
'title' => 'VAT',
|
11
|
+
'related_items' => [
|
12
|
+
{ 'artefact' => { 'kind' => 'answer', 'name' => 'VAT rates', 'slug' => 'vat-rates' } },
|
13
|
+
{ 'artefact' => { 'kind' => 'guide', 'name' => 'Starting to import', 'slug' => 'starting-to-import' } },
|
14
|
+
]
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_add_related_items
|
19
|
+
source = as_nokogiri %{
|
20
|
+
<html>
|
21
|
+
<body class="mainstream">
|
22
|
+
<div id="wrapper">The body of the page<div id="related-items"></div></div>
|
23
|
+
</body>
|
24
|
+
</html>
|
25
|
+
}
|
26
|
+
template = as_nokogiri %{
|
27
|
+
<html>
|
28
|
+
<body class="mainstream">
|
29
|
+
<div id="wrapper"></div>
|
30
|
+
<div id="related-items"></div>
|
31
|
+
</body>
|
32
|
+
</html>
|
33
|
+
}
|
34
|
+
|
35
|
+
Slimmer::Processors::RelatedItemsInserter.new(@related_template, @artefact).filter(source, template)
|
36
|
+
assert_in template, "div.related h2", "Related topics"
|
37
|
+
assert_in template, "div.related nav[role=navigation] ul li.answer:nth-child(1) a[href='/vat-rates']", "VAT rates"
|
38
|
+
assert_in template, "div.related nav[role=navigation] ul li.guide:nth-child(2) a[href='/starting-to-import']", "Starting to import"
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_should_not_add_related_items_for_non_mainstream_source
|
42
|
+
source = as_nokogiri %{
|
43
|
+
<html>
|
44
|
+
<body class="nonmainstream">
|
45
|
+
<div id="wrapper">The body of the page<div id="related-items"></div></div>
|
46
|
+
</body>
|
47
|
+
</html>
|
48
|
+
}
|
49
|
+
template = as_nokogiri %{
|
50
|
+
<html>
|
51
|
+
<body class="mainstream">
|
52
|
+
<div id="wrapper"></div>
|
53
|
+
<div id="related-items"></div>
|
54
|
+
</body>
|
55
|
+
</html>
|
56
|
+
}
|
57
|
+
|
58
|
+
Slimmer::Processors::RelatedItemsInserter.new(@related_template, @artefact).filter(source, template)
|
59
|
+
assert_not_in template, "div.related"
|
60
|
+
end
|
61
|
+
end
|
File without changes
|
@@ -20,7 +20,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
20
20
|
</html>
|
21
21
|
}
|
22
22
|
|
23
|
-
Slimmer::SectionInserter.new.filter(:any_source, template)
|
23
|
+
Slimmer::Processors::SectionInserter.new.filter(:any_source, template)
|
24
24
|
assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
|
25
25
|
assert_in template, "nav[role=navigation] ol li:nth-child(2)", %{<a href="/browse/business">Business</a>}
|
26
26
|
end
|
@@ -43,7 +43,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
43
43
|
</html>
|
44
44
|
}
|
45
45
|
|
46
|
-
Slimmer::SectionInserter.new.filter(:any_source, template)
|
46
|
+
Slimmer::Processors::SectionInserter.new.filter(:any_source, template)
|
47
47
|
assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
|
48
48
|
assert_in template, "nav[role=navigation] ol li:nth-child(2)", %{<a href="/browse">All Sections</a>}
|
49
49
|
assert_in template, "nav[role=navigation] ol li:nth-child(3)", %{<a href="/browse/business">Business</a>}
|
@@ -63,7 +63,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
63
63
|
</html>
|
64
64
|
}
|
65
65
|
|
66
|
-
Slimmer::SectionInserter.new.filter(:any_source, template)
|
66
|
+
Slimmer::Processors::SectionInserter.new.filter(:any_source, template)
|
67
67
|
assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
|
68
68
|
assert_not_in template, "nav[role=navigation] ol li:nth-child(2)"
|
69
69
|
end
|
@@ -82,7 +82,7 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
82
82
|
</html>
|
83
83
|
}
|
84
84
|
|
85
|
-
Slimmer::SectionInserter.new.filter(:any_source, template)
|
85
|
+
Slimmer::Processors::SectionInserter.new.filter(:any_source, template)
|
86
86
|
assert_in template, "nav[role=navigation] ol li:nth-child(1)", %{<a href="/">Home</a>}
|
87
87
|
assert_not_in template, "nav[role=navigation] ol li:nth-child(2)"
|
88
88
|
end
|
@@ -99,7 +99,22 @@ class SectionInserterTest < MiniTest::Unit::TestCase
|
|
99
99
|
</html>
|
100
100
|
}
|
101
101
|
|
102
|
-
Slimmer::SectionInserter.new.filter(:any_source, template)
|
102
|
+
Slimmer::Processors::SectionInserter.new.filter(:any_source, template)
|
103
103
|
assert_not_in template, "nav[role=navigation]"
|
104
104
|
end
|
105
|
+
|
106
|
+
def test_should_not_blow_up_without_an_artefact
|
107
|
+
template = as_nokogiri %{
|
108
|
+
<html>
|
109
|
+
<body>
|
110
|
+
<nav role="navigation">
|
111
|
+
<ol><li><a href="/">Home</a></li></ol>
|
112
|
+
</nav>
|
113
|
+
</body>
|
114
|
+
</html>
|
115
|
+
}
|
116
|
+
|
117
|
+
# assert_nothing_raised do
|
118
|
+
Slimmer::Processors::SectionInserter.new(nil).filter(:any_source, template)
|
119
|
+
end
|
105
120
|
end
|
data/test/test_helper.rb
CHANGED
@@ -15,11 +15,17 @@ class MiniTest::Unit::TestCase
|
|
15
15
|
Nokogiri::HTML.parse(html_string.strip)
|
16
16
|
end
|
17
17
|
|
18
|
-
def assert_in(template, selector, content, message=nil)
|
19
|
-
|
18
|
+
def assert_in(template, selector, content=nil, message=nil)
|
19
|
+
message ||= "Expected to find #{content ? "#{content.inspect} at " : ""}#{selector.inspect} in the output template"
|
20
|
+
|
21
|
+
assert template.at_css(selector), message + ", but selector not found."
|
22
|
+
|
23
|
+
if content
|
24
|
+
assert_equal content, template.at_css(selector).inner_html.to_s, message
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
|
-
def assert_not_in(template, selector, message="didn't
|
28
|
+
def assert_not_in(template, selector, message="didn't expect to find #{selector}")
|
23
29
|
refute template.at_css(selector), message
|
24
30
|
end
|
25
31
|
|
@@ -34,32 +40,35 @@ end
|
|
34
40
|
class SlimmerIntegrationTest < MiniTest::Unit::TestCase
|
35
41
|
include Rack::Test::Methods
|
36
42
|
|
43
|
+
# given_response can either be called from a setup method, or in the class scope.
|
44
|
+
# The setup method variant is necessary if you want to pass variables into the call that
|
45
|
+
# are created in higher setup methods.
|
37
46
|
def self.given_response(code, body, headers={}, app_options={})
|
38
|
-
define_method(:
|
39
|
-
|
40
|
-
|
41
|
-
}
|
42
|
-
Slimmer::App.new inner_app, {asset_host: "http://template.local"}.merge(app_options)
|
43
|
-
end
|
44
|
-
|
45
|
-
define_method :teardown do
|
46
|
-
WebMock.reset!
|
47
|
+
define_method(:setup) do
|
48
|
+
super()
|
49
|
+
given_response(code, body, headers, app_options)
|
47
50
|
end
|
51
|
+
end
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
def given_response(code, body, headers={}, app_options={})
|
54
|
+
self.class.class_eval do
|
55
|
+
define_method(:app) do
|
56
|
+
inner_app = proc { |env|
|
57
|
+
[code, {"Content-Type" => "text/html"}.merge(headers), body]
|
58
|
+
}
|
59
|
+
Slimmer::App.new inner_app, {asset_host: "http://template.local"}.merge(app_options)
|
54
60
|
end
|
61
|
+
end
|
55
62
|
|
56
|
-
|
57
|
-
|
63
|
+
template_name = case code
|
64
|
+
when 200 then 'wrapper'
|
65
|
+
when 404 then '404'
|
66
|
+
else '500'
|
58
67
|
end
|
59
|
-
end
|
60
68
|
|
61
|
-
|
62
|
-
|
69
|
+
use_template(template_name)
|
70
|
+
use_template('related.raw')
|
71
|
+
|
63
72
|
fetch_page
|
64
73
|
end
|
65
74
|
|