rest_my_case 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rest_my_case.rb +4 -2
- data/lib/rest_my_case/context/http_status.rb +68 -0
- data/lib/rest_my_case/context/status/matcher.rb +0 -4
- data/lib/rest_my_case/context/status/status.rb +5 -3
- data/lib/rest_my_case/errors/abort.rb +7 -0
- data/lib/rest_my_case/errors/base.rb +10 -0
- data/lib/rest_my_case/errors/skip.rb +7 -0
- data/lib/rest_my_case/http_status.rb +12 -0
- data/lib/rest_my_case/{with_status.rb → status.rb} +9 -3
- data/lib/rest_my_case/validator.rb +1 -1
- data/lib/rest_my_case/version.rb +1 -1
- data/spec/rest_my_case/accusation_attorneys/base_spec.rb +17 -0
- data/spec/rest_my_case/accusation_attorneys/each_spec.rb +17 -0
- data/spec/rest_my_case/context/status/base_spec.rb +16 -0
- data/spec/rest_my_case/context/status/status_spec.rb +45 -0
- data/spec/rest_my_case/http_status_spec.rb +33 -0
- data/spec/rest_my_case/status_spec.rb +77 -0
- metadata +19 -3
- data/lib/rest_my_case/errors.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3806b834670a2c8eb80d7fd00ef3923afee77ed
|
4
|
+
data.tar.gz: 94a6d4365d873c9a48bf677f5531b9b7e973d4f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 068a0cfdca202c28835aaece3c99b8efd36a3ae38d4c01c04c9db9673a966f1de84743f6278b116fdcaa3a222afae945c0be3d56381936cfef25103bbf100b9c
|
7
|
+
data.tar.gz: c580aa1241f136e325f7ed3d2db9e878a93c17761b902841dcb54628db413128086071066109d71c3b90ebaf32159d8e221315194765ced3ae86e1298a4141b4
|
data/lib/rest_my_case.rb
CHANGED
@@ -2,7 +2,7 @@ require 'ostruct'
|
|
2
2
|
|
3
3
|
require 'rest_my_case/version'
|
4
4
|
require 'rest_my_case/helpers'
|
5
|
-
require 'rest_my_case/errors'
|
5
|
+
require 'rest_my_case/errors/base'
|
6
6
|
require 'rest_my_case/config/base'
|
7
7
|
require 'rest_my_case/config/general'
|
8
8
|
require 'rest_my_case/defense_attorney/base'
|
@@ -10,6 +10,7 @@ require 'rest_my_case/context/base'
|
|
10
10
|
require 'rest_my_case/context/status/matcher'
|
11
11
|
require 'rest_my_case/context/status/status'
|
12
12
|
require 'rest_my_case/context/status/base'
|
13
|
+
require 'rest_my_case/context/http_status'
|
13
14
|
require 'rest_my_case/judge/base'
|
14
15
|
require 'rest_my_case/trial/case'
|
15
16
|
require 'rest_my_case/trial/court'
|
@@ -25,7 +26,8 @@ require 'rest_my_case/accusation_attorneys/presence'
|
|
25
26
|
require 'rest_my_case/accusation_attorneys/numericality'
|
26
27
|
|
27
28
|
require 'rest_my_case/base'
|
28
|
-
require 'rest_my_case/
|
29
|
+
require 'rest_my_case/status'
|
30
|
+
require 'rest_my_case/http_status'
|
29
31
|
require 'rest_my_case/validator'
|
30
32
|
|
31
33
|
module RestMyCase
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module RestMyCase
|
2
|
+
module Context
|
3
|
+
|
4
|
+
class HttpStatus < Status::Base
|
5
|
+
|
6
|
+
RAILS_HTTP_STATUS = {
|
7
|
+
continue: 100,
|
8
|
+
switching_protocols: 101,
|
9
|
+
processing: 102,
|
10
|
+
ok: 200,
|
11
|
+
created: 201,
|
12
|
+
accepted: 202,
|
13
|
+
non_authoritative_information: 203,
|
14
|
+
no_content: 204,
|
15
|
+
reset_content: 205,
|
16
|
+
partial_content: 206,
|
17
|
+
multi_status: 207,
|
18
|
+
im_used: 226,
|
19
|
+
multiple_choices: 300,
|
20
|
+
moved_permanently: 301,
|
21
|
+
found: 302,
|
22
|
+
see_other: 303,
|
23
|
+
not_modified: 304,
|
24
|
+
use_proxy: 305,
|
25
|
+
temporary_redirect: 307,
|
26
|
+
bad_request: 400,
|
27
|
+
unauthorized: 401,
|
28
|
+
payment_required: 402,
|
29
|
+
forbidden: 403,
|
30
|
+
not_found: 404,
|
31
|
+
method_not_allowed: 405,
|
32
|
+
not_acceptable: 406,
|
33
|
+
proxy_authentication_required: 407,
|
34
|
+
request_timeout: 408,
|
35
|
+
conflict: 409,
|
36
|
+
gone: 410,
|
37
|
+
length_required: 411,
|
38
|
+
precondition_failed: 412,
|
39
|
+
request_entity_too_large: 413,
|
40
|
+
request_uri_too_long: 414,
|
41
|
+
unsupported_media_type: 415,
|
42
|
+
requested_range_not_satisfiable: 416,
|
43
|
+
expectation_failed: 417,
|
44
|
+
unprocessable_entity: 422,
|
45
|
+
locked: 423,
|
46
|
+
failed_dependency: 424,
|
47
|
+
upgrade_required: 426,
|
48
|
+
internal_server_error: 500,
|
49
|
+
not_implemented: 501,
|
50
|
+
bad_gateway: 502,
|
51
|
+
service_unavailable: 503,
|
52
|
+
gateway_timeout: 504,
|
53
|
+
http_version_not_supported: 505,
|
54
|
+
insufficient_storage: 507,
|
55
|
+
not_extended: 510
|
56
|
+
}
|
57
|
+
|
58
|
+
def http_status
|
59
|
+
RAILS_HTTP_STATUS[status.current.to_sym]
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
|
@@ -22,10 +22,12 @@ module RestMyCase
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
26
|
-
|
25
|
+
def to_s
|
26
|
+
current.to_s
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
+
def ==(value)
|
30
|
+
to_s == value
|
29
31
|
end
|
30
32
|
|
31
33
|
end
|
@@ -1,16 +1,22 @@
|
|
1
1
|
module RestMyCase
|
2
2
|
|
3
|
-
class
|
3
|
+
class Status < Base
|
4
4
|
|
5
5
|
def self.trial_court
|
6
6
|
@trial_court ||= Trial::Court.new \
|
7
7
|
Judge::Base, DefenseAttorney::Base, Base, Context::Status::Base
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
context_reader :status
|
11
|
+
|
12
|
+
def failure(status, message = nil)
|
11
13
|
context.status.send("#{status}!")
|
12
14
|
|
13
|
-
error
|
15
|
+
error(Helpers.blank?(message) ? "#{status}" : "#{status} - #{message}")
|
16
|
+
end
|
17
|
+
|
18
|
+
def failure!(status, message = nil)
|
19
|
+
failure(status, message) && fail(Errors::Abort)
|
14
20
|
end
|
15
21
|
|
16
22
|
end
|
data/lib/rest_my_case/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::AccusationAttorneys::Base do
|
4
|
+
|
5
|
+
describe '#validate' do
|
6
|
+
context "given that the child class hasn't implemented the validate method" do
|
7
|
+
TestCase4 = Class.new(described_class)
|
8
|
+
|
9
|
+
before { @instance = TestCase4.new({ attributes: { id: '1' } }) }
|
10
|
+
|
11
|
+
it 'should raise an error' do
|
12
|
+
expect { @instance.validate(nil) }.to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::AccusationAttorneys::Each do
|
4
|
+
|
5
|
+
describe '#validate_each' do
|
6
|
+
context "given that the child class hasn't implemented the validate_each method" do
|
7
|
+
TestCase5 = Class.new(described_class)
|
8
|
+
|
9
|
+
before { @instance = TestCase5.new({ attributes: { id: '1' } }) }
|
10
|
+
|
11
|
+
it 'should raise an error' do
|
12
|
+
expect { @instance.validate_each(nil, nil, nil) }.to raise_error
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Context::Status::Base do
|
4
|
+
|
5
|
+
describe '#status=' do
|
6
|
+
|
7
|
+
let(:context) { described_class.new }
|
8
|
+
|
9
|
+
it 'raises error' do
|
10
|
+
expect do
|
11
|
+
context.status = 'not_found'
|
12
|
+
end.to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Context::Status::Status do
|
4
|
+
|
5
|
+
describe '#method_missing' do
|
6
|
+
context "given that no method was previously called" do
|
7
|
+
before { @status = described_class.new }
|
8
|
+
|
9
|
+
it 'calling an unknown_method should raise an error' do
|
10
|
+
expect { @status.unknown_method }.to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it '#ok? should be true' do
|
14
|
+
expect(@status.ok?).to be true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#to_s' do
|
20
|
+
context "given that .not_found! was called" do
|
21
|
+
before do
|
22
|
+
@status = described_class.new
|
23
|
+
@status.not_found!
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return 'not_found'" do
|
27
|
+
expect(@status.to_s).to eq "not_found"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#==' do
|
33
|
+
context "given that .unauthorized! was called" do
|
34
|
+
before do
|
35
|
+
@status = described_class.new
|
36
|
+
@status.unauthorized!
|
37
|
+
end
|
38
|
+
|
39
|
+
it "comparing to 'unauthorized' should return true" do
|
40
|
+
expect(@status == 'unauthorized').to be true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::HttpStatus do
|
4
|
+
|
5
|
+
describe "context#http_status" do
|
6
|
+
|
7
|
+
context "when status.not_found! is used" do
|
8
|
+
NotFound = Class.new(RestMyCase::HttpStatus) { def perform; status.not_found!; end }
|
9
|
+
|
10
|
+
it "should only list the class's dependencies" do
|
11
|
+
expect(NotFound.perform.http_status).to be 404
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when failure(:unprocessable_entity) is used" do
|
16
|
+
UnprocessableEntity = Class.new(RestMyCase::HttpStatus) { def perform; failure(:unprocessable_entity); end }
|
17
|
+
|
18
|
+
it "should only list the class's dependencies" do
|
19
|
+
expect(UnprocessableEntity.perform.http_status).to be 422
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when failure!(:internal_server_error) is used" do
|
24
|
+
InternalServerError = Class.new(RestMyCase::HttpStatus) { def perform; failure!(:internal_server_error); end }
|
25
|
+
|
26
|
+
it "should only list the class's dependencies" do
|
27
|
+
expect(InternalServerError.perform.http_status).to be 500
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RestMyCase::Status do
|
4
|
+
|
5
|
+
describe "context#status" do
|
6
|
+
|
7
|
+
context "when status.not_found! is used" do
|
8
|
+
TestCase1 = Class.new(described_class) { def perform; status.accepted!; end }
|
9
|
+
|
10
|
+
before { @context = TestCase1.perform }
|
11
|
+
|
12
|
+
it "@context.status.accepted? should be true" do
|
13
|
+
expect(@context.status.accepted?).to be true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "@context.status.ok? should be false" do
|
17
|
+
expect(@context.status.ok?).to be false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when failure(:unprocessable_entity) is used" do
|
22
|
+
TestCase2 = Class.new(described_class) do
|
23
|
+
def perform
|
24
|
+
failure(:unprocessable_entity)
|
25
|
+
context.next_line = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
before { @context = TestCase2.perform }
|
30
|
+
|
31
|
+
it "@context.status.unprocessable_entity? should be true" do
|
32
|
+
expect(@context.status.unprocessable_entity?).to be true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "@context.next_line should be true" do
|
36
|
+
expect(@context.next_line).to be true
|
37
|
+
end
|
38
|
+
|
39
|
+
it "@context.status.ok? should be false" do
|
40
|
+
expect(@context.status.ok?).to be false
|
41
|
+
end
|
42
|
+
|
43
|
+
it "context's errors should have a proper message" do
|
44
|
+
expect(@context.errors["TestCase2"]).to eq ["unprocessable_entity"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when failure!(:internal_server_error) is used" do
|
49
|
+
TestCase3 = Class.new(described_class) do
|
50
|
+
def perform
|
51
|
+
failure!(:internal_server_error)
|
52
|
+
context.next_line = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
before { @context = TestCase3.perform }
|
57
|
+
|
58
|
+
it "@context.status.internal_server_error? should be true" do
|
59
|
+
expect(@context.status.internal_server_error?).to be true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "@context.next_line should be true" do
|
63
|
+
expect { context.next_line }.to raise_error
|
64
|
+
end
|
65
|
+
|
66
|
+
it "@context.status.ok? should be false" do
|
67
|
+
expect(@context.status.ok?).to be false
|
68
|
+
end
|
69
|
+
|
70
|
+
it "context's errors should have a proper message" do
|
71
|
+
expect(TestCase3.perform.errors["TestCase3"]).to eq ["internal_server_error"]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_my_case
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- goncalvesjoao
|
@@ -125,21 +125,31 @@ files:
|
|
125
125
|
- lib/rest_my_case/config/base.rb
|
126
126
|
- lib/rest_my_case/config/general.rb
|
127
127
|
- lib/rest_my_case/context/base.rb
|
128
|
+
- lib/rest_my_case/context/http_status.rb
|
128
129
|
- lib/rest_my_case/context/status/base.rb
|
129
130
|
- lib/rest_my_case/context/status/matcher.rb
|
130
131
|
- lib/rest_my_case/context/status/status.rb
|
131
132
|
- lib/rest_my_case/defense_attorney/base.rb
|
132
|
-
- lib/rest_my_case/errors.rb
|
133
|
+
- lib/rest_my_case/errors/abort.rb
|
134
|
+
- lib/rest_my_case/errors/base.rb
|
135
|
+
- lib/rest_my_case/errors/skip.rb
|
133
136
|
- lib/rest_my_case/helpers.rb
|
137
|
+
- lib/rest_my_case/http_status.rb
|
134
138
|
- lib/rest_my_case/judge/base.rb
|
139
|
+
- lib/rest_my_case/status.rb
|
135
140
|
- lib/rest_my_case/trial/case.rb
|
136
141
|
- lib/rest_my_case/trial/court.rb
|
137
142
|
- lib/rest_my_case/validator.rb
|
138
143
|
- lib/rest_my_case/version.rb
|
139
|
-
- lib/rest_my_case/with_status.rb
|
140
144
|
- rest_my_case.gemspec
|
145
|
+
- spec/rest_my_case/accusation_attorneys/base_spec.rb
|
146
|
+
- spec/rest_my_case/accusation_attorneys/each_spec.rb
|
141
147
|
- spec/rest_my_case/base_spec.rb
|
148
|
+
- spec/rest_my_case/context/status/base_spec.rb
|
149
|
+
- spec/rest_my_case/context/status/status_spec.rb
|
142
150
|
- spec/rest_my_case/defense_attorney/base_spec.rb
|
151
|
+
- spec/rest_my_case/http_status_spec.rb
|
152
|
+
- spec/rest_my_case/status_spec.rb
|
143
153
|
- spec/rest_my_case/trial_case/court_spec.rb
|
144
154
|
- spec/rest_my_case/validator/hierarchy_spec.rb
|
145
155
|
- spec/spec_helper.rb
|
@@ -174,8 +184,14 @@ signing_key:
|
|
174
184
|
specification_version: 4
|
175
185
|
summary: Quick and light "The Clean Architecture" use case implementation.
|
176
186
|
test_files:
|
187
|
+
- spec/rest_my_case/accusation_attorneys/base_spec.rb
|
188
|
+
- spec/rest_my_case/accusation_attorneys/each_spec.rb
|
177
189
|
- spec/rest_my_case/base_spec.rb
|
190
|
+
- spec/rest_my_case/context/status/base_spec.rb
|
191
|
+
- spec/rest_my_case/context/status/status_spec.rb
|
178
192
|
- spec/rest_my_case/defense_attorney/base_spec.rb
|
193
|
+
- spec/rest_my_case/http_status_spec.rb
|
194
|
+
- spec/rest_my_case/status_spec.rb
|
179
195
|
- spec/rest_my_case/trial_case/court_spec.rb
|
180
196
|
- spec/rest_my_case/validator/hierarchy_spec.rb
|
181
197
|
- spec/spec_helper.rb
|