boa_vista_stubs 0.0.2 → 0.0.3
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/app/controllers/boa_vista_stubs/requests_controller.rb +3 -21
- data/app/models/boa_vista_stubs/document/cnpj.rb +4 -7
- data/app/models/boa_vista_stubs/document/cpf.rb +6 -7
- data/app/models/boa_vista_stubs/document/extension.rb +14 -0
- data/app/models/boa_vista_stubs/document/response/base.rb +14 -0
- data/app/models/boa_vista_stubs/document/response/cnpj.rb +18 -0
- data/app/models/boa_vista_stubs/document/response/cpf.rb +18 -0
- data/app/models/boa_vista_stubs/document/response.rb +8 -29
- data/app/models/boa_vista_stubs/document/validate_expression.rb +26 -0
- data/app/models/boa_vista_stubs/document.rb +12 -18
- data/app/services/boa_vista_stubs/document_service/timeout.rb +7 -0
- data/app/services/boa_vista_stubs/document_service.rb +11 -17
- data/lib/boa_vista_stubs/configuration.rb +1 -1
- data/lib/boa_vista_stubs/version.rb +1 -1
- data/spec/boa_vista_stubs_spec.rb +5 -0
- data/spec/controllers/requests_controller_spec.rb +16 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config/application.rb +28 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/boa_vista.rb +6 -0
- data/spec/dummy/config/initializers/boa_vista_stubs.rb +5 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1621 -0
- data/spec/dummy/log/test.log +112 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/layout.txt +1 -0
- data/spec/integration/navigation_test.rb +8 -0
- data/spec/lib/boa_vista_stubs/configuration_spec.rb +9 -0
- data/spec/models/boa_vista_stubs/document/cnpj_spec.rb +31 -0
- data/spec/models/boa_vista_stubs/document/cpf_spec.rb +33 -0
- data/spec/models/boa_vista_stubs/document/response/base_spec.rb +21 -0
- data/spec/models/boa_vista_stubs/document/response/cnpj_spec.rb +19 -0
- data/spec/models/boa_vista_stubs/document/response/cpf_spec.rb +19 -0
- data/spec/models/boa_vista_stubs/document/response_spec.rb +17 -0
- data/spec/models/boa_vista_stubs/document/validate_expression_spec.rb +46 -0
- data/spec/models/boa_vista_stubs/document_spec.rb +22 -0
- data/spec/rails_helper.rb +11 -0
- data/spec/services/document_service/timeout_spec.rb +7 -0
- data/spec/services/document_service_spec.rb +51 -0
- data/spec/spec_helper.rb +20 -0
- metadata +123 -6
- data/app/models/boa_vista_stubs/document/identifier.rb +0 -11
@@ -0,0 +1,112 @@
|
|
1
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
2
|
+
Parameters: {"consulta"=>"my search string"}
|
3
|
+
Rendered text template (0.0ms)
|
4
|
+
Completed 200 OK in 40.8ms (Views: 40.2ms)
|
5
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
6
|
+
Parameters: {"consulta"=>"my search string"}
|
7
|
+
Rendered text template (0.0ms)
|
8
|
+
Completed 200 OK in 6.7ms (Views: 6.4ms)
|
9
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
10
|
+
Parameters: {"consulta"=>"CSR60 01 my code my passwCADPJ 032C243075237000144 X"}
|
11
|
+
[BoaVistaStubs] - Start validating document type: CNPJ
|
12
|
+
Completed 500 Internal Server Error in 1.1ms
|
13
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
14
|
+
Parameters: {"consulta"=>"CSR60 01 my code my passwCADPJ 032C212345678901234 X"}
|
15
|
+
[BoaVistaStubs] - Start validating document type: CNPJ
|
16
|
+
Completed 500 Internal Server Error in 0.3ms
|
17
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
18
|
+
Parameters: {"consulta"=>"CSR60 01 my code my passwSINTON 012C195711895290 X"}
|
19
|
+
[BoaVistaStubs] - Start validating document type: CPF
|
20
|
+
Completed 500 Internal Server Error in 0.3ms
|
21
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
22
|
+
Parameters: {"consulta"=>"CSR60 01 my code my passwSINTON 012C100001123321 X"}
|
23
|
+
[BoaVistaStubs] - Start validating document type: CPF
|
24
|
+
Completed 500 Internal Server Error in 0.3ms
|
25
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
26
|
+
Parameters: {"consulta"=>"my search string"}
|
27
|
+
Rendered text template (0.0ms)
|
28
|
+
Completed 200 OK in 22.7ms (Views: 22.0ms)
|
29
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
30
|
+
Parameters: {"consulta"=>"my search string"}
|
31
|
+
Rendered text template (0.0ms)
|
32
|
+
Completed 200 OK in 6.2ms (Views: 5.9ms)
|
33
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
34
|
+
Parameters: {"consulta"=>"my search string"}
|
35
|
+
Rendered text template (0.0ms)
|
36
|
+
Completed 200 OK in 40.1ms (Views: 39.3ms)
|
37
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
38
|
+
Parameters: {"consulta"=>"my search string"}
|
39
|
+
Rendered text template (0.0ms)
|
40
|
+
Completed 200 OK in 51.5ms (Views: 50.7ms)
|
41
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
42
|
+
Parameters: {"consulta"=>"my search string"}
|
43
|
+
Rendered text template (0.0ms)
|
44
|
+
Completed 200 OK in 6.3ms (Views: 6.0ms)
|
45
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
46
|
+
Parameters: {"consulta"=>"my search string"}
|
47
|
+
Rendered text template (0.0ms)
|
48
|
+
Completed 200 OK in 7.5ms (Views: 7.1ms)
|
49
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
50
|
+
Parameters: {"consulta"=>"my search string"}
|
51
|
+
Rendered text template (0.0ms)
|
52
|
+
Completed 200 OK in 22.6ms (Views: 22.0ms)
|
53
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
54
|
+
Parameters: {"consulta"=>"my search string"}
|
55
|
+
Rendered text template (0.0ms)
|
56
|
+
Completed 200 OK in 8.3ms (Views: 7.7ms)
|
57
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
58
|
+
Parameters: {"consulta"=>"my search string"}
|
59
|
+
Rendered text template (0.0ms)
|
60
|
+
Completed 200 OK in 6.3ms (Views: 5.9ms)
|
61
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
62
|
+
Parameters: {"consulta"=>"my search string"}
|
63
|
+
Rendered text template (0.0ms)
|
64
|
+
Completed 200 OK in 5.9ms (Views: 5.5ms)
|
65
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
66
|
+
Parameters: {"consulta"=>"my search string"}
|
67
|
+
Rendered text template (0.0ms)
|
68
|
+
Completed 200 OK in 23.4ms (Views: 22.7ms)
|
69
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
70
|
+
Parameters: {"consulta"=>"my search string"}
|
71
|
+
Rendered text template (0.0ms)
|
72
|
+
Completed 200 OK in 24.6ms (Views: 23.7ms)
|
73
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
74
|
+
Parameters: {"consulta"=>"my search string"}
|
75
|
+
Rendered text template (0.0ms)
|
76
|
+
Completed 200 OK in 6.1ms (Views: 5.8ms)
|
77
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
78
|
+
Parameters: {"consulta"=>"my search string"}
|
79
|
+
Rendered text template (0.0ms)
|
80
|
+
Completed 200 OK in 6.3ms (Views: 6.0ms)
|
81
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
82
|
+
Parameters: {"consulta"=>"my search string"}
|
83
|
+
Rendered text template (0.0ms)
|
84
|
+
Completed 200 OK in 11.1ms (Views: 10.6ms)
|
85
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
86
|
+
Parameters: {"consulta"=>"my search string"}
|
87
|
+
Rendered text template (0.0ms)
|
88
|
+
Completed 200 OK in 6.3ms (Views: 6.0ms)
|
89
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
90
|
+
Parameters: {"consulta"=>"my search string"}
|
91
|
+
Rendered text template (0.0ms)
|
92
|
+
Completed 200 OK in 6.2ms (Views: 5.8ms)
|
93
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
94
|
+
Parameters: {"consulta"=>"my search string"}
|
95
|
+
Rendered text template (0.0ms)
|
96
|
+
Completed 200 OK in 7.6ms (Views: 7.1ms)
|
97
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
98
|
+
Parameters: {"consulta"=>"my search string"}
|
99
|
+
Rendered text template (0.0ms)
|
100
|
+
Completed 200 OK in 8.7ms (Views: 8.4ms)
|
101
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
102
|
+
Parameters: {"consulta"=>"my search string"}
|
103
|
+
Rendered text template (0.0ms)
|
104
|
+
Completed 200 OK in 6.8ms (Views: 6.3ms)
|
105
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
106
|
+
Parameters: {"consulta"=>"my search string"}
|
107
|
+
Rendered text template (0.0ms)
|
108
|
+
Completed 200 OK in 40.1ms (Views: 39.3ms)
|
109
|
+
Processing by BoaVistaStubs::RequestsController#index as HTML
|
110
|
+
Parameters: {"consulta"=>"my search string"}
|
111
|
+
Rendered text template (0.0ms)
|
112
|
+
Completed 200 OK in 22.7ms (Views: 22.1ms)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/404.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,67 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/422.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
65
|
+
</div>
|
66
|
+
</body>
|
67
|
+
</html>
|
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body>
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
this is a fake fixture for a layout.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Configuration do
|
4
|
+
context 'configures the valid parameters' do
|
5
|
+
it { expect(BoaVistaStubs.configuration.valid_cpf).to eq(/^306/) }
|
6
|
+
it { expect(BoaVistaStubs.configuration.valid_cnpj).to eq(/^4307/) }
|
7
|
+
it { expect(BoaVistaStubs.configuration.timeout_document).to eq(/^999/) }
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::Cnpj do
|
4
|
+
subject(:instance) { described_class.new(document_number) }
|
5
|
+
|
6
|
+
let(:document_number) { '43075232000115' }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it { expect(instance).to be_a_instance_of(described_class) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'returns true when the document number is included in configuration' do
|
14
|
+
document = described_class.new(document_number)
|
15
|
+
|
16
|
+
expect(document).to be_valid
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns false when the document number is not included in configuration' do
|
20
|
+
document_number = '12345678910'
|
21
|
+
|
22
|
+
document = described_class.new(document_number)
|
23
|
+
|
24
|
+
expect(document).to_not be_valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#document_type' do
|
29
|
+
it { expect(instance.document_type).to eq(:CNPJ) }
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::Cpf do
|
4
|
+
subject(:instance) { described_class.new(document_number) }
|
5
|
+
|
6
|
+
let(:document_number) { '86165232000115' }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it { expect(instance).to be_a_instance_of(described_class) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#valid?' do
|
13
|
+
it 'returns true when the document number is included in configuration' do
|
14
|
+
document_number = "30630011299 "
|
15
|
+
|
16
|
+
document = described_class.new(document_number)
|
17
|
+
|
18
|
+
expect(document).to be_valid
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns false when the document number is not included in configuration' do
|
22
|
+
document_number = '12345678910'
|
23
|
+
|
24
|
+
document = described_class.new(document_number)
|
25
|
+
|
26
|
+
expect(document).to_not be_valid
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#document_type' do
|
31
|
+
it { expect(instance.document_type).to eq(:CPF) }
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::Response::Base do
|
4
|
+
subject(:instance) { described_class.new }
|
5
|
+
|
6
|
+
describe '#read_layout' do
|
7
|
+
let(:file) { File.read('spec/fixtures/layout.txt') }
|
8
|
+
|
9
|
+
it 'returns the layout from the fixture file' do
|
10
|
+
expect(BoaVista::Fixtures).to receive(:read).with('layout_10.txt') { file }
|
11
|
+
instance.read_layout('10')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#log' do
|
16
|
+
it 'returns a formatted message' do
|
17
|
+
expect(Rails.logger).to receive(:info).with('[BoaVistaStubs] - testing log')
|
18
|
+
instance.log('testing log')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::Response::Cnpj do
|
4
|
+
subject(:instance) { described_class.new }
|
5
|
+
|
6
|
+
describe '#valid_document' do
|
7
|
+
it 'returns the content of a valid layout' do
|
8
|
+
expect(instance).to receive(:read_layout).with(described_class::LAYOUTS[:valid])
|
9
|
+
instance.valid_document
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#invalid_document' do
|
14
|
+
it 'returns the content of a invalid layout' do
|
15
|
+
expect(instance).to receive(:read_layout).with(described_class::LAYOUTS[:invalid])
|
16
|
+
instance.invalid_document
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::Response::Cpf do
|
4
|
+
subject(:instance) { described_class.new }
|
5
|
+
|
6
|
+
describe '#valid_document' do
|
7
|
+
it 'returns the content of a valid layout' do
|
8
|
+
expect(instance).to receive(:read_layout).with(described_class::LAYOUTS[:valid])
|
9
|
+
instance.valid_document
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#invalid_document' do
|
14
|
+
it 'returns the content of a invalid layout' do
|
15
|
+
expect(instance).to receive(:read_layout).with(described_class::LAYOUTS[:invalid])
|
16
|
+
instance.invalid_document
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::Response do
|
4
|
+
describe '.identify' do
|
5
|
+
it 'returns a instance of BoaVistaStubs::Document::Response::Cpf' do
|
6
|
+
document_type = :CPF
|
7
|
+
|
8
|
+
expect(described_class.identify(document_type)).to eq(BoaVistaStubs::Document::Response::Cpf)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'returns a instance of BoaVistaStubs::Document::Response::Cnpj' do
|
12
|
+
document_type = :cnpj
|
13
|
+
|
14
|
+
expect(described_class.identify(document_type)).to eq(BoaVistaStubs::Document::Response::Cnpj)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document::ValidateExpression do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'initializes with a value' do
|
6
|
+
validator = described_class.new('123456')
|
7
|
+
expect(validator).to be_a_instance_of(described_class)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#valid_cpf?' do
|
12
|
+
it 'returns true when cpf regex matches the value' do
|
13
|
+
validator = described_class.new('30630012345')
|
14
|
+
expect(validator.valid_cpf?).to be_truthy
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns false when cpf regex does not matches the value' do
|
18
|
+
validator = described_class.new('30530012345')
|
19
|
+
expect(validator.valid_cpf?).to be_falsey
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#valid_cnpj?' do
|
24
|
+
it 'returns true when cnpj regex matches the value' do
|
25
|
+
validator = described_class.new('430785784000130')
|
26
|
+
expect(validator.valid_cnpj?).to be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns false when cnpj regex does not matches the value' do
|
30
|
+
validator = described_class.new('62885784000130')
|
31
|
+
expect(validator.valid_cnpj?).to be_falsey
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#timeout?' do
|
36
|
+
it 'returns true when timeout document regex matches the value' do
|
37
|
+
validator = described_class.new('99989222222')
|
38
|
+
expect(validator.timeout_document?).to be_truthy
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns false when timeout document regex does not matches the value' do
|
42
|
+
validator = described_class.new('89123222220')
|
43
|
+
expect(validator.timeout_document?).to be_falsey
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::Document do
|
4
|
+
|
5
|
+
let(:search_params) do
|
6
|
+
'C' * 68
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.identify' do
|
10
|
+
it 'returns a instance of Document::Cpf' do
|
11
|
+
document = described_class.identify(search_params + '1')
|
12
|
+
|
13
|
+
expect(document).to be_a_instance_of(BoaVistaStubs::Document::Cpf)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns a instance of Document::Cnpj' do
|
17
|
+
document = described_class.identify(search_params + '2')
|
18
|
+
|
19
|
+
expect(document).to be_a_instance_of(BoaVistaStubs::Document::Cnpj)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
ENV['RAILS_ENV'] ||= 'test'
|
2
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
3
|
+
|
4
|
+
# Prevent database truncation if the environment is production
|
5
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
6
|
+
require 'rspec/rails'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.infer_spec_type_from_file_location!
|
10
|
+
config.filter_rails_from_backtrace!
|
11
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe BoaVistaStubs::DocumentService do
|
4
|
+
describe '#call' do
|
5
|
+
let(:document) { BoaVistaStubs::Document::Cpf.new('12345') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(BoaVistaStubs::Document).to receive(:identify).with('search params') { document }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when timeout document' do
|
12
|
+
before do
|
13
|
+
allow(document).to receive(:timeout_document?) { true }
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'raises timeout error' do
|
17
|
+
expect { BoaVistaStubs::DocumentService.call('search params') }.to raise_error(BoaVista::Errors::Timeout)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when document is valid' do
|
22
|
+
let(:response) { instance_double('response', valid_document: 'this is a valid response') }
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(document).to receive(:valid?) { true }
|
26
|
+
allow(document).to receive(:timeout_document?) { false }
|
27
|
+
|
28
|
+
allow(BoaVistaStubs::Document::Response).to receive(:identify).with(anything) { response }
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns the valid response' do
|
32
|
+
expect(BoaVistaStubs::DocumentService.call('search params')).to eq(response.valid_document)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when document is invalid' do
|
37
|
+
let(:response) { instance_double('response', invalid_document: 'this is a invalid response') }
|
38
|
+
|
39
|
+
before do
|
40
|
+
allow(document).to receive(:valid?) { false }
|
41
|
+
allow(document).to receive(:timeout_document?) { false }
|
42
|
+
|
43
|
+
allow(BoaVistaStubs::Document::Response).to receive(:identify).with(anything) { response }
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the invalid response' do
|
47
|
+
expect(BoaVistaStubs::DocumentService.call('search params')).to eq(response.invalid_document)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'boa_vista_stubs'
|
2
|
+
require 'boa_vista'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |expectations|
|
7
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
8
|
+
end
|
9
|
+
|
10
|
+
config.mock_with :rspec do |mocks|
|
11
|
+
mocks.verify_partial_doubles = true
|
12
|
+
end
|
13
|
+
|
14
|
+
BoaVista.configure do |config|
|
15
|
+
config.code = 'my code'
|
16
|
+
config.password = 'my password'
|
17
|
+
config.url = 'http://boa-vista-url.com'
|
18
|
+
config.timeout = 2
|
19
|
+
end
|
20
|
+
end
|