govspeak 3.6.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,153 @@
1
+ # encoding: utf-8
2
+
3
+ require 'test_helper'
4
+ require 'ostruct'
5
+
6
+ class HCardPresenterTest < Minitest::Test
7
+
8
+ def unindent(html)
9
+ html.gsub(/^\s+/, '')
10
+ end
11
+
12
+ test "renders address in UK format" do
13
+ assert_equal unindent(gb_addr), HCardPresenter.new(addr_fields, 'GB').render
14
+ end
15
+
16
+ test "renders address in Spanish format" do
17
+ assert_equal unindent(es_addr), HCardPresenter.new(addr_fields, 'ES').render
18
+ end
19
+
20
+ test "renders address in Japanese format" do
21
+ assert_equal unindent(jp_addr), HCardPresenter.new(addr_fields, 'JP').render
22
+ end
23
+
24
+ test "doesn't clobber address formats" do
25
+ gb_format_before = HCardPresenter.address_formats['gb'].dup
26
+ HCardPresenter.new(addr_fields, 'GB').render
27
+
28
+ assert_equal unindent(gb_format_before), HCardPresenter.address_formats['gb']
29
+ end
30
+
31
+ test "blank properties do not render extra line breaks" do
32
+ fields_without_region = addr_fields
33
+ fields_without_region.delete('region')
34
+
35
+ assert_equal unindent(addr_without_region), HCardPresenter.new(fields_without_region, 'GB').render
36
+ end
37
+
38
+ test "doesn't render a property when it's a blank string" do
39
+ fields = addr_fields
40
+
41
+ fields['region'] = ''
42
+ assert_equal unindent(addr_without_region), HCardPresenter.new(fields, 'GB').render
43
+
44
+ fields['region'] = ' '
45
+ assert_equal unindent(addr_without_region), HCardPresenter.new(fields, 'GB').render
46
+ end
47
+
48
+ test 'uses html escaping on property values' do
49
+ fields = addr_fields
50
+
51
+ fields['region'] = 'UK & Channel Islands'
52
+ assert_includes HCardPresenter.new(fields, 'GB').render, "UK &amp; Channel Islands"
53
+ end
54
+
55
+ test "it defaults to UK format" do
56
+ assert_equal unindent(gb_addr), HCardPresenter.new(addr_fields, 'FUBAR').render
57
+ end
58
+
59
+ test "it builds from a Contact" do
60
+ contact = OpenStruct.new(recipient: 'Recipient',
61
+ street_address: 'Street',
62
+ locality: 'Locality',
63
+ region: 'Region',
64
+ postal_code: 'Postcode',
65
+ country_name: 'Country',
66
+ country_code: 'ES')
67
+ hcard = HCardPresenter.from_contact(contact)
68
+
69
+ assert_equal unindent(es_addr), hcard.render
70
+ end
71
+
72
+ test "it leaves out the country name when building a GB contact" do
73
+ contact = OpenStruct.new(recipient: 'Recipient',
74
+ street_address: 'Street',
75
+ locality: 'Locality',
76
+ region: 'Region',
77
+ postal_code: 'Postcode',
78
+ country_name: 'Country',
79
+ country_code: 'GB')
80
+ hcard = HCardPresenter.from_contact(contact)
81
+
82
+ assert_equal unindent(addr_without_country), hcard.render
83
+ end
84
+
85
+ def addr_fields
86
+ { 'fn' => 'Recipient',
87
+ 'street-address' => 'Street',
88
+ 'postal-code' => 'Postcode',
89
+ 'locality' => 'Locality',
90
+ 'region' => 'Region',
91
+ 'country-name' => 'Country'
92
+ }
93
+ end
94
+
95
+ def gb_addr
96
+ <<-EOF
97
+ <p class="adr">
98
+ <span class="fn">Recipient</span><br />
99
+ <span class="street-address">Street</span><br />
100
+ <span class="locality">Locality</span><br />
101
+ <span class="region">Region</span><br />
102
+ <span class="postal-code">Postcode</span><br />
103
+ <span class="country-name">Country</span>
104
+ </p>
105
+ EOF
106
+ end
107
+
108
+ def es_addr
109
+ <<-EOF
110
+ <p class="adr">
111
+ <span class="fn">Recipient</span><br />
112
+ <span class="street-address">Street</span><br />
113
+ <span class="postal-code">Postcode</span> <span class="locality">Locality</span> <span class="region">Region</span><br />
114
+ <span class="country-name">Country</span>
115
+ </p>
116
+ EOF
117
+ end
118
+
119
+ def jp_addr
120
+ <<-EOF
121
+ <p class="adr">
122
+ 〒<span class="postal-code">Postcode</span><br />
123
+ <span class="region">Region</span><span class="locality">Locality</span><span class="street-address">Street</span><br />
124
+ <span class="fn">Recipient</span><br />
125
+ <span class="country-name">Country</span>
126
+ </p>
127
+ EOF
128
+ end
129
+
130
+ def addr_without_region
131
+ <<-EOF
132
+ <p class="adr">
133
+ <span class="fn">Recipient</span><br />
134
+ <span class="street-address">Street</span><br />
135
+ <span class="locality">Locality</span><br />
136
+ <span class="postal-code">Postcode</span><br />
137
+ <span class="country-name">Country</span>
138
+ </p>
139
+ EOF
140
+ end
141
+
142
+ def addr_without_country
143
+ <<-EOF
144
+ <p class="adr">
145
+ <span class="fn">Recipient</span><br />
146
+ <span class="street-address">Street</span><br />
147
+ <span class="locality">Locality</span><br />
148
+ <span class="region">Region</span><br />
149
+ <span class="postal-code">Postcode</span>
150
+ </p>
151
+ EOF
152
+ end
153
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govspeak
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Griffiths
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-09 00:00:00.000000000 Z
12
+ date: 2016-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: kramdown
@@ -71,16 +71,64 @@ dependencies:
71
71
  name: addressable
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 2.3.8
77
+ - - "<"
78
+ - !ruby/object:Gem::Version
79
+ version: '3'
77
80
  type: :runtime
