azeroth 0.0.7 → 0.1.0
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/.circleci/config.yml +1 -1
- data/Dockerfile +1 -1
- data/README.md +1 -1
- data/azeroth.gemspec +2 -2
- data/config/yardstick.yml +1 -0
- data/lib/azeroth.rb +4 -1
- data/lib/azeroth/request_handler.rb +93 -0
- data/lib/azeroth/request_handler/create.rb +26 -0
- data/lib/azeroth/request_handler/destroy.rb +22 -0
- data/lib/azeroth/request_handler/edit.rb +14 -0
- data/lib/azeroth/request_handler/index.rb +21 -0
- data/lib/azeroth/request_handler/new.rb +25 -0
- data/lib/azeroth/request_handler/show.rb +24 -0
- data/lib/azeroth/request_handler/update.rb +27 -0
- data/lib/azeroth/resourceable.rb +0 -14
- data/lib/azeroth/resourceable/builder.rb +0 -8
- data/lib/azeroth/routes_builder.rb +14 -38
- data/lib/azeroth/version.rb +1 -1
- data/spec/controllers/documents_controller_spec.rb +69 -22
- data/spec/dummy/db/schema.rb +2 -2
- data/spec/lib/azeroth/request_handler/create_spec.rb +27 -0
- data/spec/lib/azeroth/request_handler/destroy_spec.rb +20 -0
- data/spec/lib/azeroth/request_handler/edit_spec.rb +13 -0
- data/spec/lib/azeroth/request_handler/index_spec.rb +12 -0
- data/spec/lib/azeroth/request_handler/new_spec.rb +12 -0
- data/spec/lib/azeroth/request_handler/show_spec.rb +13 -0
- data/spec/lib/azeroth/request_handler/update_spec.rb +32 -0
- data/spec/lib/azeroth/request_handler_spec.rb +68 -0
- data/spec/lib/azeroth/resourceable/builder_spec.rb +1 -3
- data/spec/lib/azeroth/routes_builder_spec.rb +36 -8
- data/spec/support/app/controllers/request_handler_controller.rb +15 -0
- data/spec/support/shared_examples/request_handler.rb +53 -0
- metadata +30 -9
- data/lib/azeroth/resource_route_builder.rb +0 -124
- data/spec/lib/azeroth/resource_route_builder_spec.rb +0 -22
- data/spec/support/app/controllers/routes_builder_controller.rb +0 -23
- data/spec/support/shared_examples/resource_routes.rb +0 -90
data/lib/azeroth/version.rb
CHANGED
@@ -15,6 +15,10 @@ describe DocumentsController do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
let(:expected_json) do
|
19
|
+
Document::Decorator.new(documents).as_json
|
20
|
+
end
|
21
|
+
|
18
22
|
context 'when calling on format json' do
|
19
23
|
before do
|
20
24
|
get :index, params: { format: :json }
|
@@ -23,7 +27,7 @@ describe DocumentsController do
|
|
23
27
|
it { expect(response).to be_successful }
|
24
28
|
|
25
29
|
it 'returns empty array' do
|
26
|
-
expect(parsed_response).to eq(
|
30
|
+
expect(parsed_response).to eq(expected_json)
|
27
31
|
end
|
28
32
|
|
29
33
|
context 'when there is a document' do
|
@@ -32,7 +36,7 @@ describe DocumentsController do
|
|
32
36
|
it { expect(response).to be_successful }
|
33
37
|
|
34
38
|
it 'renders documents json' do
|
35
|
-
expect(parsed_response).to eq(
|
39
|
+
expect(parsed_response).to eq(expected_json)
|
36
40
|
end
|
37
41
|
end
|
38
42
|
end
|
@@ -52,6 +56,10 @@ describe DocumentsController do
|
|
52
56
|
let(:document) { Document.create }
|
53
57
|
let(:document_id) { document.id }
|
54
58
|
|
59
|
+
let(:expected_json) do
|
60
|
+
Document::Decorator.new(document).as_json
|
61
|
+
end
|
62
|
+
|
55
63
|
context 'when calling on format json' do
|
56
64
|
before do
|
57
65
|
get :show, params: { id: document_id, format: :json }
|
@@ -60,7 +68,7 @@ describe DocumentsController do
|
|
60
68
|
it { expect(response).to be_successful }
|
61
69
|
|
62
70
|
it 'returns document json' do
|
63
|
-
expect(parsed_response).to eq(
|
71
|
+
expect(parsed_response).to eq(expected_json)
|
64
72
|
end
|
65
73
|
end
|
66
74
|
|
@@ -93,25 +101,34 @@ describe DocumentsController do
|
|
93
101
|
describe 'POST create' do
|
94
102
|
let(:parameters) do
|
95
103
|
{
|
104
|
+
format: format,
|
96
105
|
document: {
|
97
106
|
name: 'My document'
|
98
107
|
}
|
99
108
|
}
|
100
109
|
end
|
101
110
|
|
102
|
-
|
103
|
-
|
104
|
-
expect(response).to be_successful
|
105
|
-
end
|
111
|
+
context 'when requesting format json' do
|
112
|
+
let(:format) { :json }
|
106
113
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
114
|
+
let(:expected_json) do
|
115
|
+
Document::Decorator.new(Document.last).as_json
|
116
|
+
end
|
111
117
|
|
112
|
-
|
113
|
-
|
114
|
-
.to
|
118
|
+
it do
|
119
|
+
post :create, params: parameters
|
120
|
+
expect(response).to be_successful
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'returns created document json' do
|
124
|
+
post :create, params: parameters
|
125
|
+
expect(parsed_response).to eq(expected_json)
|
126
|
+
end
|
127
|
+
|
128
|
+
it do
|
129
|
+
expect { post :create, params: parameters }
|
130
|
+
.to change(Document, :count).by(1)
|
131
|
+
end
|
115
132
|
end
|
116
133
|
end
|
117
134
|
|
@@ -119,9 +136,14 @@ describe DocumentsController do
|
|
119
136
|
let(:document) { Document.create }
|
120
137
|
let(:document_id) { document.id }
|
121
138
|
|
139
|
+
let(:expected_json) do
|
140
|
+
Document::Decorator.new(Document.last).as_json
|
141
|
+
end
|
142
|
+
|
122
143
|
let(:parameters) do
|
123
144
|
{
|
124
145
|
id: document_id,
|
146
|
+
format: :json,
|
125
147
|
document: {
|
126
148
|
name: 'My document'
|
127
149
|
}
|
@@ -135,7 +157,7 @@ describe DocumentsController do
|
|
135
157
|
|
136
158
|
it 'returns updated document json' do
|
137
159
|
patch :update, params: parameters
|
138
|
-
expect(parsed_response).to eq(
|
160
|
+
expect(parsed_response).to eq(expected_json)
|
139
161
|
end
|
140
162
|
|
141
163
|
it do
|
@@ -161,13 +183,29 @@ describe DocumentsController do
|
|
161
183
|
end
|
162
184
|
|
163
185
|
describe 'GET new' do
|
164
|
-
|
186
|
+
context 'when calling with format json' do
|
187
|
+
before { get :new, params: { format: :json } }
|
165
188
|
|
166
|
-
|
167
|
-
|
189
|
+
let(:expected_json) do
|
190
|
+
Document::Decorator.new(Document.new).as_json
|
191
|
+
end
|
192
|
+
|
193
|
+
it do
|
194
|
+
expect(response).to be_successful
|
195
|
+
end
|
196
|
+
|
197
|
+
it { expect(parsed_response).to eq(expected_json) }
|
168
198
|
end
|
169
199
|
|
170
|
-
|
200
|
+
context 'when calling with format html' do
|
201
|
+
before { get :new }
|
202
|
+
|
203
|
+
it do
|
204
|
+
expect(response).to be_successful
|
205
|
+
end
|
206
|
+
|
207
|
+
it { expect(response).to render_template('documents/new') }
|
208
|
+
end
|
171
209
|
end
|
172
210
|
|
173
211
|
describe 'GET edit' do
|
@@ -175,6 +213,10 @@ describe DocumentsController do
|
|
175
213
|
let(:document_id) { document.id }
|
176
214
|
|
177
215
|
context 'when calling on format json' do
|
216
|
+
let(:expected_json) do
|
217
|
+
Document::Decorator.new(document).as_json
|
218
|
+
end
|
219
|
+
|
178
220
|
before do
|
179
221
|
get :edit, params: { id: document_id, format: :json }
|
180
222
|
end
|
@@ -182,7 +224,7 @@ describe DocumentsController do
|
|
182
224
|
it { expect(response).to be_successful }
|
183
225
|
|
184
226
|
it 'returns document json' do
|
185
|
-
expect(parsed_response).to eq(
|
227
|
+
expect(parsed_response).to eq(expected_json)
|
186
228
|
end
|
187
229
|
end
|
188
230
|
|
@@ -216,9 +258,14 @@ describe DocumentsController do
|
|
216
258
|
let!(:document) { Document.create }
|
217
259
|
let(:document_id) { document.id }
|
218
260
|
|
261
|
+
let(:expected_json) do
|
262
|
+
Document::Decorator.new(document).as_json
|
263
|
+
end
|
264
|
+
|
219
265
|
let(:parameters) do
|
220
266
|
{
|
221
|
-
id: document_id
|
267
|
+
id: document_id,
|
268
|
+
format: :json
|
222
269
|
}
|
223
270
|
end
|
224
271
|
|
@@ -229,7 +276,7 @@ describe DocumentsController do
|
|
229
276
|
|
230
277
|
it do
|
231
278
|
delete :destroy, params: parameters
|
232
|
-
expect(
|
279
|
+
expect(parsed_response).to eq(expected_json)
|
233
280
|
end
|
234
281
|
|
235
282
|
it do
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::Create do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let(:extra_params) do
|
9
|
+
{
|
10
|
+
document: {
|
11
|
+
name: 'My Document'
|
12
|
+
}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:expected_json) do
|
17
|
+
{ 'name' => 'My Document' }
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'creates entry' do
|
21
|
+
expect { handler.process }
|
22
|
+
.to change(Document, :count)
|
23
|
+
.by(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::Destroy do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let(:expected_resource) { document }
|
9
|
+
let!(:document) { create(:document) }
|
10
|
+
|
11
|
+
let(:extra_params) { { id: document.id } }
|
12
|
+
|
13
|
+
it 'updates the values' do
|
14
|
+
expect { handler.process }
|
15
|
+
.to change(Document, :count)
|
16
|
+
.by(-1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::Edit do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let!(:document) { create(:document) }
|
9
|
+
let(:expected_resource) { document }
|
10
|
+
let(:extra_params) { { 'id' => document.id } }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::Index do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let(:documents_count) { 3 }
|
9
|
+
let(:expected_resource) { Document.all }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::New do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let(:document) { create(:document) }
|
9
|
+
let(:expected_resource) { Document.new }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::Show do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let!(:document) { create(:document) }
|
9
|
+
let(:expected_resource) { document }
|
10
|
+
let(:extra_params) { { 'id' => document.id } }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler::Update do
|
6
|
+
describe '#process' do
|
7
|
+
it_behaves_like 'a request handler' do
|
8
|
+
let(:expected_resource) { document }
|
9
|
+
let!(:document) { create(:document) }
|
10
|
+
|
11
|
+
let(:extra_params) do
|
12
|
+
{
|
13
|
+
id: document.id,
|
14
|
+
document: {
|
15
|
+
name: 'New Name'
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:expected_json) do
|
21
|
+
decorator.as_json.merge('name' => 'New Name')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'updates the values' do
|
25
|
+
expect { handler.process }
|
26
|
+
.to change { document.reload.name }
|
27
|
+
.from(document.name)
|
28
|
+
.to('New Name')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Azeroth::RequestHandler do
|
6
|
+
describe '#process' do
|
7
|
+
subject(:handler) { handler_class.new(controller, model) }
|
8
|
+
|
9
|
+
let(:controller) { controller_class.new }
|
10
|
+
let(:params) { ActionController::Parameters.new(parameters) }
|
11
|
+
let(:model) { Azeroth::Model.new(:document) }
|
12
|
+
|
13
|
+
let(:decorator) { Document::Decorator.new(Document.all) }
|
14
|
+
let(:expected_json) { decorator.as_json }
|
15
|
+
let(:documents_count) { 3 }
|
16
|
+
|
17
|
+
let(:controller_class) { RequestHandlerController }
|
18
|
+
|
19
|
+
let(:parameters) do
|
20
|
+
{ format: format }
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:handler_class) do
|
24
|
+
Class.new(described_class) do
|
25
|
+
private
|
26
|
+
|
27
|
+
def resource
|
28
|
+
Document.all
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
documents_count.times { create(:document) }
|
35
|
+
|
36
|
+
allow(controller).to receive(:params)
|
37
|
+
.and_return(params)
|
38
|
+
|
39
|
+
allow(controller).to receive(:render)
|
40
|
+
.with(json: expected_json)
|
41
|
+
.and_return(expected_json)
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with format json' do
|
45
|
+
let(:format) { 'json' }
|
46
|
+
|
47
|
+
it 'returns json for resource' do
|
48
|
+
expect(handler.process).to eq(expected_json)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'renders the json' do
|
52
|
+
handler.process
|
53
|
+
|
54
|
+
expect(controller).to have_received(:render)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with format html' do
|
59
|
+
let(:format) { 'html' }
|
60
|
+
|
61
|
+
it do
|
62
|
+
handler.process
|
63
|
+
|
64
|
+
expect(controller).not_to have_received(:render)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -7,17 +7,38 @@ describe Azeroth::RoutesBuilder do
|
|
7
7
|
described_class.new(model, builder, options)
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:
|
11
|
-
let(:
|
12
|
-
let(:
|
13
|
-
let(:
|
14
|
-
let(:
|
10
|
+
let(:controller) { controller_class.new }
|
11
|
+
let(:params) { ActionController::Parameters.new(parameters) }
|
12
|
+
let(:model) { Azeroth::Model.new(:document) }
|
13
|
+
let(:builder) { Sinclair.new(controller_class) }
|
14
|
+
let(:parameters) { { action: :index, format: :json } }
|
15
|
+
|
15
16
|
let(:options) { Azeroth::Options.new(options_hash) }
|
16
17
|
let(:options_hash) { {} }
|
17
18
|
|
19
|
+
let(:expected_json) do
|
20
|
+
Document::Decorator.new(Document.all).as_json
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:controller_class) do
|
24
|
+
Class.new(ActionController::Base) do
|
25
|
+
include Azeroth::Resourceable
|
26
|
+
|
27
|
+
def documents
|
28
|
+
Document.all
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
18
33
|
before do
|
19
|
-
routes_builder.append
|
20
34
|
10.times { Document.create }
|
35
|
+
|
36
|
+
allow(controller).to receive(:params)
|
37
|
+
.and_return(params)
|
38
|
+
|
39
|
+
allow(controller).to receive(:render)
|
40
|
+
.with(json: expected_json)
|
41
|
+
.and_return(expected_json)
|
21
42
|
end
|
22
43
|
|
23
44
|
describe '#append' do
|
@@ -26,14 +47,21 @@ describe Azeroth::RoutesBuilder do
|
|
26
47
|
it 'adds index route' do
|
27
48
|
expect do
|
28
49
|
builder.build
|
29
|
-
end.to add_method(:index).to(
|
50
|
+
end.to add_method(:index).to(controller)
|
30
51
|
end
|
31
52
|
|
32
53
|
describe 'when calling index' do
|
33
54
|
before { builder.build }
|
34
55
|
|
35
56
|
it 'returns the index object' do
|
36
|
-
expect(
|
57
|
+
expect(controller.index).to eq(expected_json)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'renders the json' do
|
61
|
+
controller.index
|
62
|
+
|
63
|
+
expect(controller).to have_received(:render)
|
64
|
+
.with(json: expected_json)
|
37
65
|
end
|
38
66
|
end
|
39
67
|
end
|