erratum 0.0.1

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE.txt +19 -0
  4. data/README.md +2 -0
  5. data/Rakefile +2 -0
  6. data/lib/erratum/configuration.rb +44 -0
  7. data/lib/erratum/error.rb +110 -0
  8. data/lib/erratum/errors/authentication_error.rb +9 -0
  9. data/lib/erratum/errors/authentication_errors/duplicate_authentication_error.rb +37 -0
  10. data/lib/erratum/errors/authentication_errors/invalid_token_error.rb +30 -0
  11. data/lib/erratum/errors/authentication_errors/invalid_username_or_password_error.rb +30 -0
  12. data/lib/erratum/errors/authorization_error.rb +9 -0
  13. data/lib/erratum/errors/authorization_errors/forbidden_error.rb +48 -0
  14. data/lib/erratum/errors/crud_error.rb +24 -0
  15. data/lib/erratum/errors/crud_errors/association_error.rb +54 -0
  16. data/lib/erratum/errors/crud_errors/resource_not_found_error.rb +52 -0
  17. data/lib/erratum/errors/crud_errors/resource_persistence_error.rb +50 -0
  18. data/lib/erratum/errors/request_errors/parameter_missing_error.rb +43 -0
  19. data/lib/erratum/errors/request_errors/unpermitted_parameters_error.rb +49 -0
  20. data/lib/erratum/rescuable_resource.rb +29 -0
  21. data/lib/erratum/resource_naming.rb +31 -0
  22. data/lib/erratum/utilities/string.rb +18 -0
  23. data/lib/erratum/verifiable_resource.rb +23 -0
  24. data/lib/erratum/version.rb +4 -0
  25. data/lib/erratum.rb +48 -0
  26. data/spec/lib/erratum/configuration_spec.rb +27 -0
  27. data/spec/lib/erratum/error_spec.rb +189 -0
  28. data/spec/lib/erratum/errors/authentication_errors/duplicate_authentication_error_spec.rb +43 -0
  29. data/spec/lib/erratum/errors/authentication_errors/invalid_token_error_spec.rb +33 -0
  30. data/spec/lib/erratum/errors/authentication_errors/invalid_username_or_password_error_spec.rb +35 -0
  31. data/spec/lib/erratum/errors/authorization_errors/forbidden_error_spec.rb +52 -0
  32. data/spec/lib/erratum/errors/crud_errors/association_error_spec.rb +69 -0
  33. data/spec/lib/erratum/errors/crud_errors/resource_not_found_error_spec.rb +89 -0
  34. data/spec/lib/erratum/errors/crud_errors/resource_persistence_error_spec.rb +84 -0
  35. data/spec/lib/erratum/errors/request_errors/parameter_missing_error_spec.rb +58 -0
  36. data/spec/lib/erratum/errors/request_errors/unpermitted_parameters_error_spec.rb +67 -0
  37. data/spec/lib/erratum/rescuable_resource_spec.rb +8 -0
  38. data/spec/lib/human_error_spec.rb +20 -0
  39. data.tar.gz.sig +0 -0
  40. metadata +171 -0
  41. metadata.gz.sig +0 -0
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+ require 'rspeckled'
3
+ require 'erratum/errors/crud_errors/resource_persistence_error'
4
+ require 'active_support'
5
+ require 'active_model'
6
+ require 'active_record/errors'
7
+ require 'active_record/validations'
8
+
9
+ class ErratumTestModel
10
+ include ActiveModel::Model
11
+ include ActiveModel::AttributeMethods
12
+
13
+ attr_accessor :some_attribute
14
+
15
+ validates_presence_of :some_attribute
16
+
17
+ def attributes
18
+ {
19
+ 'some_attribute' => @some_attribute,
20
+ }
21
+ end
22
+ end
23
+
24
+ class Erratum
25
+ module Errors
26
+ RSpec.describe ResourcePersistenceError do
27
+ it 'has a status of 422' do
28
+ error = ResourcePersistenceError.new
29
+
30
+ expect(error.http_status).to eql 422
31
+ end
32
+
33
+ it 'has a code' do
34
+ error = ResourcePersistenceError.new
35
+
36
+ expect(error.code).to eql 'errors.resource_persistence_error'
37
+ end
38
+
39
+ it 'has a title' do
40
+ error = ResourcePersistenceError.new
41
+
42
+ expect(error.title).to eql 'Resource Persistence Error'
43
+ end
44
+
45
+ it 'includes the resource name and action in the detail' do
46
+ error = ResourcePersistenceError.new resource_name: 'dragon',
47
+ action: 'ride'
48
+
49
+ expect(error.detail).to eql 'One or more of the attributes on the dragon you ' \
50
+ 'attempted to ride is invalid.'
51
+ end
52
+
53
+ it 'includes the resource name and action in the source' do
54
+ error = ResourcePersistenceError.new errors: 'lots of errors',
55
+ attributes: 'winter is coming'
56
+
57
+ expect(error.source).to eql('errors' => 'lots of errors',
58
+ 'attributes' => 'winter is coming')
59
+ end
60
+
61
+ it 'can convert an "ActiveRecord::RecordNotSaved"' do
62
+ record = ErratumTestModel.new
63
+ record.valid?
64
+ resource_persistence_error = ActiveRecord::RecordNotSaved.new('message', record)
65
+ error = ResourcePersistenceError.
66
+ convert(resource_persistence_error)
67
+
68
+ expect(error.attributes).to eql('some_attribute' => nil)
69
+ expect(error.errors).to eql ["Some attribute can't be blank"]
70
+ end
71
+
72
+ it 'can convert an "ActiveRecord::RecordInvalid"' do
73
+ record = ErratumTestModel.new
74
+ record.valid?
75
+ resource_persistence_error = ActiveRecord::RecordInvalid.new(record)
76
+ error = ResourcePersistenceError.
77
+ convert(resource_persistence_error)
78
+
79
+ expect(error.attributes).to eql('some_attribute' => nil)
80
+ expect(error.errors).to eql ["Some attribute can't be blank"]
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ require 'rspeckled'
3
+ require 'erratum'
4
+ require 'action_controller'
5
+
6
+ class Erratum
7
+ module Errors
8
+ RSpec.describe ParameterMissingError do
9
+ it 'has a status' do
10
+ error = ParameterMissingError.new
11
+
12
+ expect(error.http_status).to eql 400
13
+ end
14
+
15
+ it 'has a code' do
16
+ error = ParameterMissingError.new
17
+
18
+ expect(error.code).to eql 'errors.parameter_missing_error'
19
+ end
20
+
21
+ it 'has a title' do
22
+ error = ParameterMissingError.new
23
+
24
+ expect(error.title).to eql 'Missing Parameter'
25
+ end
26
+
27
+ it 'includes the resource name and action in the detail' do
28
+ error = ParameterMissingError.new resource_name: 'dragon',
29
+ action: 'create',
30
+ parameter: 'color'
31
+
32
+ expect(error.detail).to eql "When attempting to create a dragon, 'color' is " \
33
+ "a required parameter."
34
+ end
35
+
36
+ it 'includes the resource name and action in the source' do
37
+ error = ParameterMissingError.new parameter: 'dragon'
38
+
39
+ expect(error.source).to eql('required_parameter' => 'dragon')
40
+ end
41
+
42
+ it 'can convert an "ActionController::ParameterMissing"' do
43
+ parameter_missing_error = ActionController::ParameterMissing.new('dragon')
44
+ error = ParameterMissingError.convert(parameter_missing_error)
45
+
46
+ expect(error.parameter).to eql 'dragon'
47
+ end
48
+
49
+ it 'can convert an "ActionController::ParameterMissing" while overriding attributes' do
50
+ parameter_missing_error = ActionController::ParameterMissing.new('dragon')
51
+ error = ParameterMissingError.convert(parameter_missing_error,
52
+ parameter: 'westeros')
53
+
54
+ expect(error.parameter).to eql 'westeros'
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+ require 'rspeckled'
3
+ require 'erratum'
4
+ require 'action_controller'
5
+
6
+ class Erratum
7
+ module Errors
8
+ RSpec.describe UnpermittedParametersError do
9
+ it 'has a status' do
10
+ error = UnpermittedParametersError.new
11
+
12
+ expect(error.http_status).to eql 400
13
+ end
14
+
15
+ it 'has a code' do
16
+ error = UnpermittedParametersError.new
17
+
18
+ expect(error.code).to eql 'errors.unpermitted_parameters_error'
19
+ end
20
+
21
+ it 'has a title' do
22
+ error = UnpermittedParametersError.new
23
+
24
+ expect(error.title).to eql 'Unpermitted Parameters'
25
+ end
26
+
27
+ it 'includes the resource name and action in the detail' do
28
+ error = UnpermittedParametersError.new resource_name: 'dragon',
29
+ action: 'create',
30
+ parameters: 'color'
31
+
32
+ expect(error.detail).to eql 'Attempting to create a dragon with the ' \
33
+ 'following parameters is not allowed: color'
34
+ end
35
+
36
+ it 'includes the resource name and action in the detail' do
37
+ error = UnpermittedParametersError.new resource_name: 'dragon',
38
+ action: 'create',
39
+ parameters: %w{color size}
40
+
41
+ expect(error.detail).to eql 'Attempting to create a dragon with the ' \
42
+ 'following parameters is not allowed: color, size'
43
+ end
44
+
45
+ it 'includes the resource name and action in the source' do
46
+ error = UnpermittedParametersError.new parameters: 'dragon'
47
+
48
+ expect(error.source).to eql('unpermitted_parameters' => ['dragon'])
49
+ end
50
+
51
+ it 'can convert an "ActionController::UnpermittedParameters"' do
52
+ parameters_error = ActionController::UnpermittedParameters.new(%w{dragon})
53
+ error = UnpermittedParametersError.convert(parameters_error)
54
+
55
+ expect(error.parameters).to eql %w{dragon}
56
+ end
57
+
58
+ it 'can convert an "ActionController::ParameterMissing" while overriding attributes' do
59
+ parameters_error = ActionController::UnpermittedParameters.new(%w{dragon})
60
+ error = UnpermittedParametersError.convert(parameters_error,
61
+ parameters: 'westeros')
62
+
63
+ expect(error.parameters).to eql %w{westeros}
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ require 'rspeckled'
3
+ require 'erratum/rescuable_resource'
4
+
5
+ class Erratum
6
+ RSpec.describe RescuableResource do
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'rspeckled'
3
+ require 'erratum'
4
+ require 'active_record/errors'
5
+
6
+ RSpec.describe Erratum do
7
+ let(:original_error) do
8
+ ActiveRecord::RecordNotFound.new("Couldn't find resource with 'id'=3")
9
+ end
10
+
11
+ it 'can lookup errors' do
12
+ expect(Erratum.fetch('InvalidTokenError')).to \
13
+ eql Erratum::Errors::InvalidTokenError
14
+ end
15
+
16
+ it 'can raise an error' do
17
+ expect { Erratum.raise('InvalidTokenError') }.to \
18
+ raise_error Erratum::Errors::InvalidTokenError
19
+ end
20
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: erratum
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - thegranddesign
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDqjCCApKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBNMREwDwYDV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 000RFl0u7xJE8dg9y3Kmntar83Mr/Uf1F88/4mQsvGNnxGa39QP9IY4p6FkyEO3L
30
+ RRz+3xE8j0OBl1FNALFtP74/A3zmBRbCizr8En/jbQe/DISJG2o8QOyqm/64uNoy
31
+ zRIv8lqQM8QFT76rzP5SBCERwN+ltKAFbQ5/FwmZNGWYnmCP3RZMQiRnbh+9H9lh
32
+ mlbwaYZTjgsXq6cy8N38EecewgBbZYS1IYJraE/M
33
+ -----END CERTIFICATE-----
34
+ date: 2016-05-01 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '3.4'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.4'
50
+ - !ruby/object:Gem::Dependency
51
+ name: rspeckled
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '0.0'
64
+ - !ruby/object:Gem::Dependency
65
+ name: activerecord
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '4.2'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '4.2'
78
+ - !ruby/object:Gem::Dependency
79
+ name: actionpack
80
+ requirement: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '4.2'
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '4.2'
92
+ description: ''
93
+ email: rubygems@livinghighontheblog.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - lib/erratum.rb
102
+ - lib/erratum/configuration.rb
103
+ - lib/erratum/error.rb
104
+ - lib/erratum/errors/authentication_error.rb
105
+ - lib/erratum/errors/authentication_errors/duplicate_authentication_error.rb
106
+ - lib/erratum/errors/authentication_errors/invalid_token_error.rb
107
+ - lib/erratum/errors/authentication_errors/invalid_username_or_password_error.rb
108
+ - lib/erratum/errors/authorization_error.rb
109
+ - lib/erratum/errors/authorization_errors/forbidden_error.rb
110
+ - lib/erratum/errors/crud_error.rb
111
+ - lib/erratum/errors/crud_errors/association_error.rb
112
+ - lib/erratum/errors/crud_errors/resource_not_found_error.rb
113
+ - lib/erratum/errors/crud_errors/resource_persistence_error.rb
114
+ - lib/erratum/errors/request_errors/parameter_missing_error.rb
115
+ - lib/erratum/errors/request_errors/unpermitted_parameters_error.rb
116
+ - lib/erratum/rescuable_resource.rb
117
+ - lib/erratum/resource_naming.rb
118
+ - lib/erratum/utilities/string.rb
119
+ - lib/erratum/verifiable_resource.rb
120
+ - lib/erratum/version.rb
121
+ - spec/lib/erratum/configuration_spec.rb
122
+ - spec/lib/erratum/error_spec.rb
123
+ - spec/lib/erratum/errors/authentication_errors/duplicate_authentication_error_spec.rb
124
+ - spec/lib/erratum/errors/authentication_errors/invalid_token_error_spec.rb
125
+ - spec/lib/erratum/errors/authentication_errors/invalid_username_or_password_error_spec.rb
126
+ - spec/lib/erratum/errors/authorization_errors/forbidden_error_spec.rb
127
+ - spec/lib/erratum/errors/crud_errors/association_error_spec.rb
128
+ - spec/lib/erratum/errors/crud_errors/resource_not_found_error_spec.rb
129
+ - spec/lib/erratum/errors/crud_errors/resource_persistence_error_spec.rb
130
+ - spec/lib/erratum/errors/request_errors/parameter_missing_error_spec.rb
131
+ - spec/lib/erratum/errors/request_errors/unpermitted_parameters_error_spec.rb
132
+ - spec/lib/erratum/rescuable_resource_spec.rb
133
+ - spec/lib/human_error_spec.rb
134
+ homepage:
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.5.1
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Errors Need Love
158
+ test_files:
159
+ - spec/lib/erratum/configuration_spec.rb
160
+ - spec/lib/erratum/error_spec.rb
161
+ - spec/lib/erratum/errors/authentication_errors/duplicate_authentication_error_spec.rb
162
+ - spec/lib/erratum/errors/authentication_errors/invalid_token_error_spec.rb
163
+ - spec/lib/erratum/errors/authentication_errors/invalid_username_or_password_error_spec.rb
164
+ - spec/lib/erratum/errors/authorization_errors/forbidden_error_spec.rb
165
+ - spec/lib/erratum/errors/crud_errors/association_error_spec.rb
166
+ - spec/lib/erratum/errors/crud_errors/resource_not_found_error_spec.rb
167
+ - spec/lib/erratum/errors/crud_errors/resource_persistence_error_spec.rb
168
+ - spec/lib/erratum/errors/request_errors/parameter_missing_error_spec.rb
169
+ - spec/lib/erratum/errors/request_errors/unpermitted_parameters_error_spec.rb
170
+ - spec/lib/erratum/rescuable_resource_spec.rb
171
+ - spec/lib/human_error_spec.rb
metadata.gz.sig ADDED
Binary file