azeroth 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/yardstick.yml +3 -1
- data/lib/azeroth.rb +9 -8
- data/lib/azeroth/decorator.rb +16 -2
- data/lib/azeroth/dummy_decorator.rb +25 -0
- data/lib/azeroth/model.rb +35 -4
- data/lib/azeroth/options.rb +6 -2
- data/lib/azeroth/resourceable/builder.rb +1 -1
- data/lib/azeroth/resourceable/class_methods.rb +14 -4
- data/lib/azeroth/version.rb +1 -1
- data/spec/controllers/documents_controller_spec.rb +2 -2
- data/spec/controllers/documents_with_error_controller_spec.rb +183 -0
- data/spec/dummy/app/controllers/documents_with_error_controller.rb +13 -0
- data/spec/dummy/app/controllers/index_documents_controller.rb +1 -1
- data/spec/dummy/app/models/document/decorator_with_error.rb +1 -2
- data/spec/dummy/app/models/dummy_model.rb +1 -1
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/lib/azeroth/dummy_decorator_spec.rb +66 -0
- data/spec/lib/azeroth/model_spec.rb +47 -1
- data/spec/lib/azeroth/request_handler_spec.rb +2 -1
- data/spec/lib/azeroth/resource_builder_spec.rb +2 -1
- data/spec/lib/azeroth/routes_builder_spec.rb +1 -1
- data/spec/support/factories/dummy_model.rb +1 -0
- data/spec/support/shared_examples/request_handler.rb +2 -1
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12fa0ab1ef082540f0c7d7bdedf2ed52c3b9bdce5655d15ea45779be34c1cbe0
|
4
|
+
data.tar.gz: 7b9e0ce7be0223f0e2d9797197160f30ec1113d48cb9375ad650846d4f1ae481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c2dffb1b5b8366d2c37ae8addf1c15396825c3711acdf6c4b20b7818ddf9dc7ad720a0be1baad0cc8dbe29a88fb3e4fe681989d892b96f4390d8787e8a95de
|
7
|
+
data.tar.gz: c1cdf88c0f8ecad8d5b00fb5a1898445e33b2da407c77893f87df2d1ca57cf051d99642f65273fdf3e8c08ea71746dd8e3c013550d65324105f16e9cbbcfb375
|
data/README.md
CHANGED
data/config/yardstick.yml
CHANGED
@@ -15,7 +15,8 @@ rules:
|
|
15
15
|
exclude: []
|
16
16
|
ExampleTag:
|
17
17
|
enabled: true
|
18
|
-
exclude:
|
18
|
+
exclude:
|
19
|
+
- Azeroth::DummyDecorator#as_json
|
19
20
|
ReturnTag:
|
20
21
|
enabled: true
|
21
22
|
exclude: []
|
@@ -24,6 +25,7 @@ rules:
|
|
24
25
|
exclude:
|
25
26
|
- Azeroth::Decorator#initialize
|
26
27
|
- Azeroth::Decorator::HashBuilder#initialize
|
28
|
+
- Azeroth::DummyDecorator#initialize
|
27
29
|
- Azeroth::Exception::InvalidOptions#initialize
|
28
30
|
- Azeroth::Model#initialize
|
29
31
|
- Azeroth::Options#initialize
|
data/lib/azeroth.rb
CHANGED
@@ -10,12 +10,13 @@ require 'sinclair'
|
|
10
10
|
#
|
11
11
|
# @see Resourceable
|
12
12
|
module Azeroth
|
13
|
-
autoload :Decorator,
|
14
|
-
autoload :
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
13
|
+
autoload :Decorator, 'azeroth/decorator'
|
14
|
+
autoload :DummyDecorator, 'azeroth/dummy_decorator'
|
15
|
+
autoload :Exception, 'azeroth/exception'
|
16
|
+
autoload :Model, 'azeroth/model'
|
17
|
+
autoload :RequestHandler, 'azeroth/request_handler'
|
18
|
+
autoload :Resourceable, 'azeroth/resourceable'
|
19
|
+
autoload :ResourceBuilder, 'azeroth/resource_builder'
|
20
|
+
autoload :RoutesBuilder, 'azeroth/routes_builder'
|
21
|
+
autoload :Options, 'azeroth/options'
|
21
22
|
end
|
data/lib/azeroth/decorator.rb
CHANGED
@@ -47,13 +47,27 @@ module Azeroth
|
|
47
47
|
#
|
48
48
|
# All attributes exposed
|
49
49
|
#
|
50
|
-
# @return [
|
50
|
+
# @return [Hash<Symbol,Hash>]
|
51
51
|
def attributes_map
|
52
|
-
@attributes_map ||=
|
52
|
+
@attributes_map ||= build_attributes_map
|
53
53
|
end
|
54
54
|
|
55
55
|
private
|
56
56
|
|
57
|
+
# @api private
|
58
|
+
# @private
|
59
|
+
#
|
60
|
+
# Initialize attributes to be exposed map
|
61
|
+
#
|
62
|
+
# When the class inherity from another
|
63
|
+
# decorator, the new class should expose the
|
64
|
+
# same attributes.
|
65
|
+
#
|
66
|
+
# @return [Hash<Symbol,Hash>]
|
67
|
+
def build_attributes_map
|
68
|
+
superclass.try(:attributes_map).dup || {}
|
69
|
+
end
|
70
|
+
|
57
71
|
# @visibility public
|
58
72
|
# @api public
|
59
73
|
# @private
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'sinclair'
|
4
|
+
|
5
|
+
module Azeroth
|
6
|
+
# @api private
|
7
|
+
# @author Darthjee
|
8
|
+
#
|
9
|
+
# Decorator that calls #as_json on object
|
10
|
+
class DummyDecorator
|
11
|
+
delegate :as_json, to: :@object
|
12
|
+
# @method as_json
|
13
|
+
# @public
|
14
|
+
# @api public
|
15
|
+
#
|
16
|
+
# Returns object.as_json
|
17
|
+
#
|
18
|
+
# @return [Hash]
|
19
|
+
|
20
|
+
# @param object [Object] object to be decorated
|
21
|
+
def initialize(object)
|
22
|
+
@object = object
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/azeroth/model.rb
CHANGED
@@ -7,12 +7,15 @@ module Azeroth
|
|
7
7
|
# Model responsible for making the conection to the resource model class
|
8
8
|
class Model
|
9
9
|
# @param name [String,Symbol] name of the resource
|
10
|
-
|
10
|
+
# @param options [Azeroth::Options] resource options
|
11
|
+
def initialize(name, options)
|
11
12
|
if name.is_a?(Class)
|
12
13
|
@klass = name
|
13
14
|
else
|
14
15
|
@name = name.to_s
|
15
16
|
end
|
17
|
+
|
18
|
+
@options = options
|
16
19
|
end
|
17
20
|
|
18
21
|
# Returns the name of the resource represented by the model
|
@@ -46,19 +49,47 @@ module Azeroth
|
|
46
49
|
# @return [Hash]
|
47
50
|
def decorate(object)
|
48
51
|
decorator_class.new(object).as_json
|
49
|
-
rescue NameError
|
50
|
-
object.as_json
|
51
52
|
end
|
52
53
|
|
53
54
|
private
|
54
55
|
|
56
|
+
attr_reader :options
|
57
|
+
# @method options
|
58
|
+
# @api private
|
59
|
+
# @private
|
60
|
+
#
|
61
|
+
# Returns options
|
62
|
+
#
|
63
|
+
# @return [Azeroth::Options]
|
64
|
+
|
55
65
|
# @private
|
56
66
|
#
|
57
67
|
# Returns decorator class for the object
|
58
68
|
#
|
59
69
|
# @return [Class] subclass of {Decorator}
|
60
70
|
def decorator_class
|
61
|
-
@decorator_class ||=
|
71
|
+
@decorator_class ||= calculate_decorator_class
|
72
|
+
end
|
73
|
+
|
74
|
+
# @private
|
75
|
+
#
|
76
|
+
# Calculates decorator class
|
77
|
+
#
|
78
|
+
# When options.decorator is false return DummyDecorator
|
79
|
+
#
|
80
|
+
# when options.decorator is a class, returns it
|
81
|
+
#
|
82
|
+
# When finding the decorator from the model fails,
|
83
|
+
# returns DummyDecorator
|
84
|
+
#
|
85
|
+
# @return [Azeroth::Decorator,DummyDecorator]
|
86
|
+
def calculate_decorator_class
|
87
|
+
return DummyDecorator unless options.decorator
|
88
|
+
return options.decorator if options.decorator.is_a?(Class)
|
89
|
+
|
90
|
+
klass::Decorator
|
91
|
+
rescue NameError
|
92
|
+
DummyDecorator
|
62
93
|
end
|
63
94
|
end
|
64
95
|
end
|
data/lib/azeroth/options.rb
CHANGED
@@ -6,16 +6,20 @@ module Azeroth
|
|
6
6
|
#
|
7
7
|
# Resource buiilding options
|
8
8
|
class Options < ::OpenStruct
|
9
|
+
# Default options
|
9
10
|
DEFAULT_OPTIONS = {
|
10
11
|
only: %i[create destroy edit index new show update],
|
11
|
-
except: []
|
12
|
+
except: [],
|
13
|
+
decorator: true
|
12
14
|
}.freeze
|
13
15
|
|
14
|
-
# @param options [Hash] hash with options
|
16
|
+
# @param options [Hash] hash with options (see {Options::DEFAULT_OPTIONS})
|
15
17
|
# @option options only [Array<Symbol,String>] List of
|
16
18
|
# actions to be built
|
17
19
|
# @option options except [Array<Symbol,String>] List of
|
18
20
|
# actions to not to be built
|
21
|
+
# @option options decorator [Azeroth::Decorator,TrueClass,FalseClass]
|
22
|
+
# Decorator class or flag allowing/disallowing decorators
|
19
23
|
def initialize(options = {})
|
20
24
|
check_options(options)
|
21
25
|
|
@@ -19,8 +19,8 @@ module Azeroth
|
|
19
19
|
# @param options [Options]
|
20
20
|
def initialize(clazz, model_name, options)
|
21
21
|
@clazz = clazz
|
22
|
-
@model = Azeroth::Model.new(model_name)
|
23
22
|
@options = options
|
23
|
+
@model = Azeroth::Model.new(model_name, options)
|
24
24
|
|
25
25
|
add_params
|
26
26
|
add_resource
|
@@ -10,15 +10,25 @@ module Azeroth
|
|
10
10
|
# Adds resource methods for resource
|
11
11
|
#
|
12
12
|
# @param name [String, Symbol] Name of the resource
|
13
|
-
# @param
|
13
|
+
# @param (see Options#initialize)
|
14
|
+
# @option (see Options#initialize)
|
14
15
|
#
|
15
|
-
# @return [Array<MethodDefinition>]
|
16
|
+
# @return [Array<MethodDefinition>] list of methods created
|
16
17
|
#
|
17
|
-
# @
|
18
|
+
# @see Options
|
19
|
+
#
|
20
|
+
# @example Controller without delete
|
21
|
+
# class DocumentsController < ApplicationController
|
22
|
+
# include Azeroth::Resourceable
|
23
|
+
#
|
24
|
+
# resource_for :document, except: :delete
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# @example Controller with only create, show and list
|
18
28
|
# class DocumentsController < ApplicationController
|
19
29
|
# include Azeroth::Resourceable
|
20
30
|
#
|
21
|
-
# resource_for :document
|
31
|
+
# resource_for :document, only: %w[create index show]
|
22
32
|
# end
|
23
33
|
def resource_for(name, **options)
|
24
34
|
Builder.new(
|
data/lib/azeroth/version.rb
CHANGED
@@ -215,12 +215,12 @@ describe DocumentsController do
|
|
215
215
|
end
|
216
216
|
|
217
217
|
it do
|
218
|
-
post :
|
218
|
+
post :update, params: parameters
|
219
219
|
expect(response).not_to be_successful
|
220
220
|
end
|
221
221
|
|
222
222
|
it 'returns created document json' do
|
223
|
-
post :
|
223
|
+
post :update, params: parameters
|
224
224
|
expect(parsed_response).to eq(expected_json)
|
225
225
|
end
|
226
226
|
|
@@ -0,0 +1,183 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DocumentsWithErrorController do
|
6
|
+
let(:parsed_response) do
|
7
|
+
JSON.parse(response.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'GET index' do
|
11
|
+
let(:documents_count) { 0 }
|
12
|
+
|
13
|
+
before do
|
14
|
+
documents_count.times.map { create(:document) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when calling on format json' do
|
18
|
+
it do
|
19
|
+
expect { get :index, params: { format: :json } }
|
20
|
+
.to raise_error(AbstractController::ActionNotFound)
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when there is a document' do
|
24
|
+
let(:documents_count) { 1 }
|
25
|
+
|
26
|
+
it do
|
27
|
+
expect { get :index, params: { format: :json } }
|
28
|
+
.to raise_error(AbstractController::ActionNotFound)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when calling on format html' do
|
34
|
+
it do
|
35
|
+
expect { get :index, params: { format: :html } }
|
36
|
+
.to raise_error(AbstractController::ActionNotFound)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'POST create' do
|
42
|
+
let(:payload) do
|
43
|
+
{
|
44
|
+
name: 'My document'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
let(:parameters) do
|
48
|
+
{
|
49
|
+
format: format,
|
50
|
+
document: payload
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when requesting format json' do
|
55
|
+
let(:format) { :json }
|
56
|
+
|
57
|
+
let(:expected_json) do
|
58
|
+
Document::Decorator.new(Document.last).as_json
|
59
|
+
end
|
60
|
+
|
61
|
+
it do
|
62
|
+
post :create, params: parameters
|
63
|
+
expect(response).to be_successful
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns created document json' do
|
67
|
+
post :create, params: parameters
|
68
|
+
expect(parsed_response).to eq(expected_json)
|
69
|
+
end
|
70
|
+
|
71
|
+
it do
|
72
|
+
expect { post :create, params: parameters }
|
73
|
+
.to change(Document, :count).by(1)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when there is validation error' do
|
78
|
+
let(:format) { :json }
|
79
|
+
let(:payload) { { reference: 'x01' } }
|
80
|
+
|
81
|
+
let(:expected_body) do
|
82
|
+
Document::DecoratorWithError.new(Document.new(payload)).to_json
|
83
|
+
end
|
84
|
+
|
85
|
+
it do
|
86
|
+
post :create, params: parameters
|
87
|
+
expect(response).not_to be_successful
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns created document json' do
|
91
|
+
post :create, params: parameters
|
92
|
+
expect(response.body).to eq(expected_body)
|
93
|
+
end
|
94
|
+
|
95
|
+
it do
|
96
|
+
expect { post :create, params: parameters }
|
97
|
+
.not_to change(Document, :count)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'PATCH update' do
|
103
|
+
let(:document) { create(:document) }
|
104
|
+
let(:document_id) { document.id }
|
105
|
+
|
106
|
+
let(:expected_body) do
|
107
|
+
Document.last.to_json
|
108
|
+
end
|
109
|
+
|
110
|
+
let(:payload) do
|
111
|
+
{
|
112
|
+
name: 'My document'
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
let(:parameters) do
|
117
|
+
{
|
118
|
+
id: document_id,
|
119
|
+
format: :json,
|
120
|
+
document: payload
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
it do
|
125
|
+
patch :update, params: parameters
|
126
|
+
expect(response).to be_successful
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'returns updated document json' do
|
130
|
+
patch :update, params: parameters
|
131
|
+
expect(response.body).to eq(expected_body)
|
132
|
+
end
|
133
|
+
|
134
|
+
it do
|
135
|
+
expect { patch :update, params: parameters }
|
136
|
+
.to change { document.reload.name }
|
137
|
+
.to('My document')
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'when calling on an inexistent id' do
|
141
|
+
let(:document_id) { :wrong_id }
|
142
|
+
|
143
|
+
before do
|
144
|
+
patch :update, params: parameters
|
145
|
+
end
|
146
|
+
|
147
|
+
it { expect(response).not_to be_successful }
|
148
|
+
it { expect(response.status).to eq(404) }
|
149
|
+
|
150
|
+
it 'returns empty body' do
|
151
|
+
expect(response.body).to eq('')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when there is validation error' do
|
156
|
+
let(:format) { :json }
|
157
|
+
let(:payload) { { name: nil } }
|
158
|
+
|
159
|
+
let(:expected_json) do
|
160
|
+
{
|
161
|
+
'id' => document.id,
|
162
|
+
'name' => '',
|
163
|
+
'reference' => nil
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
it do
|
168
|
+
post :update, params: parameters
|
169
|
+
expect(response).not_to be_successful
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'returns created document json' do
|
173
|
+
post :update, params: parameters
|
174
|
+
expect(parsed_response).to eq(expected_json)
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'does not update entry' do
|
178
|
+
expect { post :update, params: parameters }
|
179
|
+
.not_to(change { document.reload.name })
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class DocumentsWithErrorController < ApplicationController
|
4
|
+
include Azeroth::Resourceable
|
5
|
+
|
6
|
+
resource_for :document,
|
7
|
+
only: :create,
|
8
|
+
decorator: Document::DecoratorWithError
|
9
|
+
|
10
|
+
resource_for :document,
|
11
|
+
only: :update,
|
12
|
+
decorator: false
|
13
|
+
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::DummyDecorator do
|
6
|
+
subject(:decorator) { described_class.new(object) }
|
7
|
+
|
8
|
+
let(:model) { build(:dummy_model) }
|
9
|
+
let(:object) { model }
|
10
|
+
|
11
|
+
describe '#as_json' do
|
12
|
+
context 'when object is just a model' do
|
13
|
+
let(:expected_json) do
|
14
|
+
{
|
15
|
+
favorite_game: 'pokemon',
|
16
|
+
favorite_pokemon: 'squirtle',
|
17
|
+
first_name: 'dummy',
|
18
|
+
id: model.id,
|
19
|
+
last_name: 'bot',
|
20
|
+
age: 21
|
21
|
+
}.stringify_keys
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'object.as_json' do
|
25
|
+
expect(decorator.as_json).to eq(expected_json)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when object is an array' do
|
30
|
+
let(:object) { [model, other_model] }
|
31
|
+
|
32
|
+
let(:other_model) do
|
33
|
+
build(
|
34
|
+
:dummy_model,
|
35
|
+
first_name: 'dum',
|
36
|
+
age: 65,
|
37
|
+
favorite_pokemon: :bulbasaur
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:expected_json) do
|
42
|
+
[
|
43
|
+
{
|
44
|
+
favorite_game: 'pokemon',
|
45
|
+
favorite_pokemon: 'squirtle',
|
46
|
+
first_name: 'dummy',
|
47
|
+
id: model.id,
|
48
|
+
last_name: 'bot',
|
49
|
+
age: 21
|
50
|
+
}, {
|
51
|
+
favorite_game: 'pokemon',
|
52
|
+
favorite_pokemon: 'bulbasaur',
|
53
|
+
first_name: 'dum',
|
54
|
+
id: other_model.id,
|
55
|
+
last_name: 'bot',
|
56
|
+
age: 65
|
57
|
+
}
|
58
|
+
].map(&:stringify_keys)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'object.as_json' do
|
62
|
+
expect(decorator.as_json).to eq(expected_json)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -23,7 +23,10 @@ shared_examples 'a model wrapper' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe Azeroth::Model do
|
26
|
-
subject(:model) { described_class.new(input) }
|
26
|
+
subject(:model) { described_class.new(input, options) }
|
27
|
+
|
28
|
+
let(:options) { Azeroth::Options.new(options_hash) }
|
29
|
+
let(:options_hash) { {} }
|
27
30
|
|
28
31
|
context 'when initializing with symbol' do
|
29
32
|
let(:input) { :document }
|
@@ -119,5 +122,48 @@ describe Azeroth::Model do
|
|
119
122
|
expect(model.decorate(object)).to eq(object.as_json)
|
120
123
|
end
|
121
124
|
end
|
125
|
+
|
126
|
+
context 'when model has a decorator and option decorator is false' do
|
127
|
+
let(:input) { :document }
|
128
|
+
let(:reference) { SecureRandom.uuid }
|
129
|
+
let(:object) { create(:document, reference: reference) }
|
130
|
+
let(:options_hash) { { decorator: false } }
|
131
|
+
|
132
|
+
context 'when object is just a model and has decorator' do
|
133
|
+
let!(:object) { create(:document, reference: reference) }
|
134
|
+
|
135
|
+
let(:expected_json) do
|
136
|
+
object.as_json
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'object.as_json' do
|
140
|
+
expect(model.decorate(object)).to eq(expected_json)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when model has a decorator and option decorator is a decorator' do
|
146
|
+
let(:input) { :document }
|
147
|
+
let(:reference) { SecureRandom.uuid }
|
148
|
+
let(:object) { create(:document, reference: reference) }
|
149
|
+
let(:options_hash) { { decorator: Document::DecoratorWithError } }
|
150
|
+
|
151
|
+
context 'when object is just a model and has decorator' do
|
152
|
+
let!(:object) { Document.new }
|
153
|
+
|
154
|
+
let(:expected_json) do
|
155
|
+
{
|
156
|
+
name: nil,
|
157
|
+
errors: {
|
158
|
+
name: ["can't be blank"]
|
159
|
+
}
|
160
|
+
}.stringify_keys
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'object.as_json' do
|
164
|
+
expect(model.decorate(object)).to eq(expected_json)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
122
168
|
end
|
123
169
|
end
|
@@ -8,7 +8,8 @@ describe Azeroth::RequestHandler do
|
|
8
8
|
|
9
9
|
let(:controller) { controller_class.new }
|
10
10
|
let(:params) { ActionController::Parameters.new(parameters) }
|
11
|
-
let(:model) { Azeroth::Model.new(:document) }
|
11
|
+
let(:model) { Azeroth::Model.new(:document, options) }
|
12
|
+
let(:options) { Azeroth::Options.new }
|
12
13
|
|
13
14
|
let(:decorator) { Document::Decorator.new(Document.all) }
|
14
15
|
let(:expected_json) { decorator.as_json }
|
@@ -5,7 +5,8 @@ require 'spec_helper'
|
|
5
5
|
describe Azeroth::ResourceBuilder do
|
6
6
|
subject(:resource_builder) { described_class.new(model, builder) }
|
7
7
|
|
8
|
-
let(:model) { Azeroth::Model.new(:document) }
|
8
|
+
let(:model) { Azeroth::Model.new(:document, options) }
|
9
|
+
let(:options) { Azeroth::Options.new }
|
9
10
|
let(:builder) { Sinclair.new(klass) }
|
10
11
|
let(:klass) { Class.new(ResourceBuilderController) }
|
11
12
|
|
@@ -9,7 +9,7 @@ describe Azeroth::RoutesBuilder do
|
|
9
9
|
|
10
10
|
let(:controller) { controller_class.new }
|
11
11
|
let(:params) { ActionController::Parameters.new(parameters) }
|
12
|
-
let(:model) { Azeroth::Model.new(:document) }
|
12
|
+
let(:model) { Azeroth::Model.new(:document, options) }
|
13
13
|
let(:builder) { Sinclair.new(controller_class) }
|
14
14
|
let(:parameters) { { action: :index, format: :json } }
|
15
15
|
|
@@ -5,7 +5,8 @@ shared_examples 'a request handler' do |status: :ok|
|
|
5
5
|
|
6
6
|
let(:controller) { controller_class.new }
|
7
7
|
let(:params) { ActionController::Parameters.new(parameters) }
|
8
|
-
let(:model) { Azeroth::Model.new(:document) }
|
8
|
+
let(:model) { Azeroth::Model.new(:document, options) }
|
9
|
+
let(:options) { Azeroth::Options.new }
|
9
10
|
let(:extra_params) { {} }
|
10
11
|
|
11
12
|
let(:decorator) { Document::Decorator.new(expected_resource) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azeroth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
@@ -416,6 +416,7 @@ files:
|
|
416
416
|
- lib/azeroth.rb
|
417
417
|
- lib/azeroth/decorator.rb
|
418
418
|
- lib/azeroth/decorator/hash_builder.rb
|
419
|
+
- lib/azeroth/dummy_decorator.rb
|
419
420
|
- lib/azeroth/exception.rb
|
420
421
|
- lib/azeroth/model.rb
|
421
422
|
- lib/azeroth/options.rb
|
@@ -434,6 +435,7 @@ files:
|
|
434
435
|
- lib/azeroth/routes_builder.rb
|
435
436
|
- lib/azeroth/version.rb
|
436
437
|
- spec/controllers/documents_controller_spec.rb
|
438
|
+
- spec/controllers/documents_with_error_controller_spec.rb
|
437
439
|
- spec/controllers/index_documents_controller_spec.rb
|
438
440
|
- spec/dummy/.ruby-version
|
439
441
|
- spec/dummy/Rakefile
|
@@ -448,6 +450,7 @@ files:
|
|
448
450
|
- spec/dummy/app/controllers/application_controller.rb
|
449
451
|
- spec/dummy/app/controllers/concerns/.keep
|
450
452
|
- spec/dummy/app/controllers/documents_controller.rb
|
453
|
+
- spec/dummy/app/controllers/documents_with_error_controller.rb
|
451
454
|
- spec/dummy/app/controllers/index_documents_controller.rb
|
452
455
|
- spec/dummy/app/helpers/application_helper.rb
|
453
456
|
- spec/dummy/app/jobs/application_job.rb
|
@@ -513,6 +516,7 @@ files:
|
|
513
516
|
- spec/integration/yard/azeroth/exception/invalid_options_spec.rb
|
514
517
|
- spec/lib/azeroth/decorator/hash_builder_spec.rb
|
515
518
|
- spec/lib/azeroth/decorator_spec.rb
|
519
|
+
- spec/lib/azeroth/dummy_decorator_spec.rb
|
516
520
|
- spec/lib/azeroth/exception/invalid_options_spec.rb
|
517
521
|
- spec/lib/azeroth/model_spec.rb
|
518
522
|
- spec/lib/azeroth/options_spec.rb
|
@@ -563,6 +567,7 @@ specification_version: 4
|
|
563
567
|
summary: Azeroth
|
564
568
|
test_files:
|
565
569
|
- spec/controllers/documents_controller_spec.rb
|
570
|
+
- spec/controllers/documents_with_error_controller_spec.rb
|
566
571
|
- spec/controllers/index_documents_controller_spec.rb
|
567
572
|
- spec/dummy/.ruby-version
|
568
573
|
- spec/dummy/Rakefile
|
@@ -577,6 +582,7 @@ test_files:
|
|
577
582
|
- spec/dummy/app/controllers/application_controller.rb
|
578
583
|
- spec/dummy/app/controllers/concerns/.keep
|
579
584
|
- spec/dummy/app/controllers/documents_controller.rb
|
585
|
+
- spec/dummy/app/controllers/documents_with_error_controller.rb
|
580
586
|
- spec/dummy/app/controllers/index_documents_controller.rb
|
581
587
|
- spec/dummy/app/helpers/application_helper.rb
|
582
588
|
- spec/dummy/app/jobs/application_job.rb
|
@@ -642,6 +648,7 @@ test_files:
|
|
642
648
|
- spec/integration/yard/azeroth/exception/invalid_options_spec.rb
|
643
649
|
- spec/lib/azeroth/decorator/hash_builder_spec.rb
|
644
650
|
- spec/lib/azeroth/decorator_spec.rb
|
651
|
+
- spec/lib/azeroth/dummy_decorator_spec.rb
|
645
652
|
- spec/lib/azeroth/exception/invalid_options_spec.rb
|
646
653
|
- spec/lib/azeroth/model_spec.rb
|
647
654
|
- spec/lib/azeroth/options_spec.rb
|