78
81
  prerelease: false
79
82
  version_requirements: !ruby/object:Gem::Requirement
80
83
  requirements:
81
- - - "~>"
84
+ - - ">="
82
85
  - !ruby/object:Gem::Version
83
86
  version: 2.3.8
87
+ - - "<"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ - !ruby/object:Gem::Dependency
91
+ name: actionview
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.1'
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.1'
104
+ - !ruby/object:Gem::Dependency
105
+ name: i18n
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ type: :runtime
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.7'
118
+ - !ruby/object:Gem::Dependency
119
+ name: money
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '6.7'
125
+ type: :runtime
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '6.7'
84
132
  - !ruby/object:Gem::Dependency
85
133
  name: rake
86
134
  requirement: !ruby/object:Gem::Requirement
@@ -166,19 +214,29 @@ files:
166
214
  - README.md
167
215
  - Rakefile
168
216
  - lib/govspeak.rb
217
+ - lib/govspeak/blockquote_extra_quote_remover.rb
218
+ - lib/govspeak/extension/attachment.html.erb
219
+ - lib/govspeak/extension/inline_attachment.html.erb
169
220
  - lib/govspeak/header_extractor.rb
170
221
  - lib/govspeak/html_sanitizer.rb
171
222
  - lib/govspeak/html_validator.rb
172
223
  - lib/govspeak/kramdown_overrides.rb
224
+ - lib/govspeak/post_processor.rb
173
225
  - lib/govspeak/structured_header_extractor.rb
174
226
  - lib/govspeak/version.rb
175
227
  - lib/kramdown/parser/kramdown_with_automatic_external_links.rb
228
+ - lib/presenters/attachment_presenter.rb
229
+ - lib/presenters/h_card_presenter.rb
230
+ - lib/templates/contact.html.erb
176
231
  - lib/with_deep_merge.rb
232
+ - test/blockquote_extra_quote_remover_test.rb
233
+ - test/govspeak_contacts_test.rb
177
234
  - test/govspeak_structured_headers_test.rb
178
235
  - test/govspeak_test.rb
179
236
  - test/govspeak_test_helper.rb
180
237
  - test/html_sanitizer_test.rb
181
238
  - test/html_validator_test.rb
239
+ - test/presenters/h_card_presenter_test.rb
182
240
  - test/test_helper.rb
183
241
  - test/with_deep_merge_test.rb
184
242
  homepage: http://github.com/alphagov/govspeak
@@ -200,14 +258,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
258
  version: '0'
201
259
  requirements: []
202
260
  rubyforge_project:
203
- rubygems_version: 2.2.5
261
+ rubygems_version: 2.5.1
204
262
  signing_key:
205
263
  specification_version: 4
206
264
  summary: Markup language for single domain
207
265
  test_files:
266
+ - test/govspeak_contacts_test.rb
208
267
  - test/govspeak_test_helper.rb
268
+ - test/blockquote_extra_quote_remover_test.rb
209
269
  - test/govspeak_test.rb
210
270
  - test/test_helper.rb
271
+ - test/presenters/h_card_presenter_test.rb
211
272
  - test/with_deep_merge_test.rb
212
273
  - test/html_sanitizer_test.rb
213
274
  - test/html_validator_test.rb