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
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RequestHandlerController < ActionController::Base
|
4
|
+
def document_params
|
5
|
+
params.require(:document).permit(:name)
|
6
|
+
end
|
7
|
+
|
8
|
+
def documents
|
9
|
+
Document.all
|
10
|
+
end
|
11
|
+
|
12
|
+
def document
|
13
|
+
documents.find(params.require(:id))
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'a request handler' do
|
4
|
+
subject(:handler) { described_class.new(controller, model) }
|
5
|
+
|
6
|
+
let(:controller) { controller_class.new }
|
7
|
+
let(:params) { ActionController::Parameters.new(parameters) }
|
8
|
+
let(:model) { Azeroth::Model.new(:document) }
|
9
|
+
let(:extra_params) { {} }
|
10
|
+
|
11
|
+
let(:decorator) { Document::Decorator.new(expected_resource) }
|
12
|
+
let(:expected_json) { decorator.as_json }
|
13
|
+
let(:documents_count) { 0 }
|
14
|
+
|
15
|
+
let(:controller_class) { RequestHandlerController }
|
16
|
+
|
17
|
+
let(:format) { 'json' }
|
18
|
+
|
19
|
+
let(:parameters) do
|
20
|
+
{ format: format }.merge(extra_params)
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
documents_count.times { create(:document) }
|
25
|
+
|
26
|
+
allow(controller).to receive(:params)
|
27
|
+
.and_return(params)
|
28
|
+
|
29
|
+
allow(controller).to receive(:render)
|
30
|
+
.with(json: expected_json)
|
31
|
+
.and_return(expected_json)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns all documents json' do
|
35
|
+
expect(handler.process).to eq(expected_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'renders the json' do
|
39
|
+
handler.process
|
40
|
+
|
41
|
+
expect(controller).to have_received(:render)
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'with format html' do
|
45
|
+
let(:format) { 'html' }
|
46
|
+
|
47
|
+
it do
|
48
|
+
handler.process
|
49
|
+
|
50
|
+
expect(controller).not_to have_received(:render)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: azeroth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -403,8 +403,15 @@ files:
|
|
403
403
|
- lib/azeroth/decorator.rb
|
404
404
|
- lib/azeroth/model.rb
|
405
405
|
- lib/azeroth/options.rb
|
406
|
+
- lib/azeroth/request_handler.rb
|
407
|
+
- lib/azeroth/request_handler/create.rb
|
408
|
+
- lib/azeroth/request_handler/destroy.rb
|
409
|
+
- lib/azeroth/request_handler/edit.rb
|
410
|
+
- lib/azeroth/request_handler/index.rb
|
411
|
+
- lib/azeroth/request_handler/new.rb
|
412
|
+
- lib/azeroth/request_handler/show.rb
|
413
|
+
- lib/azeroth/request_handler/update.rb
|
406
414
|
- lib/azeroth/resource_builder.rb
|
407
|
-
- lib/azeroth/resource_route_builder.rb
|
408
415
|
- lib/azeroth/resourceable.rb
|
409
416
|
- lib/azeroth/resourceable/builder.rb
|
410
417
|
- lib/azeroth/resourceable/class_methods.rb
|
@@ -486,21 +493,28 @@ files:
|
|
486
493
|
- spec/integration/yard/azeroth/decorator_spec.rb
|
487
494
|
- spec/lib/azeroth/decorator_spec.rb
|
488
495
|
- spec/lib/azeroth/model_spec.rb
|
496
|
+
- spec/lib/azeroth/request_handler/create_spec.rb
|
497
|
+
- spec/lib/azeroth/request_handler/destroy_spec.rb
|
498
|
+
- spec/lib/azeroth/request_handler/edit_spec.rb
|
499
|
+
- spec/lib/azeroth/request_handler/index_spec.rb
|
500
|
+
- spec/lib/azeroth/request_handler/new_spec.rb
|
501
|
+
- spec/lib/azeroth/request_handler/show_spec.rb
|
502
|
+
- spec/lib/azeroth/request_handler/update_spec.rb
|
503
|
+
- spec/lib/azeroth/request_handler_spec.rb
|
489
504
|
- spec/lib/azeroth/resource_builder_spec.rb
|
490
|
-
- spec/lib/azeroth/resource_route_builder_spec.rb
|
491
505
|
- spec/lib/azeroth/resourceable/builder_spec.rb
|
492
506
|
- spec/lib/azeroth/routes_builder_spec.rb
|
493
507
|
- spec/spec_helper.rb
|
494
508
|
- spec/support/app/controllers/controller.rb
|
509
|
+
- spec/support/app/controllers/request_handler_controller.rb
|
495
510
|
- spec/support/app/controllers/resource_builder_controller.rb
|
496
511
|
- spec/support/app/controllers/resource_route_builder_controller.rb
|
497
|
-
- spec/support/app/controllers/routes_builder_controller.rb
|
498
512
|
- spec/support/factories/document.rb
|
499
513
|
- spec/support/factories/dummy_model.rb
|
500
514
|
- spec/support/factories/user.rb
|
501
515
|
- spec/support/factory_bot.rb
|
502
516
|
- spec/support/matchers/add_method.rb
|
503
|
-
- spec/support/shared_examples/
|
517
|
+
- spec/support/shared_examples/request_handler.rb
|
504
518
|
homepage: https://github.com/darthjee/azeroth
|
505
519
|
licenses: []
|
506
520
|
metadata: {}
|
@@ -601,18 +615,25 @@ test_files:
|
|
601
615
|
- spec/integration/yard/azeroth/decorator_spec.rb
|
602
616
|
- spec/lib/azeroth/decorator_spec.rb
|
603
617
|
- spec/lib/azeroth/model_spec.rb
|
618
|
+
- spec/lib/azeroth/request_handler/create_spec.rb
|
619
|
+
- spec/lib/azeroth/request_handler/destroy_spec.rb
|
620
|
+
- spec/lib/azeroth/request_handler/edit_spec.rb
|
621
|
+
- spec/lib/azeroth/request_handler/index_spec.rb
|
622
|
+
- spec/lib/azeroth/request_handler/new_spec.rb
|
623
|
+
- spec/lib/azeroth/request_handler/show_spec.rb
|
624
|
+
- spec/lib/azeroth/request_handler/update_spec.rb
|
625
|
+
- spec/lib/azeroth/request_handler_spec.rb
|
604
626
|
- spec/lib/azeroth/resource_builder_spec.rb
|
605
|
-
- spec/lib/azeroth/resource_route_builder_spec.rb
|
606
627
|
- spec/lib/azeroth/resourceable/builder_spec.rb
|
607
628
|
- spec/lib/azeroth/routes_builder_spec.rb
|
608
629
|
- spec/spec_helper.rb
|
609
630
|
- spec/support/app/controllers/controller.rb
|
631
|
+
- spec/support/app/controllers/request_handler_controller.rb
|
610
632
|
- spec/support/app/controllers/resource_builder_controller.rb
|
611
633
|
- spec/support/app/controllers/resource_route_builder_controller.rb
|
612
|
-
- spec/support/app/controllers/routes_builder_controller.rb
|
613
634
|
- spec/support/factories/document.rb
|
614
635
|
- spec/support/factories/dummy_model.rb
|
615
636
|
- spec/support/factories/user.rb
|
616
637
|
- spec/support/factory_bot.rb
|
617
638
|
- spec/support/matchers/add_method.rb
|
618
|
-
- spec/support/shared_examples/
|
639
|
+
- spec/support/shared_examples/request_handler.rb
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Azeroth
|
4
|
-
# @api private
|
5
|
-
# @author Darthjee
|
6
|
-
#
|
7
|
-
# Builder for resources for each route
|
8
|
-
#
|
9
|
-
# For each route method in the controller, there
|
10
|
-
# should be a resource, index should have listing
|
11
|
-
# of all entries, update should update and return
|
12
|
-
# updated resource, new should return an empty object,
|
13
|
-
# etc..
|
14
|
-
class ResourceRouteBuilder
|
15
|
-
# @param (see ResourceBuilder#initialize)
|
16
|
-
def initialize(model, builder)
|
17
|
-
@model = model
|
18
|
-
@builder = builder
|
19
|
-
end
|
20
|
-
|
21
|
-
# Append methods to be build to the builder
|
22
|
-
#
|
23
|
-
# The methods to be added are resources related
|
24
|
-
# to the routes:
|
25
|
-
# - new
|
26
|
-
# - show
|
27
|
-
# - create
|
28
|
-
# - update
|
29
|
-
# - edit
|
30
|
-
# - index
|
31
|
-
#
|
32
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
33
|
-
def append
|
34
|
-
add_new_reource
|
35
|
-
add_create_resource
|
36
|
-
add_update_resource
|
37
|
-
|
38
|
-
add_method(:index_resource, model.plural)
|
39
|
-
add_method(:edit_resource, name)
|
40
|
-
add_method(:show_resource, name)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
attr_reader :model, :builder
|
46
|
-
# @method model
|
47
|
-
# @api private
|
48
|
-
# @private
|
49
|
-
#
|
50
|
-
# Returns the model class of the resource
|
51
|
-
#
|
52
|
-
# @return [Model]
|
53
|
-
|
54
|
-
# @method builder
|
55
|
-
# @api private
|
56
|
-
# @private
|
57
|
-
#
|
58
|
-
# Returns a method builder
|
59
|
-
#
|
60
|
-
# @return [Sinclair]
|
61
|
-
#
|
62
|
-
# @see https://www.rubydoc.info/gems/sinclair Sinclair
|
63
|
-
|
64
|
-
delegate :add_method, to: :builder
|
65
|
-
# @api private
|
66
|
-
# @method add_method
|
67
|
-
#
|
68
|
-
# Add a method to be build on the controller
|
69
|
-
#
|
70
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
71
|
-
|
72
|
-
delegate :name, :klass, to: :model
|
73
|
-
# @method name
|
74
|
-
# @api private
|
75
|
-
#
|
76
|
-
# Returns the name of the resource represented by the model
|
77
|
-
#
|
78
|
-
# @return [String]
|
79
|
-
|
80
|
-
# @method klass
|
81
|
-
# @api private
|
82
|
-
#
|
83
|
-
# Resource class (real model class)
|
84
|
-
#
|
85
|
-
# @return [Class]
|
86
|
-
|
87
|
-
# Adds the reource for new route
|
88
|
-
#
|
89
|
-
# It returns a new empty object
|
90
|
-
#
|
91
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
92
|
-
def add_new_reource
|
93
|
-
add_method(:new_resource, "@new_resource ||= #{klass}.new")
|
94
|
-
end
|
95
|
-
|
96
|
-
# Adds the reource for create route
|
97
|
-
#
|
98
|
-
# It creates an entry in the database from the parameters
|
99
|
-
#
|
100
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
101
|
-
def add_create_resource
|
102
|
-
add_method(
|
103
|
-
:create_resource,
|
104
|
-
"@create_resource ||= #{klass}.create(#{name}_params)"
|
105
|
-
)
|
106
|
-
end
|
107
|
-
|
108
|
-
# Adds the reource for update route
|
109
|
-
#
|
110
|
-
# It updates an entry in the database from the parameters
|
111
|
-
#
|
112
|
-
# @return [Array<Sinclair::MethodDefinition>]
|
113
|
-
def add_update_resource
|
114
|
-
add_method(
|
115
|
-
:update_resource,
|
116
|
-
<<-CODE
|
117
|
-
@update_resource ||= #{name}.tap do |value|
|
118
|
-
value.update(#{name}_params)
|
119
|
-
end
|
120
|
-
CODE
|
121
|
-
)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Azeroth::ResourceRouteBuilder do
|
6
|
-
subject(:resource_routes_builder) do
|
7
|
-
described_class.new(model, builder)
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:model) { Azeroth::Model.new(:document) }
|
11
|
-
let(:builder) { Sinclair.new(klass) }
|
12
|
-
let(:klass) { Class.new(ResourceRouteBuilderController) }
|
13
|
-
|
14
|
-
before do
|
15
|
-
resource_routes_builder.append
|
16
|
-
10.times { Document.create }
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#append' do
|
20
|
-
it_behaves_like 'a route resource build'
|
21
|
-
end
|
22
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class RoutesBuilderController
|
4
|
-
def initialize(id: nil, document: nil)
|
5
|
-
@id = id
|
6
|
-
@document_params = document
|
7
|
-
end
|
8
|
-
|
9
|
-
def perform(action)
|
10
|
-
@action = action
|
11
|
-
send(action)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
attr_reader :id, :document_params, :action
|
17
|
-
|
18
|
-
def render_basic
|
19
|
-
{
|
20
|
-
json: "#{action}_json"
|
21
|
-
}
|
22
|
-
end
|
23
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
shared_examples 'a builder that adds a resource for route' do |route|
|
4
|
-
let(:params) { {} }
|
5
|
-
let(:instance) { klass.new(params) }
|
6
|
-
let(:value) { instance.public_send("#{route}_resource") }
|
7
|
-
|
8
|
-
it "adds #{route}_resource" do
|
9
|
-
expect { builder.build }
|
10
|
-
.to change { klass.new.respond_to?(:"#{route}_resource") }
|
11
|
-
.from(false).to(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
it "#{route}_resource responds with correct resource" do
|
15
|
-
builder.build
|
16
|
-
expect(value.to_json).to eq(expected.to_json)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
shared_examples 'a route resource build' do
|
21
|
-
let(:name) { 'The Doc' }
|
22
|
-
let(:document_params) { { name: name } }
|
23
|
-
|
24
|
-
describe 'index_resource' do
|
25
|
-
it_behaves_like 'a builder that adds a resource for route', :index do
|
26
|
-
let(:expected) { Document.all }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe 'new_resource' do
|
31
|
-
it_behaves_like 'a builder that adds a resource for route', :new do
|
32
|
-
let(:expected) { Document.new }
|
33
|
-
|
34
|
-
it 'does not create the resource' do
|
35
|
-
builder.build
|
36
|
-
expect do
|
37
|
-
instance.new_resource
|
38
|
-
end.not_to change(Document, :count)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'create_resource' do
|
44
|
-
it_behaves_like 'a builder that adds a resource for route', :create do
|
45
|
-
let(:expected) { Document.last }
|
46
|
-
let(:params) { { document: document_params } }
|
47
|
-
|
48
|
-
it 'creates the resource' do
|
49
|
-
builder.build
|
50
|
-
expect do
|
51
|
-
instance.create_resource
|
52
|
-
end.to change(Document, :count).by(1)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe 'show_resource' do
|
58
|
-
let(:document) { Document.create }
|
59
|
-
|
60
|
-
it_behaves_like 'a builder that adds a resource for route', :show do
|
61
|
-
let(:expected) { document }
|
62
|
-
let(:params) { { id: document.id } }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe 'update_resource' do
|
67
|
-
let!(:document) { Document.create }
|
68
|
-
|
69
|
-
it_behaves_like 'a builder that adds a resource for route', :update do
|
70
|
-
let(:expected) { Document.find(document.id) }
|
71
|
-
let(:params) { { id: document.id, document: document_params } }
|
72
|
-
|
73
|
-
describe 'after the methods has been built' do
|
74
|
-
before { builder.build }
|
75
|
-
|
76
|
-
it 'updates the resource the resource' do
|
77
|
-
expect do
|
78
|
-
instance.update_resource
|
79
|
-
end.to change { document.reload.name }.to(name)
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'does not create the resource' do
|
83
|
-
expect do
|
84
|
-
instance.update_resource
|
85
|
-
end.not_to change(Document, :count)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|