azeroth 0.0.5 → 0.0.6
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/.gitignore +3 -0
- data/README.md +1 -1
- data/azeroth.gemspec +22 -19
- data/bin/test +7 -0
- data/config/check_specs.yml +1 -0
- data/config/yardstick.yml +1 -1
- data/lib/azeroth.rb +5 -0
- data/lib/azeroth/resourceable.rb +20 -5
- data/lib/azeroth/resourceable/class_methods.rb +21 -0
- data/lib/azeroth/routes_builder.rb +16 -1
- data/lib/azeroth/version.rb +1 -1
- data/spec/controllers/documents_controller_spec.rb +256 -0
- data/spec/dummy/.ruby-version +1 -0
- data/spec/dummy/Rakefile +9 -0
- data/spec/dummy/app/assets/config/manifest.js +3 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/documents_controller.rb +7 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/jobs/application_job.rb +4 -0
- data/spec/dummy/app/mailers/application_mailer.rb +6 -0
- data/spec/dummy/app/models/application_record.rb +5 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/{support → dummy}/app/models/document.rb +0 -0
- data/spec/dummy/app/views/documents/edit.html +1 -0
- data/spec/dummy/app/views/documents/index.html +1 -0
- data/spec/dummy/app/views/documents/new.html +1 -0
- data/spec/dummy/app/views/documents/show.html +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +40 -0
- data/spec/dummy/bin/update +35 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config.ru +7 -0
- data/spec/dummy/config/application.rb +34 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +65 -0
- data/spec/dummy/config/environments/production.rb +108 -0
- data/spec/dummy/config/environments/test.rb +49 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
- data/spec/dummy/config/initializers/assets.rb +16 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +13 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +18 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +17 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +37 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/{support → dummy/db}/schema.rb +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/spec_helper.rb +9 -1
- metadata +186 -9
- data/spec/support/app/serializers/serializer.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 670fc994395afb0d20d4a113976c2b813d151ca6cad00d928e145d904294bcbc
|
4
|
+
data.tar.gz: 8c6f020d5e79b0dfc1559672a57d24468e883ec750e6503032e289deed19328b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caf235cb34805e990b810e396859b42a6937eaa14f54cfff32cfa34867e716b180f0634a00e81042b56e0ce3b0851c08d5e3927b16da3c4138f3134703536e81
|
7
|
+
data.tar.gz: 2adb8cf2c8751e7c3e6cb7dcda4591285565d4b1e6deee999cbbeb6f941127e4b3c3b454fbf65e38c40ae9caa1de02d1562ff77b3ec9e6d4752c1b9f58dbf426
|
data/.gitignore
CHANGED
data/README.md
CHANGED
data/azeroth.gemspec
CHANGED
@@ -22,23 +22,26 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.add_runtime_dependency 'darthjee-active_ext', '>= 1.3.2'
|
23
23
|
gem.add_runtime_dependency 'sinclair', '>= 1.5.2'
|
24
24
|
|
25
|
-
gem.add_development_dependency 'actionpack',
|
26
|
-
gem.add_development_dependency 'activerecord',
|
27
|
-
gem.add_development_dependency 'bundler',
|
28
|
-
gem.add_development_dependency 'pry',
|
29
|
-
gem.add_development_dependency 'pry-nav',
|
30
|
-
gem.add_development_dependency '
|
31
|
-
gem.add_development_dependency '
|
32
|
-
gem.add_development_dependency '
|
33
|
-
gem.add_development_dependency '
|
34
|
-
gem.add_development_dependency 'rspec
|
35
|
-
gem.add_development_dependency 'rspec-
|
36
|
-
gem.add_development_dependency 'rspec-
|
37
|
-
gem.add_development_dependency '
|
38
|
-
gem.add_development_dependency '
|
39
|
-
gem.add_development_dependency '
|
40
|
-
gem.add_development_dependency '
|
41
|
-
gem.add_development_dependency '
|
42
|
-
gem.add_development_dependency '
|
43
|
-
gem.add_development_dependency '
|
25
|
+
gem.add_development_dependency 'actionpack', '~> 5.x'
|
26
|
+
gem.add_development_dependency 'activerecord', '~> 5.x'
|
27
|
+
gem.add_development_dependency 'bundler', '~> 1.16.1'
|
28
|
+
gem.add_development_dependency 'pry', '0.12.2'
|
29
|
+
gem.add_development_dependency 'pry-nav', '0.3.0'
|
30
|
+
gem.add_development_dependency 'rails', '>= 5.2.0'
|
31
|
+
gem.add_development_dependency 'rails-controller-testing', '1.0.4'
|
32
|
+
gem.add_development_dependency 'rake', '12.3.3'
|
33
|
+
gem.add_development_dependency 'reek', '5.4.0'
|
34
|
+
gem.add_development_dependency 'rspec', '3.8.0'
|
35
|
+
gem.add_development_dependency 'rspec-core', '3.8.0'
|
36
|
+
gem.add_development_dependency 'rspec-expectations', '3.8.3'
|
37
|
+
gem.add_development_dependency 'rspec-mocks', '3.8.0'
|
38
|
+
gem.add_development_dependency 'rspec-rails', '3.8.0'
|
39
|
+
gem.add_development_dependency 'rspec-support', '3.8.0'
|
40
|
+
gem.add_development_dependency 'rubocop', '0.73.0'
|
41
|
+
gem.add_development_dependency 'rubocop-rspec', '1.33.0'
|
42
|
+
gem.add_development_dependency 'rubycritic', '4.1.0'
|
43
|
+
gem.add_development_dependency 'simplecov', '0.17.0'
|
44
|
+
gem.add_development_dependency 'sqlite3', '>= 1.3.13'
|
45
|
+
gem.add_development_dependency 'yard', '0.9.20'
|
46
|
+
gem.add_development_dependency 'yardstick', '0.9.9'
|
44
47
|
end
|
data/bin/test
ADDED
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
data/lib/azeroth.rb
CHANGED
data/lib/azeroth/resourceable.rb
CHANGED
@@ -3,17 +3,32 @@
|
|
3
3
|
require 'active_support'
|
4
4
|
|
5
5
|
module Azeroth
|
6
|
+
# @api public
|
7
|
+
# @author Darthjee
|
8
|
+
#
|
9
|
+
# Concern for building controller methods for the routes
|
6
10
|
module Resourceable
|
7
11
|
extend ActiveSupport::Concern
|
8
12
|
|
13
|
+
included do
|
14
|
+
rescue_from ActiveRecord::RecordNotFound, with: :not_found
|
15
|
+
end
|
16
|
+
|
9
17
|
autoload :Builder, 'azeroth/resourceable/builder'
|
18
|
+
autoload :ClassMethods, 'azeroth/resourceable/class_methods'
|
19
|
+
|
20
|
+
private
|
10
21
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
def render_basic
|
23
|
+
action = params[:action]
|
24
|
+
respond_to do |format|
|
25
|
+
format.json { render json: send("#{action}_resource") }
|
26
|
+
format.html { action }
|
16
27
|
end
|
17
28
|
end
|
29
|
+
|
30
|
+
def not_found
|
31
|
+
head :not_found
|
32
|
+
end
|
18
33
|
end
|
19
34
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Azeroth
|
4
|
+
module Resourceable
|
5
|
+
# @api public
|
6
|
+
# @author Darthjee
|
7
|
+
#
|
8
|
+
# Class methods added by {Resourceable}
|
9
|
+
module ClassMethods
|
10
|
+
# Adds resource methods for resource
|
11
|
+
#
|
12
|
+
# @param name [String, Symbol] Name of the resource
|
13
|
+
# @param options [Hash]
|
14
|
+
def resource_for(name, **options)
|
15
|
+
Builder.new(
|
16
|
+
self, name, Azeroth::Options.new(options)
|
17
|
+
).build
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -19,10 +19,13 @@ module Azeroth
|
|
19
19
|
#
|
20
20
|
# @return [Array<Sinclair::MethodDefinition>]
|
21
21
|
def append
|
22
|
-
%i[index show
|
22
|
+
%i[index show edit].each do |route|
|
23
23
|
add_method(route, 'render_basic')
|
24
24
|
end
|
25
25
|
|
26
|
+
add_method(:new, '')
|
27
|
+
add_method(:update, update_code)
|
28
|
+
add_method(:create, create_code)
|
26
29
|
add_method(:destroy, destroy_code)
|
27
30
|
end
|
28
31
|
|
@@ -54,6 +57,18 @@ module Azeroth
|
|
54
57
|
#
|
55
58
|
# @return [Array<Sinclair::MethodDefinition>]
|
56
59
|
|
60
|
+
def update_code
|
61
|
+
<<-RUBY
|
62
|
+
render json: update_resource
|
63
|
+
RUBY
|
64
|
+
end
|
65
|
+
|
66
|
+
def create_code
|
67
|
+
<<-RUBY
|
68
|
+
render json: create_resource
|
69
|
+
RUBY
|
70
|
+
end
|
71
|
+
|
57
72
|
# @private
|
58
73
|
#
|
59
74
|
# Method code to destrou route
|
data/lib/azeroth/version.rb
CHANGED
@@ -0,0 +1,256 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DocumentsController 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
|
+
let!(:documents) do
|
13
|
+
documents_count.times.map do
|
14
|
+
Document.create
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'when calling on format json' do
|
19
|
+
before do
|
20
|
+
get :index, params: { format: :json }
|
21
|
+
end
|
22
|
+
|
23
|
+
it { expect(response).to be_successful }
|
24
|
+
|
25
|
+
it 'returns empty array' do
|
26
|
+
expect(parsed_response).to eq([])
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when there is a document' do
|
30
|
+
let(:documents_count) { 1 }
|
31
|
+
|
32
|
+
it { expect(response).to be_successful }
|
33
|
+
|
34
|
+
it 'renders documents json' do
|
35
|
+
expect(parsed_response).to eq(documents.as_json)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when calling on format html' do
|
41
|
+
before do
|
42
|
+
get :index, params: { format: :html }
|
43
|
+
end
|
44
|
+
|
45
|
+
it { expect(response).to be_successful }
|
46
|
+
|
47
|
+
it { expect(response).to render_template('documents/index') }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'GET show' do
|
52
|
+
let(:document) { Document.create }
|
53
|
+
let(:document_id) { document.id }
|
54
|
+
|
55
|
+
context 'when calling on format json' do
|
56
|
+
before do
|
57
|
+
get :show, params: { id: document_id, format: :json }
|
58
|
+
end
|
59
|
+
|
60
|
+
it { expect(response).to be_successful }
|
61
|
+
|
62
|
+
it 'returns document json' do
|
63
|
+
expect(parsed_response).to eq(document.as_json)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when calling on an inexistent id' do
|
68
|
+
let(:document_id) { :wrong_id }
|
69
|
+
|
70
|
+
before do
|
71
|
+
get :show, params: { id: document_id, format: :json }
|
72
|
+
end
|
73
|
+
|
74
|
+
it { expect(response).not_to be_successful }
|
75
|
+
it { expect(response.status).to eq(404) }
|
76
|
+
|
77
|
+
it 'returns empty body' do
|
78
|
+
expect(response.body).to eq('')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'when calling on format html' do
|
83
|
+
before do
|
84
|
+
get :show, params: { id: :id, format: :html }
|
85
|
+
end
|
86
|
+
|
87
|
+
it { expect(response).to be_successful }
|
88
|
+
|
89
|
+
it { expect(response).to render_template('documents/show') }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'POST create' do
|
94
|
+
let(:parameters) do
|
95
|
+
{
|
96
|
+
document: {
|
97
|
+
name: 'My document'
|
98
|
+
}
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
it do
|
103
|
+
post :create, params: parameters
|
104
|
+
expect(response).to be_successful
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'returns created document json' do
|
108
|
+
post :create, params: parameters
|
109
|
+
expect(parsed_response).to eq(Document.last.as_json)
|
110
|
+
end
|
111
|
+
|
112
|
+
it do
|
113
|
+
expect { post :create, params: parameters }
|
114
|
+
.to change(Document, :count).by(1)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe 'PATCH update' do
|
119
|
+
let(:document) { Document.create }
|
120
|
+
let(:document_id) { document.id }
|
121
|
+
|
122
|
+
let(:parameters) do
|
123
|
+
{
|
124
|
+
id: document_id,
|
125
|
+
document: {
|
126
|
+
name: 'My document'
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
it do
|
132
|
+
patch :update, params: parameters
|
133
|
+
expect(response).to be_successful
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'returns updated document json' do
|
137
|
+
patch :update, params: parameters
|
138
|
+
expect(parsed_response).to eq(Document.last.as_json)
|
139
|
+
end
|
140
|
+
|
141
|
+
it do
|
142
|
+
expect { patch :update, params: parameters }
|
143
|
+
.to change { document.reload.name }
|
144
|
+
.from(nil).to('My document')
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when calling on an inexistent id' do
|
148
|
+
let(:document_id) { :wrong_id }
|
149
|
+
|
150
|
+
before do
|
151
|
+
patch :update, params: parameters
|
152
|
+
end
|
153
|
+
|
154
|
+
it { expect(response).not_to be_successful }
|
155
|
+
it { expect(response.status).to eq(404) }
|
156
|
+
|
157
|
+
it 'returns empty body' do
|
158
|
+
expect(response.body).to eq('')
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe 'GET new' do
|
164
|
+
before { get :new }
|
165
|
+
|
166
|
+
it do
|
167
|
+
expect(response).to be_successful
|
168
|
+
end
|
169
|
+
|
170
|
+
it { expect(response).to render_template('documents/new') }
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'GET edit' do
|
174
|
+
let(:document) { Document.create }
|
175
|
+
let(:document_id) { document.id }
|
176
|
+
|
177
|
+
context 'when calling on format json' do
|
178
|
+
before do
|
179
|
+
get :edit, params: { id: document_id, format: :json }
|
180
|
+
end
|
181
|
+
|
182
|
+
it { expect(response).to be_successful }
|
183
|
+
|
184
|
+
it 'returns document json' do
|
185
|
+
expect(parsed_response).to eq(document.as_json)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context 'when calling on an inexistent id' do
|
190
|
+
let(:document_id) { :wrong_id }
|
191
|
+
|
192
|
+
before do
|
193
|
+
get :edit, params: { id: document_id, format: :json }
|
194
|
+
end
|
195
|
+
|
196
|
+
it { expect(response).not_to be_successful }
|
197
|
+
it { expect(response.status).to eq(404) }
|
198
|
+
|
199
|
+
it 'returns empty body' do
|
200
|
+
expect(response.body).to eq('')
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'when calling on format html' do
|
205
|
+
before do
|
206
|
+
get :edit, params: { id: :id, format: :html }
|
207
|
+
end
|
208
|
+
|
209
|
+
it { expect(response).to be_successful }
|
210
|
+
|
211
|
+
it { expect(response).to render_template('documents/edit') }
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe 'DELETE destroy' do
|
216
|
+
let!(:document) { Document.create }
|
217
|
+
let(:document_id) { document.id }
|
218
|
+
|
219
|
+
let(:parameters) do
|
220
|
+
{
|
221
|
+
id: document_id
|
222
|
+
}
|
223
|
+
end
|
224
|
+
|
225
|
+
it do
|
226
|
+
delete :destroy, params: parameters
|
227
|
+
expect(response).to be_successful
|
228
|
+
end
|
229
|
+
|
230
|
+
it do
|
231
|
+
delete :destroy, params: parameters
|
232
|
+
expect(response.body).to eq('')
|
233
|
+
end
|
234
|
+
|
235
|
+
it do
|
236
|
+
expect { delete :destroy, params: parameters }
|
237
|
+
.to change(Document, :count)
|
238
|
+
.by(-1)
|
239
|
+
end
|
240
|
+
|
241
|
+
context 'when calling on an inexistent id' do
|
242
|
+
let(:document_id) { :wrong_id }
|
243
|
+
|
244
|
+
before do
|
245
|
+
delete :destroy, params: parameters
|
246
|
+
end
|
247
|
+
|
248
|
+
it { expect(response).not_to be_successful }
|
249
|
+
it { expect(response.status).to eq(404) }
|
250
|
+
|
251
|
+
it 'returns empty body' do
|
252
|
+
expect(response.body).to eq('')
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|