Skip to content

Commit ee04b4f

Browse files
author
Sebastian Wilgosz
committed
Fix configuration and spec files
1 parent 1877069 commit ee04b4f

2 files changed

Lines changed: 13 additions & 30 deletions

File tree

lib/jsonapi_errors_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def self.configure(&block)
3939
config.configure(&block)
4040
end
4141

42-
def self.config
42+
def config
4343
Configuration.instance
4444
end
4545
end

spec/jsonapi_errors_handler_spec.rb

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
class TestJsonapiErrorsHandler
66
include JsonapiErrorsHandler
77

8+
def config
9+
JsonapiErrorsHandler::Configuration.instance
10+
end
11+
812
def render(json: {}, status:)
913
json.to_h.merge(status: status)
1014
end
@@ -79,7 +83,15 @@ def log_error(e)
7983
}
8084
end
8185

86+
it 'raises the original error by default' do
87+
expect { subject }.to raise_error(unmapped_error)
88+
end
89+
8290
it 'renders 500 error' do
91+
JsonapiErrorsHandler.configure do |config|
92+
config.handle_unexpected = true
93+
end
94+
8395
expect(subject).to include(expected_result)
8496
end
8597

@@ -94,35 +106,6 @@ def log_error(e)
94106
end
95107
end
96108

97-
describe '.map_error' do
98-
let(:subject) { dummy.map_error(mapped_error) }
99-
100-
context 'error is not in defined error list' do
101-
let(:mapped_error) { 'Error' }
102-
103-
it 'returns error' do
104-
expect(subject).to be_nil
105-
end
106-
end
107-
108-
context 'when error is an instance and is defined on the error list' do
109-
let(:mapped_error) { JsonapiErrorsHandler::Errors::Forbidden.new(message: 'test') }
110-
111-
it 'returns the original error if the instance had been risen' do
112-
expect(subject).to eq mapped_error
113-
expect(subject.detail).to eq('test')
114-
end
115-
end
116-
117-
context 'when error is a class and is defined on the error list' do
118-
let(:mapped_error) { JsonapiErrorsHandler::Errors::Forbidden }
119-
120-
it 'returns an instance of the risen error klass' do
121-
expect(subject).to eq mapped_error.new
122-
end
123-
end
124-
end
125-
126109
describe '.render_error' do
127110
let(:subject) { dummy.render_error(error) }
128111

0 commit comments

Comments
 (0)