gravaty 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +835 -0
- data/COPYING.md +675 -0
- data/Gemfile +21 -0
- data/ISSUES.md +62 -0
- data/README.md +287 -0
- data/Rakefile +52 -0
- data/acknowledgements.md +66 -0
- data/authors.md +63 -0
- data/copyright.md +468 -0
- data/examples/avatar.rb +159 -0
- data/examples/basics.rb +75 -0
- data/examples/cacert.pem +3401 -0
- data/examples/profile.rb +187 -0
- data/examples/xmlrpc.rb +41 -0
- data/gravaty.gemspec +78 -0
- data/gravaty.odp +0 -0
- data/gravaty.pdf +0 -0
- data/html/CHANGELOG.html +1117 -0
- data/html/COPYING_md.html +393 -0
- data/html/Gemfile.html +108 -0
- data/html/Gravaty/Gravaty.html +1002 -0
- data/html/Gravaty/ParsableDuckType.html +162 -0
- data/html/Gravaty/Parser.html +239 -0
- data/html/Gravaty/Parsers/Avatar.html +169 -0
- data/html/Gravaty/Parsers/Callback.html +170 -0
- data/html/Gravaty/Parsers/Default.html +178 -0
- data/html/Gravaty/Parsers/Force.html +170 -0
- data/html/Gravaty/Parsers/Format.html +181 -0
- data/html/Gravaty/Parsers/Pixelsize.html +181 -0
- data/html/Gravaty/Parsers/Rating.html +181 -0
- data/html/Gravaty/Parsers/Secure.html +169 -0
- data/html/Gravaty/Parsers/Type.html +181 -0
- data/html/Gravaty/Parsers.html +96 -0
- data/html/Gravaty/Utils/Downloader/Downloader.html +227 -0
- data/html/Gravaty/Utils/Downloader.html +108 -0
- data/html/Gravaty/Utils/Raisers.html +203 -0
- data/html/Gravaty/Utils/Rfc5322.html +139 -0
- data/html/Gravaty/Utils/RpcConnector/RpcConnector.html +248 -0
- data/html/Gravaty/Utils/RpcConnector.html +111 -0
- data/html/Gravaty/Utils.html +111 -0
- data/html/Gravaty.html +320 -0
- data/html/ISSUES_md.html +165 -0
- data/html/Object.html +187 -0
- data/html/README_md.html +276 -0
- data/html/Rakefile.html +141 -0
- data/html/acknowledgements_md.html +160 -0
- data/html/authors_md.html +173 -0
- data/html/copyright_md.html +481 -0
- data/html/created.rid +59 -0
- data/html/css/fonts.css +167 -0
- data/html/css/rdoc.css +590 -0
- data/html/examples/cacert_pem.html +1056 -0
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/gravaty_gemspec.html +169 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +308 -0
- data/html/js/darkfish.js +161 -0
- data/html/js/jquery.js +4 -0
- data/html/js/navigation.js +141 -0
- data/html/js/navigation.js.gz +0 -0
- data/html/js/search.js +109 -0
- data/html/js/search_index.js +1 -0
- data/html/js/search_index.js.gz +0 -0
- data/html/js/searcher.js +229 -0
- data/html/js/searcher.js.gz +0 -0
- data/html/table_of_contents.html +995 -0
- data/lib/gravaty/application.rb +354 -0
- data/lib/gravaty/constants.rb +65 -0
- data/lib/gravaty/locales/en.yml +38 -0
- data/lib/gravaty/locales/it.yml +38 -0
- data/lib/gravaty/locales/ja.yml +39 -0
- data/lib/gravaty/parser.rb +50 -0
- data/lib/gravaty/parsers/avatar.rb +40 -0
- data/lib/gravaty/parsers/callback.rb +41 -0
- data/lib/gravaty/parsers/default.rb +92 -0
- data/lib/gravaty/parsers/force.rb +40 -0
- data/lib/gravaty/parsers/format.rb +45 -0
- data/lib/gravaty/parsers/pixelsize.rb +45 -0
- data/lib/gravaty/parsers/rating.rb +45 -0
- data/lib/gravaty/parsers/secure.rb +39 -0
- data/lib/gravaty/parsers/type.rb +45 -0
- data/lib/gravaty/utils/downloader.rb +156 -0
- data/lib/gravaty/utils/raisers.rb +63 -0
- data/lib/gravaty/utils/rfc5322.rb +110 -0
- data/lib/gravaty/utils/rpc_connector.rb +86 -0
- data/lib/gravaty/version.rb +24 -0
- data/lib/gravaty.rb +75 -0
- data/test/gravaty/locales/test_locales.rb +69 -0
- data/test/gravaty/parsers/test_avatar.rb +39 -0
- data/test/gravaty/parsers/test_callback.rb +42 -0
- data/test/gravaty/parsers/test_default.rb +79 -0
- data/test/gravaty/parsers/test_force.rb +39 -0
- data/test/gravaty/parsers/test_format.rb +54 -0
- data/test/gravaty/parsers/test_pixelsize.rb +56 -0
- data/test/gravaty/parsers/test_rating.rb +54 -0
- data/test/gravaty/parsers/test_secure.rb +39 -0
- data/test/gravaty/parsers/test_type.rb +44 -0
- data/test/gravaty/test_application.rb +126 -0
- data/test/gravaty/test_avatar.rb +122 -0
- data/test/gravaty/test_parser.rb +59 -0
- data/test/gravaty/test_profile.rb +70 -0
- data/test/gravaty/utils/test_downloader.rb +51 -0
- data/test/gravaty/utils/test_raisers.rb +62 -0
- data/test/gravaty/utils/test_rfc5322.rb +82 -0
- data/test/gravaty/utils/test_rpc_connector.rb +82 -0
- data/test/test_gravaty.rb +48 -0
- data/test/test_helper.rb +105 -0
- metadata +348 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Gravaty do
|
24
|
+
describe 'when using a parser' do
|
25
|
+
include Gravaty::ParsableDuckType
|
26
|
+
|
27
|
+
before do
|
28
|
+
I18n.load_path = Dir[File.join(
|
29
|
+
File.dirname(__FILE__),
|
30
|
+
'/../../../lib/gravaty/locales/',
|
31
|
+
'*.yml')]
|
32
|
+
end
|
33
|
+
|
34
|
+
subject {Gravaty::Parsers::Type.new}
|
35
|
+
|
36
|
+
Gravaty::AVATAR_FORMATS.each do |value|
|
37
|
+
[[nil, ''], %W(#{value} .#{value.downcase})].each do |pair|
|
38
|
+
it "shall return '#{pair[1]}' when parameter is '#{pair[0]}'" do
|
39
|
+
subject.parse(pair[0]).must_equal pair[1]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Gravaty do
|
24
|
+
describe 'when created with a valid email address' do
|
25
|
+
|
26
|
+
subject {Gravaty::Gravaty.new(Gravaty::TEST_MY_ADDRESS,
|
27
|
+
Gravaty::parser)}
|
28
|
+
|
29
|
+
it 'shall return the email content on demand' do
|
30
|
+
subject.email.must_equal Gravaty::TEST_MY_ADDRESS.downcase
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'shall return the digest content on demand' do
|
34
|
+
subject.digest.must_equal Gravaty::TEST_MY_MD5
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'shall return a valid string' do
|
38
|
+
subject.to_s.wont_be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'shall return a valid JSON' do
|
42
|
+
subject.to_json.wont_be_nil
|
43
|
+
JSON.parse(subject.to_json).wont_be_nil
|
44
|
+
end
|
45
|
+
|
46
|
+
[:avatar, :profile].each do |method|
|
47
|
+
describe "when asked for '#{method}'" do
|
48
|
+
describe 'when no parameters are provided' do
|
49
|
+
it 'shall provide an URI' do
|
50
|
+
subject.send(method)
|
51
|
+
.must_match Gravaty::TEST_SIMPLE_URI_REGEXP
|
52
|
+
end
|
53
|
+
|
54
|
+
it "shall provide a '#{method}' URI" do
|
55
|
+
subject.send(method)
|
56
|
+
.must_include Gravaty::TEST_STRING[method]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "shall provide a '#{method}' with a secure URI" do
|
60
|
+
subject.send(method)
|
61
|
+
.must_match Gravaty::TEST_SECURE_URI_REGEXP
|
62
|
+
subject.send(method)
|
63
|
+
.wont_match Gravaty::TEST_UNSECURE_URI_REGEXP
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'when nil is provided' do
|
68
|
+
it 'shall provide an URI' do
|
69
|
+
subject.send(method, nil)
|
70
|
+
.must_match Gravaty::TEST_SIMPLE_URI_REGEXP
|
71
|
+
end
|
72
|
+
|
73
|
+
it "shall provide a '#{method}' URI" do
|
74
|
+
subject.send(method, nil)
|
75
|
+
.must_include Gravaty::TEST_STRING[method]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "shall provide a '#{method}' with a secure URI" do
|
79
|
+
subject.send(method, nil)
|
80
|
+
.must_match Gravaty::TEST_SECURE_URI_REGEXP
|
81
|
+
subject.send(method, nil)
|
82
|
+
.wont_match Gravaty::TEST_UNSECURE_URI_REGEXP
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'when secure:false is provided' do
|
88
|
+
it "shall provide a '#{method}' with an unsecure URI" do
|
89
|
+
subject.send(method, secure: false)
|
90
|
+
.wont_match Gravaty::TEST_SECURE_URI_REGEXP
|
91
|
+
subject.send(method, secure: false)
|
92
|
+
.must_match Gravaty::TEST_UNSECURE_URI_REGEXP
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'shall provide the XML-RPC API interface' do
|
99
|
+
subject.must_respond_to :xmlrpc
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'when asked for nil method' do
|
103
|
+
it 'must raise an ArgumentError' do
|
104
|
+
assert_raises ArgumentError do
|
105
|
+
subject.xmlrpc(nil)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe 'when asked for an unsupported method' do
|
111
|
+
it 'must raise an ArgumentError' do
|
112
|
+
assert_raises ArgumentError do
|
113
|
+
subject.xmlrpc('my_method', 'my_password')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'when asked for a valid method with a nil password' do
|
119
|
+
it 'must raise an ArgumentError' do
|
120
|
+
assert_raises ArgumentError do
|
121
|
+
subject.xmlrpc('my_method')
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Gravaty do
|
24
|
+
describe 'when created with a valid email address ' do
|
25
|
+
|
26
|
+
subject {Gravaty::Gravaty.new(Gravaty::TEST_MY_ADDRESS,
|
27
|
+
Gravaty::parser)}
|
28
|
+
|
29
|
+
Gravaty::AVATAR_FORMATS.each do |avatar|
|
30
|
+
describe "when asked for '#{avatar}' image" do
|
31
|
+
it "shall provide an URI with specified '#{avatar}' image" do
|
32
|
+
subject.avatar(type: avatar).must_include(".#{avatar}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'when asked for unknown image' do
|
38
|
+
it 'must raise an ArgumentError' do
|
39
|
+
assert_raises ArgumentError do
|
40
|
+
subject.avatar type: 'unknown'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Gravaty::ALLOWED_SIZES.each do |size|
|
46
|
+
describe "when asked for a size of '#{size}' pixels" do
|
47
|
+
it "shall provide an URI with specified '#{size}' image" do
|
48
|
+
subject.avatar(pixelsize: size)
|
49
|
+
.must_match(/#{Gravaty::TEST_SIZE_REGEXP}$/)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
[-1, 0, Gravaty::ALLOWED_SIZES.max + 1].each do |size|
|
55
|
+
describe "when asked for an invalid size of '#{size}' pixels" do
|
56
|
+
it 'must raise an argument error' do
|
57
|
+
assert_raises ArgumentError do
|
58
|
+
subject.avatar(pixelsize: size)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Gravaty::RATING_OPTIONS.each do |rating|
|
65
|
+
describe "when asked for a specific image rating '#{rating}'" do
|
66
|
+
it "shall provide an URI with specified '#{rating}'" do
|
67
|
+
subject.avatar(rating: rating)
|
68
|
+
.must_include("rating=#{rating}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'when asked for unknown rating' do
|
74
|
+
it 'must raise an ArgumentError' do
|
75
|
+
assert_raises ArgumentError do
|
76
|
+
subject.avatar rating: 'unknown'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe 'when asked for forcing default image' do
|
82
|
+
it 'shall provide a forced URI' do
|
83
|
+
subject.avatar(force: true).must_include Gravaty::TEST_FORCED
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
Gravaty::DEFAULT_OPTIONS.each do |options|
|
88
|
+
describe "when asked for a specific image options '#{options}'" do
|
89
|
+
it "shall provide an URI with option '#{options}'" do
|
90
|
+
subject.avatar(default: options).must_include("d=#{options}")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'when provided with a own default image' do
|
96
|
+
it 'shall provide a HTTP(S) URI' do
|
97
|
+
['', 's'].each do |type|
|
98
|
+
an_uri = "http#{type}://www.example.com/example.jpg"
|
99
|
+
subject.avatar(default: an_uri).must_include CGI::escape(an_uri)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'must raise an ArgumentError when URI is not HTTP(S)' do
|
104
|
+
assert_raises ArgumentError do
|
105
|
+
subject.avatar default: 'ftp://www.example.com/example.jpg'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'must raise an ArgumentError when image format is not supported' do
|
110
|
+
assert_raises ArgumentError do
|
111
|
+
subject.avatar default: 'http://www.example.com/example.svg'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'must raise an ArgumentError when URI contains a query string' do
|
116
|
+
assert_raises ArgumentError do
|
117
|
+
subject.avatar default: 'http://www.example.com?image=example.jpg'
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Gravaty do
|
24
|
+
describe 'when using a parser ' do
|
25
|
+
|
26
|
+
subject {Gravaty::parser}
|
27
|
+
|
28
|
+
it 'shall provide a list of parsers' do
|
29
|
+
subject.parsers.wont_be_empty
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'shall provide all needed parsers' do
|
33
|
+
subject.parsers.length.must_equal Gravaty::ALLOWED_PARAMS.length
|
34
|
+
subject.parsers.keys.must_equal Gravaty::ALLOWED_PARAMS
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'shall use the parsable duck type' do
|
38
|
+
parsable_mocks = {}
|
39
|
+
|
40
|
+
Gravaty::ALLOWED_PARAMS.each do |param|
|
41
|
+
parsable_mocks[param] = MiniTest::Mock.new
|
42
|
+
parsable_mocks[param].expect(:parse, false, [nil])
|
43
|
+
parsable_mocks[param].expect(:nil?, false)
|
44
|
+
end
|
45
|
+
|
46
|
+
my_parser = Gravaty::Parser.new(parsable_mocks)
|
47
|
+
|
48
|
+
Gravaty::ALLOWED_PARAMS.each do |param|
|
49
|
+
my_parser.parse(param, nil)
|
50
|
+
parsable_mocks[param].verify
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'shall die gracefully whether parameters are not valid' do
|
55
|
+
a_parser = Gravaty::Parser.new(nil)
|
56
|
+
a_parser.parse
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Gravaty do
|
24
|
+
describe 'when created with a valid email address ' do
|
25
|
+
subject {Gravaty::Gravaty.new(Gravaty::TEST_MY_ADDRESS,
|
26
|
+
Gravaty::parser)}
|
27
|
+
|
28
|
+
Gravaty::PROFILE_FORMATS.each do |format|
|
29
|
+
describe "when asked for '#{format}' profile" do
|
30
|
+
it "shall provide an URI with required '#{format}' format" do
|
31
|
+
subject.profile(format: format).must_include(".#{format}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'when asked for unknown profile format ' do
|
37
|
+
it 'must raise an ArgumentError' do
|
38
|
+
assert_raises ArgumentError do
|
39
|
+
subject.profile format: 'unknown'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'when asked for JSON format ' do
|
45
|
+
it 'shall provide an URI in JSON format' do
|
46
|
+
subject.json.must_match Gravaty::TEST_JSON_REGEXP
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'shall provide a JSON URI when callback is provided' do
|
50
|
+
subject.json.must_match Gravaty::TEST_JSON_REGEXP
|
51
|
+
subject.json(callback: Gravaty::TEST_CALLBACK)
|
52
|
+
.must_match(/#{Gravaty::TEST_CALLBACK}$/)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'when asked for QR code format ' do
|
57
|
+
it 'shall provide an URI in QR code format' do
|
58
|
+
subject.qrcode.must_match Gravaty::TEST_QR_REGEXP
|
59
|
+
end
|
60
|
+
|
61
|
+
Gravaty::ALLOWED_SIZES.each do |size|
|
62
|
+
it "shall provide a '#{size}' pixels URI, when size '#{size}'" do
|
63
|
+
subject.qrcode.must_match Gravaty::TEST_QR_REGEXP
|
64
|
+
subject.qrcode(pixelsize: size)
|
65
|
+
.must_match(/#{Gravaty::TEST_SIZE_REGEXP}$/)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Utils::Downloader do
|
24
|
+
describe 'when passed a nil uri' do
|
25
|
+
it 'must raise a RuntimeError' do
|
26
|
+
assert_raises RuntimeError do
|
27
|
+
Gravaty::Utils::Downloader::Downloader
|
28
|
+
.download_file nil, 'filename'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'when passed an invalid uri' do
|
34
|
+
it 'must raise a InvalidURIError' do
|
35
|
+
assert_raises URI::InvalidURIError do
|
36
|
+
Gravaty::Utils::Downloader::Downloader
|
37
|
+
.download_file 'http://example.com/%uABCD',
|
38
|
+
'filename'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'when passed a nil filename' do
|
44
|
+
it 'must raise a TypeError' do
|
45
|
+
assert_raises TypeError do
|
46
|
+
Gravaty::Utils::Downloader::Downloader
|
47
|
+
.download_file 'http://www.example.com', nil
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Utils::Raisers do
|
24
|
+
include Gravaty::Utils::Raisers
|
25
|
+
|
26
|
+
before do
|
27
|
+
I18n.load_path = Dir[File.join(File.dirname(__FILE__),
|
28
|
+
'/../../../lib/gravaty/locales/',
|
29
|
+
'*.yml')]
|
30
|
+
I18n.locale = 'it'
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'when running any raiser method' do
|
34
|
+
it 'do not raise an ArgumentError when value is nil or in array' do
|
35
|
+
all_methods = Hash.new
|
36
|
+
all_methods[:raiser_downcase] = [[nil, nil], ['value', ['value']]]
|
37
|
+
all_methods[:raiser_to_i] = [[nil, nil], ['42', [42]]]
|
38
|
+
|
39
|
+
all_methods.each_key do |method_name|
|
40
|
+
a_method = self.method method_name
|
41
|
+
all_methods[method_name.to_sym].each do |params|
|
42
|
+
a_method.call 'error.value', params[0], params[1]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'raises ArgumentError when value is not nil and not in array' do
|
48
|
+
all_methods = Hash.new
|
49
|
+
all_methods[:raiser_downcase] = ['value', ['no value']]
|
50
|
+
all_methods[:raiser_to_i] = ['42', [47]]
|
51
|
+
|
52
|
+
all_methods.each_key do |method_name|
|
53
|
+
a_method = self.method method_name
|
54
|
+
assert_raises ArgumentError do
|
55
|
+
a_method.call 'error.value',
|
56
|
+
all_methods[method_name.to_sym][0],
|
57
|
+
all_methods[method_name.to_sym][1]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#--
|
2
|
+
# gravaty
|
3
|
+
# Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Marco Bresciani
|
4
|
+
#
|
5
|
+
# This file is part of gravaty.
|
6
|
+
#
|
7
|
+
# gravaty is free software: you can redistribute it and/or modify it
|
8
|
+
# under the terms of the GNU General Public License as published by the
|
9
|
+
# Free Software Foundation, either version 3 of the License, or (at your
|
10
|
+
# option) any later version.
|
11
|
+
#
|
12
|
+
# gravaty is distributed in the hope that it will be useful, but WITHOUT
|
13
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
14
|
+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
15
|
+
# for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with gravaty. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
#++
|
20
|
+
|
21
|
+
require_relative '../../test_helper'
|
22
|
+
|
23
|
+
describe Gravaty::Utils::Rfc5322 do
|
24
|
+
describe 'when passed a nil email address' do
|
25
|
+
it 'must return nil' do
|
26
|
+
Gravaty::Utils::Rfc5322::EMAIL.match(nil).must_be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'when passed an invalid email address, according to RF5322' do
|
31
|
+
|
32
|
+
# This test does not pass with 'Joe Q. Public
|
33
|
+
# <john.q.public@example.com>' email: see
|
34
|
+
# <https://tools.ietf.org/html/rfc5322#appendix-A.1.2> that is: it
|
35
|
+
# matches the address even if it has no double-quotes as specified
|
36
|
+
# in RFC 5322.
|
37
|
+
#
|
38
|
+
# Note that the display names for Joe Q. Public and Giant; "Big" Box
|
39
|
+
# needed to be enclosed in double-quotes because the former contains
|
40
|
+
# the period and the latter contains both semicolon and double-quote
|
41
|
+
# characters (the double-quote characters appearing as quoted-pair
|
42
|
+
# constructs).
|
43
|
+
['-.', 'Joe Q. Public <john.q.public@example.com>']
|
44
|
+
.each do |invalid_address|
|
45
|
+
it "must return nil for '#{invalid_address}' invalid address" do
|
46
|
+
assert_nil Gravaty::Utils::Rfc5322::EMAIL.match invalid_address
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'when passed a valid email address, according to RF5322' do
|
52
|
+
|
53
|
+
# This test shall pass... see
|
54
|
+
# <https://tools.ietf.org/html/rfc5322#appendix-A.5>
|
55
|
+
#
|
56
|
+
# The above example is aesthetically displeasing, but perfectly
|
57
|
+
# legal. Note particularly (1) the comments in the "From:" field
|
58
|
+
# (including one that has a ")" character appearing as part of a
|
59
|
+
# quoted-pair); (2) the white space absent after the ":" in the
|
60
|
+
# "To:" field as well as the comment and folding white space after
|
61
|
+
# the group name, the special character (".") in the comment in
|
62
|
+
# Chris Jones's address, and the folding white space before and
|
63
|
+
# after "joe@example.org,"; (3) the multiple and nested comments in
|
64
|
+
# the "Cc:" field as well as the comment immediately following the
|
65
|
+
# ":" after "Cc"; (4) the folding white space (but no comments
|
66
|
+
# except at the end) and the missing seconds in the time of the date
|
67
|
+
# field; and (5) the white space before (but not within) the
|
68
|
+
# identifier in the "Message-ID:" field.
|
69
|
+
['John Doe <jdoe@machine.example>', 'Mary Smith <mary@example.net>',
|
70
|
+
'Mary Smith <mary@example.net>',
|
71
|
+
"A Group(Some people)\n :Chris Jones <c@(Chris's host.)public.example>,\n joe@example.org,\n John <jdoe@one.test> (my dear friend);",
|
72
|
+
'Who? <one@y.test>', '"Joe Q. Public" <john.q.public@example.com>',
|
73
|
+
'"Giant; \"Big\" Box" <sysservices@example.net>',
|
74
|
+
'A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>;',
|
75
|
+
'Pete(A nice \) chap) <pete(his account)@silly.test(his host)>']
|
76
|
+
.each do |address|
|
77
|
+
it "must match the valid '#{address}' email address" do
|
78
|
+
refute_nil Gravaty::Utils::Rfc5322::EMAIL.match address
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|