usps_flags 0.3.26 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +87 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +2 -2
- data/Rakefile +4 -2
- data/lib/rational.rb +3 -1
- data/lib/usps_flags.rb +15 -17
- data/lib/usps_flags/config.rb +32 -29
- data/lib/usps_flags/core.rb +11 -9
- data/lib/usps_flags/core/ensign.rb +20 -17
- data/lib/usps_flags/core/field.rb +33 -30
- data/lib/usps_flags/core/footer.rb +2 -0
- data/lib/usps_flags/core/headers.rb +11 -8
- data/lib/usps_flags/core/icons.rb +14 -0
- data/lib/usps_flags/core/{anchor.rb → icons/anchor.rb} +7 -5
- data/lib/usps_flags/core/{binoculars.rb → icons/binoculars.rb} +7 -5
- data/lib/usps_flags/core/{lighthouse.rb → icons/lighthouse.rb} +3 -1
- data/lib/usps_flags/core/{star.rb → icons/star.rb} +3 -1
- data/lib/usps_flags/core/{trident.rb → icons/trident.rb} +29 -25
- data/lib/usps_flags/core/{trumpet.rb → icons/trumpet.rb} +3 -1
- data/lib/usps_flags/core/pennant.rb +20 -17
- data/lib/usps_flags/core/trident_spec.rb +62 -174
- data/lib/usps_flags/core/trident_specs.rb +14 -0
- data/lib/usps_flags/core/trident_specs/base.rb +15 -0
- data/lib/usps_flags/core/trident_specs/circle.rb +51 -0
- data/lib/usps_flags/core/trident_specs/delta.rb +68 -0
- data/lib/usps_flags/core/trident_specs/header.rb +65 -0
- data/lib/usps_flags/core/trident_specs/long.rb +54 -0
- data/lib/usps_flags/core/trident_specs/short.rb +176 -0
- data/lib/usps_flags/core/tridents.rb +16 -14
- data/lib/usps_flags/core/us.rb +9 -7
- data/lib/usps_flags/core/wheel.rb +2 -0
- data/lib/usps_flags/errors.rb +16 -4
- data/lib/usps_flags/generate.rb +48 -44
- data/lib/usps_flags/generate/flag.rb +33 -30
- data/lib/usps_flags/helpers.rb +48 -63
- data/lib/usps_flags/helpers/builders.rb +39 -37
- data/lib/usps_flags/helpers/spec_arrows.rb +16 -13
- data/spec/rational_spec.rb +9 -7
- data/spec/spec_helper.rb +5 -3
- data/spec/usps_flags/config_spec.rb +15 -13
- data/spec/usps_flags/core_spec.rb +52 -51
- data/spec/usps_flags/generate_spec.rb +70 -60
- data/spec/usps_flags/helpers_spec.rb +12 -10
- data/spec/usps_flags_spec.rb +22 -20
- data/usps_flags.gemspec +4 -2
- metadata +31 -21
@@ -1,25 +1,27 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe USPSFlags::Core do
|
4
|
-
describe
|
5
|
-
[
|
6
|
+
describe 'trident_spec' do
|
7
|
+
['Field', 'Specification Heading Information', 'Short Trident', 'Delta Trident', 'Circle Trident', 'Long Trident'].each do |section|
|
6
8
|
it "should contain the #{section} section" do
|
7
9
|
expect(USPSFlags::Core.trident_spec).to include("<!-- #{section} -->")
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
12
|
-
describe
|
13
|
-
[
|
14
|
+
describe 'headers' do
|
15
|
+
['?xml ', '!DOCTYPE', 'svg ', 'metadata'].each do |tag|
|
14
16
|
it "should contain the #{tag} tag" do
|
15
17
|
expect(USPSFlags::Core.headers).to include("<#{tag}")
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
describe
|
21
|
-
it
|
22
|
-
expect(USPSFlags::Core.footer).to include(
|
22
|
+
describe 'footer' do
|
23
|
+
it 'should contain the closing tag' do
|
24
|
+
expect(USPSFlags::Core.footer).to include('</svg>')
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -30,8 +32,8 @@ describe USPSFlags::Core do
|
|
30
32
|
@blue = USPSFlags::Config::BLUE
|
31
33
|
end
|
32
34
|
|
33
|
-
describe
|
34
|
-
it
|
35
|
+
describe 'field' do
|
36
|
+
it 'should correctly generate the basic field' do
|
35
37
|
expect(USPSFlags::Core.field).to eql(
|
36
38
|
<<~SVG
|
37
39
|
<path d="M 0 0
|
@@ -39,13 +41,12 @@ describe USPSFlags::Core do
|
|
39
41
|
l 0 #{@hoist}
|
40
42
|
l -#{@fly} 0
|
41
43
|
l 0 -#{@hoist}
|
42
|
-
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
44
|
+
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
43
45
|
SVG
|
44
46
|
)
|
45
47
|
end
|
46
48
|
|
47
|
-
it
|
48
|
-
|
49
|
+
it 'should correctly generate the red field' do
|
49
50
|
expect(USPSFlags::Core.field(color: :red)).to eql(
|
50
51
|
<<~SVG
|
51
52
|
<path d="M 0 0
|
@@ -58,78 +59,78 @@ describe USPSFlags::Core do
|
|
58
59
|
)
|
59
60
|
end
|
60
61
|
|
61
|
-
it
|
62
|
+
it 'should correctly generate the swallowtail field' do
|
62
63
|
expect(USPSFlags::Core.field(style: :swallowtail)).to eql(
|
63
64
|
<<~SVG
|
64
65
|
<path d="M 2 1
|
65
|
-
l #{@fly} #{@hoist/6}
|
66
|
-
l -#{@fly/5} #{@hoist/3}
|
67
|
-
l #{@fly/5} #{@hoist/3}
|
68
|
-
l -#{@fly} #{@hoist/6} z
|
69
|
-
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
66
|
+
l #{@fly} #{@hoist / 6}
|
67
|
+
l -#{@fly / 5} #{@hoist / 3}
|
68
|
+
l #{@fly / 5} #{@hoist / 3}
|
69
|
+
l -#{@fly} #{@hoist / 6} z
|
70
|
+
" fill="#FFFFFF" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
70
71
|
SVG
|
71
72
|
)
|
72
73
|
end
|
73
74
|
|
74
|
-
it
|
75
|
+
it 'should correctly generate the blue past field' do
|
75
76
|
expect(USPSFlags::Core.field(style: :past, color: :blue)).to eql(
|
76
77
|
<<~SVG
|
77
78
|
<g transform="translate(2, 1)">
|
78
79
|
<path d="M 0 5
|
79
|
-
l #{@fly/2} #{@hoist*1/12}
|
80
|
-
l 0 #{@hoist*10/12}
|
81
|
-
l -#{@fly/2} #{@hoist*1/12}
|
80
|
+
l #{@fly / 2} #{@hoist * 1 / 12}
|
81
|
+
l 0 #{@hoist * 10 / 12}
|
82
|
+
l -#{@fly / 2} #{@hoist * 1 / 12}
|
82
83
|
" fill="#{@blue}" />
|
83
|
-
<path d="M #{@fly/2} #{@hoist*1/12}
|
84
|
-
l #{@fly/4} #{@hoist*1/24}
|
85
|
-
l 0 #{@hoist*9/12}
|
86
|
-
l -#{@fly/4} #{@hoist*1/24}
|
84
|
+
<path d="M #{@fly / 2} #{@hoist * 1 / 12}
|
85
|
+
l #{@fly / 4} #{@hoist * 1 / 24}
|
86
|
+
l 0 #{@hoist * 9 / 12}
|
87
|
+
l -#{@fly / 4} #{@hoist * 1 / 24}
|
87
88
|
" fill="#FFFFFF" />
|
88
|
-
<path d="M #{@fly*3/4} #{@hoist*3/24}
|
89
|
-
l #{@fly/4} #{@hoist*1/24}
|
90
|
-
l -#{@fly/5} #{@hoist/3}
|
91
|
-
l #{@fly/5} #{@hoist/3}
|
92
|
-
l -#{@fly/4} #{@hoist*1/24}
|
89
|
+
<path d="M #{@fly * 3 / 4} #{@hoist * 3 / 24}
|
90
|
+
l #{@fly / 4} #{@hoist * 1 / 24}
|
91
|
+
l -#{@fly / 5} #{@hoist / 3}
|
92
|
+
l #{@fly / 5} #{@hoist / 3}
|
93
|
+
l -#{@fly / 4} #{@hoist * 1 / 24}
|
93
94
|
" fill="#{@red}" />
|
94
95
|
<path d="M 0 0
|
95
|
-
l #{@fly} #{@hoist/6}
|
96
|
-
l -#{@fly/5} #{@hoist/3}
|
97
|
-
l #{@fly/5} #{@hoist/3}
|
98
|
-
l -#{@fly} #{@hoist/6} z
|
99
|
-
" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY/600}" />
|
96
|
+
l #{@fly} #{@hoist / 6}
|
97
|
+
l -#{@fly / 5} #{@hoist / 3}
|
98
|
+
l #{@fly / 5} #{@hoist / 3}
|
99
|
+
l -#{@fly} #{@hoist / 6} z
|
100
|
+
" fill="none" stroke="#000000" stroke-width="#{USPSFlags::Config::BASE_FLY / 600}" />
|
100
101
|
</g>
|
101
102
|
SVG
|
102
103
|
)
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
|
-
describe
|
107
|
-
it
|
108
|
-
expect(USPSFlags::Core.trident(:s)).to include("<path d=\"M #{@fly/2} #{@hoist/4}\n")
|
107
|
+
describe 'trident' do
|
108
|
+
it 'should correctly generate a short trident' do
|
109
|
+
expect(USPSFlags::Core.trident(:s)).to include("<path d=\"M #{@fly / 2} #{@hoist / 4}\n")
|
109
110
|
end
|
110
111
|
|
111
|
-
it
|
112
|
-
expect(USPSFlags::Core.trident(:d)).to include("<g mask=\"url(#delta-mask)\"><path d=\"M #{@fly/2} #{@hoist*3/16}\n")
|
112
|
+
it 'should correctly generate a delta trident' do
|
113
|
+
expect(USPSFlags::Core.trident(:d)).to include("<g mask=\"url(#delta-mask)\"><path d=\"M #{@fly / 2} #{@hoist * 3 / 16}\n")
|
113
114
|
end
|
114
115
|
|
115
|
-
it
|
116
|
-
expect(USPSFlags::Core.trident(:stf)).to include("<g mask=\"url(#circle-mask-for-main-spike)\"><path d=\"M #{@fly/2} #{@hoist/8}\n")
|
116
|
+
it 'should correctly generate a circle trident' do
|
117
|
+
expect(USPSFlags::Core.trident(:stf)).to include("<g mask=\"url(#circle-mask-for-main-spike)\"><path d=\"M #{@fly / 2} #{@hoist / 8}\n")
|
117
118
|
end
|
118
119
|
|
119
|
-
it
|
120
|
-
expect(USPSFlags::Core.trident(:n)).to include("<path d=\"M #{@fly/2} #{@hoist/8}\n")
|
120
|
+
it 'should correctly generate a long trident' do
|
121
|
+
expect(USPSFlags::Core.trident(:n)).to include("<path d=\"M #{@fly / 2} #{@hoist / 8}\n")
|
121
122
|
end
|
122
123
|
end
|
123
124
|
|
124
|
-
describe
|
125
|
-
it
|
126
|
-
expect(USPSFlags::Core.anchor).to include(
|
125
|
+
describe 'anchor' do
|
126
|
+
it 'should correctly generate an anchor' do
|
127
|
+
expect(USPSFlags::Core.anchor).to include('<mask id="anchor-mask">')
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
|
-
describe
|
131
|
-
it
|
132
|
-
expect(USPSFlags::Core.lighthouse).to include(
|
131
|
+
describe 'lighthouse' do
|
132
|
+
it 'should correctly generate a lighthouse' do
|
133
|
+
expect(USPSFlags::Core.lighthouse).to include('<mask id="lighthouse-mask">')
|
133
134
|
end
|
134
135
|
end
|
135
136
|
end
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe USPSFlags::Generate do
|
4
|
-
describe
|
5
|
-
it
|
6
|
-
expect(USPSFlags::Generate.svg(
|
6
|
+
describe 'general features' do
|
7
|
+
it 'should generate a flag with the correct size' do
|
8
|
+
expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include(
|
7
9
|
'width="1024" height="682" viewBox="0 0 3072 2048"'
|
8
10
|
)
|
9
11
|
end
|
10
12
|
|
11
|
-
it
|
12
|
-
expect(USPSFlags::Generate.svg(
|
13
|
+
it 'should generate a flag with the correct field' do
|
14
|
+
expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include(
|
13
15
|
<<~SVG
|
14
16
|
<path d="M 0 0
|
15
17
|
l 3072 0
|
@@ -21,102 +23,110 @@ describe USPSFlags::Generate do
|
|
21
23
|
)
|
22
24
|
end
|
23
25
|
|
24
|
-
it
|
25
|
-
expect(USPSFlags::Generate.svg(
|
26
|
+
it 'should generate a flag with the correct starting position' do
|
27
|
+
expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include('<path d="M 1536 512')
|
26
28
|
end
|
27
29
|
|
28
|
-
it
|
29
|
-
expect(USPSFlags::Generate.svg(
|
30
|
-
expect(USPSFlags::Generate.svg(
|
30
|
+
it 'should generate a flag with the correct trident transformations' do
|
31
|
+
expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include('<g transform="translate(-512)">')
|
32
|
+
expect(USPSFlags::Generate.svg('LtC', outfile: '')).to include('<g transform="translate(512)">')
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
describe
|
36
|
+
describe 'officer flags' do
|
35
37
|
[
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
'PLTC', 'PC', 'PDLTC', 'PDC', 'PSTFC', 'PRC', 'PVC', 'PCC',
|
39
|
+
'PORTCAP', 'FLEETCAP', 'FLT', 'DAIDE', 'DFLT', 'NAIDE', 'NFLT',
|
40
|
+
'LT', '1LT', 'LTC', 'CDR', 'DLT', 'D1LT', 'DLTC', 'DC', 'STFC', 'RC', 'VC', 'CC'
|
39
41
|
].each do |flag|
|
40
42
|
it "should generate #{flag}" do
|
41
|
-
expect(USPSFlags::Generate.svg(flag, outfile:
|
43
|
+
expect(USPSFlags::Generate.svg(flag, outfile: '')).to include("<title>#{flag}</title>")
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
|
-
describe
|
47
|
-
it
|
48
|
-
expect(USPSFlags::Generate.svg(
|
48
|
+
describe 'pennants' do
|
49
|
+
it 'should generate the cruise pennant' do
|
50
|
+
expect(USPSFlags::Generate.svg('Cruise', outfile: '')).to include('<title>Cruise Pennant</title>')
|
49
51
|
end
|
50
52
|
|
51
|
-
it
|
52
|
-
expect(USPSFlags::Generate.svg(
|
53
|
+
it 'should generate the officer-in-charge pennant' do
|
54
|
+
expect(USPSFlags::Generate.svg('OIC', outfile: '')).to include('<title>Officer-in-Charge Pennant</title>')
|
53
55
|
end
|
54
56
|
end
|
55
57
|
|
56
|
-
describe
|
57
|
-
it
|
58
|
-
expect(USPSFlags::Generate.svg(
|
58
|
+
describe 'other flags' do
|
59
|
+
it 'should generate US' do
|
60
|
+
expect(USPSFlags::Generate.svg('US', outfile: '')).to include('<title>US Ensign</title>')
|
59
61
|
end
|
60
62
|
|
61
|
-
it
|
62
|
-
expect(USPSFlags::Generate.svg(
|
63
|
+
it 'should generate USPS Ensign' do
|
64
|
+
expect(USPSFlags::Generate.svg('Ensign', outfile: '')).to include('<title>USPS Ensign</title>')
|
63
65
|
end
|
64
66
|
|
65
|
-
it
|
66
|
-
expect(USPSFlags::Generate.svg(
|
67
|
+
it 'should generate the USPS Wheel logo' do
|
68
|
+
expect(USPSFlags::Generate.svg('Wheel', outfile: '')).to include('<title>USPS Ensign Wheel</title>')
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
70
|
-
describe
|
71
|
-
it
|
72
|
-
expect(USPSFlags::Generate.spec(outfile:
|
72
|
+
describe 'trident specifications' do
|
73
|
+
it 'should generate the trident specification sheet' do
|
74
|
+
expect(USPSFlags::Generate.spec(outfile: '')).to include('<title>USPS Trident Specifications</title>')
|
73
75
|
end
|
74
76
|
|
75
|
-
it
|
76
|
-
expect(USPSFlags::Generate.spec(outfile:
|
77
|
+
it 'should generate the trident specification sheet with a scaled border' do
|
78
|
+
expect(USPSFlags::Generate.spec(outfile: '', scaled_border: true)).to include('<title>USPS Trident Specifications</title>')
|
77
79
|
end
|
78
80
|
|
79
|
-
it
|
80
|
-
expect(USPSFlags::Generate.spec(outfile:
|
81
|
+
it 'should generate the trident specification sheet with a fractional field size' do
|
82
|
+
expect(USPSFlags::Generate.spec(outfile: '', fly: 23.5)).to include('<title>USPS Trident Specifications</title>')
|
81
83
|
end
|
82
84
|
end
|
83
85
|
|
84
|
-
describe
|
86
|
+
describe 'png' do
|
85
87
|
before(:each) do
|
86
|
-
@svg = USPSFlags::Generate.svg(
|
88
|
+
@svg = USPSFlags::Generate.svg('LtC', outfile: '')
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should raise PNGGenerationError without an outfile' do
|
92
|
+
expect { USPSFlags::Generate.png(@svg, outfile: '') }.to raise_error(USPSFlags::Errors::PNGGenerationError)
|
87
93
|
end
|
88
94
|
|
89
|
-
it
|
90
|
-
|
95
|
+
it 'should contain the SVG when raising PNGGenerationError without an outfile' do
|
96
|
+
begin
|
97
|
+
USPSFlags::Generate.png(@svg, outfile: '')
|
98
|
+
rescue => e
|
99
|
+
expect(e.svg).to eql(@svg)
|
100
|
+
end
|
91
101
|
end
|
92
102
|
|
93
|
-
it
|
94
|
-
expect { USPSFlags::Generate.png(@svg, outfile:
|
103
|
+
it 'should not raise PNGGenerationError when correctly configured' do
|
104
|
+
expect { USPSFlags::Generate.png(@svg, outfile: 'lib/output/PNG/LTC.png') }.to_not raise_error(USPSFlags::Errors::PNGGenerationError)
|
95
105
|
end
|
96
106
|
end
|
97
107
|
|
98
|
-
describe
|
99
|
-
it
|
100
|
-
expect(STDOUT).to receive(:puts).with(USPSFlags::Generate.svg(
|
101
|
-
USPSFlags::Generate.svg(
|
108
|
+
describe 'without an outfile set' do
|
109
|
+
it 'should print SVG data to the console' do
|
110
|
+
expect(STDOUT).to receive(:puts).with(USPSFlags::Generate.svg('Lt', outfile: ''), "\n")
|
111
|
+
USPSFlags::Generate.svg('Lt')
|
102
112
|
end
|
103
113
|
end
|
104
114
|
|
105
|
-
describe
|
106
|
-
it
|
115
|
+
describe 'static files errors' do
|
116
|
+
it 'should raise USPSFlags::Errors::StaticFilesGenerationError when not given any true arguments' do
|
107
117
|
expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: false) }.to raise_error(
|
108
|
-
USPSFlags::Errors::StaticFilesGenerationError,
|
118
|
+
USPSFlags::Errors::StaticFilesGenerationError, 'At least one argument switch must be true out of [svg, png, zips, reset].'
|
109
119
|
)
|
110
120
|
end
|
111
121
|
|
112
|
-
it
|
122
|
+
it 'should raise USPSFlags::Errors::ZipGenerationError when not given any true arguments' do
|
113
123
|
expect { USPSFlags::Generate.zips(svg: false, png: false) }.to raise_error(
|
114
|
-
USPSFlags::Errors::ZipGenerationError,
|
124
|
+
USPSFlags::Errors::ZipGenerationError, 'At least one argument switch must be true out of [svg, png].'
|
115
125
|
)
|
116
126
|
end
|
117
127
|
end
|
118
128
|
|
119
|
-
describe
|
129
|
+
describe 'static files generation', slow: true do
|
120
130
|
before(:all) do
|
121
131
|
svg_dir = "#{USPSFlags.configuration.flags_dir}/SVG"
|
122
132
|
png_dir = "#{USPSFlags.configuration.flags_dir}/PNG"
|
@@ -130,22 +140,22 @@ describe USPSFlags::Generate do
|
|
130
140
|
|
131
141
|
USPSFlags::Generate.svg(@svg_flag, outfile: "#{svg_dir}/#{@svg_flag}.svg")
|
132
142
|
USPSFlags::Generate.svg(@svg_ins_flag, field: false, outfile: "#{svg_dir}/insignia/#{@svg_ins_flag}.svg")
|
133
|
-
USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_flag, outfile:
|
134
|
-
USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_ins_flag, field: false, outfile:
|
135
|
-
USPSFlags::Generate.png(USPSFlags::Generate.svg(@thb_flag, field: false, outfile:
|
136
|
-
USPSFlags::Helpers.resize_png("#{png_dir}/insignia/#{@thb_flag}.png", file: "insignia/#{@thb_flag}", size: 150, size_key:
|
143
|
+
USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_flag, outfile: ''), outfile: "#{png_dir}/#{@png_flag}.png")
|
144
|
+
USPSFlags::Generate.png(USPSFlags::Generate.svg(@png_ins_flag, field: false, outfile: ''), trim: true, outfile: "#{png_dir}/insignia/#{@png_ins_flag}.png")
|
145
|
+
USPSFlags::Generate.png(USPSFlags::Generate.svg(@thb_flag, field: false, outfile: ''), trim: true, outfile: "#{png_dir}/insignia/#{@thb_flag}.png")
|
146
|
+
USPSFlags::Helpers.resize_png("#{png_dir}/insignia/#{@thb_flag}.png", file: "insignia/#{@thb_flag}", size: 150, size_key: 'thumb')
|
137
147
|
end
|
138
148
|
|
139
|
-
it
|
149
|
+
it 'should not raise an error while generating all static files' do
|
140
150
|
expect { USPSFlags::Generate.all(reset: false) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError)
|
141
151
|
end
|
142
152
|
|
143
|
-
describe
|
153
|
+
describe 'generation logs' do
|
144
154
|
before(:each) do
|
145
155
|
@log_contents = ::File.read("#{USPSFlags.configuration.log_path}/flag.log")
|
146
156
|
end
|
147
157
|
|
148
|
-
it
|
158
|
+
it 'should have generated the correct log output' do
|
149
159
|
correct_log_pattern = <<~LOG
|
150
160
|
Flag | SVG | PNG | Run time
|
151
161
|
---------------------------------------
|
@@ -197,7 +207,7 @@ describe USPSFlags::Generate do
|
|
197
207
|
expect(@log_contents).to match(correct_log_regexp)
|
198
208
|
end
|
199
209
|
|
200
|
-
it
|
210
|
+
it 'should not match an incorrect log output' do
|
201
211
|
incorrect_log_pattern = 'PLTC \| -- \| ---------- \| .*{3,6} s'
|
202
212
|
|
203
213
|
incorrect_log_regexp = Regexp.new(incorrect_log_pattern)
|
@@ -206,11 +216,11 @@ describe USPSFlags::Generate do
|
|
206
216
|
end
|
207
217
|
end
|
208
218
|
|
209
|
-
it
|
219
|
+
it 'should not raise an error while clearing all static files' do
|
210
220
|
expect { USPSFlags::Generate.all(svg: false, png: false, zips: false, reset: true) }.to_not raise_error # (USPSFlags::Errors::StaticFilesGenerationError)
|
211
221
|
end
|
212
222
|
|
213
|
-
it
|
223
|
+
it 'should not raise an error while generating zip files' do
|
214
224
|
expect { USPSFlags::Generate.zips }.to_not raise_error # (USPSFlags::Errors::ZipGenerationError)
|
215
225
|
end
|
216
226
|
end
|
@@ -1,30 +1,32 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe USPSFlags::Helpers do
|
4
|
-
describe
|
5
|
-
it
|
6
|
+
describe 'valid_flags' do
|
7
|
+
it 'should return an Array' do
|
6
8
|
expect(USPSFlags::Helpers.valid_flags).to be_an(Array)
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
11
|
+
it 'should return all officer flags but nothing else when given type :officer' do
|
10
12
|
expect(USPSFlags::Helpers.valid_flags(:officer).sort).to eql(%w[
|
11
13
|
PLTC PC PORTCAP FLEETCAP LT FLT 1LT LTC CDR PDLTC PDC DLT DAIDE
|
12
14
|
DFLT D1LT DLTC DC PSTFC PRC PVC PCC NAIDE NFLT STFC RC VC CC
|
13
15
|
].sort)
|
14
16
|
end
|
15
17
|
|
16
|
-
it
|
17
|
-
expect(USPSFlags::Helpers::Builders.grid).to include("<circle cx=\"0\" cy=\"0\" r=\"#{USPSFlags::Config::BASE_FLY/60}\" fill=\"#000000\" fill-opacity=\"0.4\" />")
|
18
|
+
it 'should correctly generate the grid helper' do
|
19
|
+
expect(USPSFlags::Helpers::Builders.grid).to include("<circle cx=\"0\" cy=\"0\" r=\"#{USPSFlags::Config::BASE_FLY / 60}\" fill=\"#000000\" fill-opacity=\"0.4\" />")
|
18
20
|
end
|
19
21
|
|
20
|
-
it
|
21
|
-
expect(USPSFlags::Helpers::Builders.locator).to include("<rect x=\"0\" y=\"0\" width=\"#{USPSFlags::Config::BASE_FLY/30}\" height=\"#{USPSFlags::Config::BASE_FLY/30}\" fill=\"#333333\" fill-opacity=\"0.6\" />")
|
22
|
+
it 'should correctly generate the locator helper' do
|
23
|
+
expect(USPSFlags::Helpers::Builders.locator).to include("<rect x=\"0\" y=\"0\" width=\"#{USPSFlags::Config::BASE_FLY / 30}\" height=\"#{USPSFlags::Config::BASE_FLY / 30}\" fill=\"#333333\" fill-opacity=\"0.6\" />")
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
|
-
describe
|
26
|
-
it
|
27
|
-
expect { USPSFlags::Helpers.resize_png(
|
27
|
+
describe 'resize_png' do
|
28
|
+
it 'should raise USPSFlags::Errors::PNGConversionError with invalid parameters' do
|
29
|
+
expect { USPSFlags::Helpers.resize_png('path/to/image.png', size: 100, size_key: 'thumb') }.to raise_error(USPSFlags::Errors::PNGConversionError)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|