azeroth 0.3.0 → 0.4.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 +4 -10
- data/README.md +1 -1
- data/azeroth.gemspec +13 -12
- data/config/check_specs.yml +1 -0
- data/config/yardstick.yml +2 -0
- data/lib/azeroth/exception.rb +46 -0
- data/lib/azeroth/options.rb +38 -1
- data/lib/azeroth/request_handler/create.rb +3 -0
- data/lib/azeroth/request_handler/update.rb +3 -0
- data/lib/azeroth/routes_builder.rb +10 -4
- data/lib/azeroth/version.rb +1 -1
- data/lib/azeroth.rb +1 -0
- data/spec/controllers/documents_controller_spec.rb +6 -10
- data/spec/controllers/index_documents_controller_spec.rb +160 -0
- data/spec/dummy/app/controllers/documents_controller.rb +1 -1
- data/spec/dummy/app/controllers/index_documents_controller.rb +7 -0
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/integration/yard/azeroth/exception/invalid_options_spec.rb +16 -0
- data/spec/lib/azeroth/exception/invalid_options_spec.rb +16 -0
- data/spec/lib/azeroth/options_spec.rb +61 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/factories/document.rb +1 -1
- data/spec/support/factories/dummy_model.rb +1 -1
- data/spec/support/factories/user.rb +1 -1
- metadata +51 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7b900f12e602cd5e71dcb0384e0d4edf783a699a9462dd644d849ec52af171f1
|
|
4
|
+
data.tar.gz: c9212340df4b356fb223874e340a3679111d0dd1d80b4e0293d7b3f7afebb790
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c884137cfce1ae2e0fac3a35817ecfecb62dc1093a7b95c5f77a8d9fffb426b0b7024028221789b6b560097bcae07a8012ef751edd3c9a08941a1ab6d4890e7d
|
|
7
|
+
data.tar.gz: 63ca6a97a61293b3551852ac2fab43ce0ab27fe9fafc37268c9c542f3c033ce5f6a8aac45d9c5ae0f220c9c6963dcaa169b8e9810841fe7cdf3751e1505631d6
|
data/.circleci/config.yml
CHANGED
data/Dockerfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
FROM darthjee/rails_gems:0.
|
|
2
|
-
FROM darthjee/scripts:0.1.
|
|
1
|
+
FROM darthjee/rails_gems:0.4.0 as base
|
|
2
|
+
FROM darthjee/scripts:0.1.7 as scripts
|
|
3
3
|
|
|
4
4
|
######################################
|
|
5
5
|
|
|
@@ -16,15 +16,9 @@ RUN bundle_builder.sh
|
|
|
16
16
|
FROM base
|
|
17
17
|
RUN mkdir lib/azeroth -p
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
COPY --chown=app:app --from=builder /home/app/bundle/gems /usr/local/bundle/gems
|
|
22
|
-
COPY --chown=app:app --from=builder /home/app/bundle/cache /usr/local/bundle/cache
|
|
23
|
-
COPY --chown=app:app --from=builder /home/app/bundle/specifications /usr/local/bundle/specifications
|
|
24
|
-
COPY --chown=app:app --from=builder /home/app/bundle/bin /usr/local/bundle/bin
|
|
25
|
-
COPY --chown=app:app --from=builder /home/app/bundle/extensions /usr/local/bundle/extensions
|
|
19
|
+
COPY --chown=app:app --from=builder /home/app/bundle/ /usr/local/bundle/
|
|
26
20
|
|
|
27
21
|
COPY --chown=app ./*.gemspec ./Gemfile /home/app/app/
|
|
28
22
|
COPY --chown=app ./lib/azeroth/version.rb /home/app/app/lib/azeroth/
|
|
29
|
-
|
|
23
|
+
|
|
30
24
|
RUN bundle install
|
data/README.md
CHANGED
data/azeroth.gemspec
CHANGED
|
@@ -26,23 +26,24 @@ Gem::Specification.new do |gem|
|
|
|
26
26
|
gem.add_development_dependency 'activerecord', '~> 5.x'
|
|
27
27
|
gem.add_development_dependency 'bundler', '~> 1.16.1'
|
|
28
28
|
gem.add_development_dependency 'factory_bot', '~> 5.1.1'
|
|
29
|
+
gem.add_development_dependency 'nokogiri', '1.10.9'
|
|
29
30
|
gem.add_development_dependency 'pry', '0.12.2'
|
|
30
31
|
gem.add_development_dependency 'pry-nav', '0.3.0'
|
|
31
32
|
gem.add_development_dependency 'rails', '>= 5.2.0'
|
|
32
33
|
gem.add_development_dependency 'rails-controller-testing', '1.0.4'
|
|
33
34
|
gem.add_development_dependency 'rake', '12.3.3'
|
|
34
|
-
gem.add_development_dependency 'reek', '5.
|
|
35
|
-
gem.add_development_dependency 'rspec', '3.
|
|
36
|
-
gem.add_development_dependency 'rspec-core', '3.
|
|
37
|
-
gem.add_development_dependency 'rspec-expectations', '3.
|
|
38
|
-
gem.add_development_dependency 'rspec-mocks', '3.
|
|
39
|
-
gem.add_development_dependency 'rspec-rails', '3.
|
|
40
|
-
gem.add_development_dependency 'rspec-support', '3.
|
|
41
|
-
gem.add_development_dependency 'rubocop', '0.
|
|
42
|
-
gem.add_development_dependency 'rubocop-rspec', '1.
|
|
43
|
-
gem.add_development_dependency 'rubycritic', '4.1
|
|
44
|
-
gem.add_development_dependency 'simplecov', '0.17.
|
|
35
|
+
gem.add_development_dependency 'reek', '5.6.0'
|
|
36
|
+
gem.add_development_dependency 'rspec', '3.9.0'
|
|
37
|
+
gem.add_development_dependency 'rspec-core', '3.9.1'
|
|
38
|
+
gem.add_development_dependency 'rspec-expectations', '3.9.0'
|
|
39
|
+
gem.add_development_dependency 'rspec-mocks', '3.9.1'
|
|
40
|
+
gem.add_development_dependency 'rspec-rails', '3.9.0'
|
|
41
|
+
gem.add_development_dependency 'rspec-support', '3.9.2'
|
|
42
|
+
gem.add_development_dependency 'rubocop', '0.80.1'
|
|
43
|
+
gem.add_development_dependency 'rubocop-rspec', '1.38.1'
|
|
44
|
+
gem.add_development_dependency 'rubycritic', '4.4.1'
|
|
45
|
+
gem.add_development_dependency 'simplecov', '0.17.1'
|
|
45
46
|
gem.add_development_dependency 'sqlite3', '>= 1.3.13'
|
|
46
|
-
gem.add_development_dependency 'yard', '0.9.
|
|
47
|
+
gem.add_development_dependency 'yard', '0.9.24'
|
|
47
48
|
gem.add_development_dependency 'yardstick', '0.9.9'
|
|
48
49
|
end
|
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
|
@@ -24,7 +24,9 @@ rules:
|
|
|
24
24
|
exclude:
|
|
25
25
|
- Azeroth::Decorator#initialize
|
|
26
26
|
- Azeroth::Decorator::HashBuilder#initialize
|
|
27
|
+
- Azeroth::Exception::InvalidOptions#initialize
|
|
27
28
|
- Azeroth::Model#initialize
|
|
29
|
+
- Azeroth::Options#initialize
|
|
28
30
|
- Azeroth::RequestHandler#initialize
|
|
29
31
|
- Azeroth::ResourceBuilder#initialize
|
|
30
32
|
- Azeroth::ResourceRouteBuilder#initialize
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Azeroth
|
|
4
|
+
# @api private
|
|
5
|
+
# @author Darthjee
|
|
6
|
+
#
|
|
7
|
+
# Excaptions raised by azeroth
|
|
8
|
+
class Exception < ::StandardError
|
|
9
|
+
# @api private
|
|
10
|
+
# @author Darthjee
|
|
11
|
+
#
|
|
12
|
+
# Exception raised when invalid options are given
|
|
13
|
+
#
|
|
14
|
+
# @example Usage
|
|
15
|
+
# exception = Azeroth::Exception::InvalidOptions.new(%i[invalid options])
|
|
16
|
+
# exception.message
|
|
17
|
+
# # return 'Invalid keys on options initialization (invalid options)'
|
|
18
|
+
class InvalidOptions < Azeroth::Exception
|
|
19
|
+
# @param invalid_keys [Array<Symbol>] list of invalid keys
|
|
20
|
+
def initialize(invalid_keys = [])
|
|
21
|
+
@invalid_keys = invalid_keys
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Exception string showing invalid keys
|
|
25
|
+
#
|
|
26
|
+
# @return [String]
|
|
27
|
+
#
|
|
28
|
+
# @example (see InvalidOptions)
|
|
29
|
+
def message
|
|
30
|
+
keys = invalid_keys.join(' ')
|
|
31
|
+
"Invalid keys on options initialization (#{keys})"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
attr_reader :invalid_keys
|
|
37
|
+
# @method invalid_keys
|
|
38
|
+
# @api private
|
|
39
|
+
# @private
|
|
40
|
+
#
|
|
41
|
+
# invalid keys on options initialization
|
|
42
|
+
#
|
|
43
|
+
# @return [Array<Symbol>]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/azeroth/options.rb
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Azeroth
|
|
4
|
+
# @api private
|
|
5
|
+
# @author Darthjee
|
|
6
|
+
#
|
|
7
|
+
# Resource buiilding options
|
|
4
8
|
class Options < ::OpenStruct
|
|
5
9
|
DEFAULT_OPTIONS = {
|
|
10
|
+
only: %i[create destroy edit index new show update],
|
|
11
|
+
except: []
|
|
6
12
|
}.freeze
|
|
7
13
|
|
|
8
|
-
|
|
14
|
+
# @param options [Hash] hash with options
|
|
15
|
+
# @option options only [Array<Symbol,String>] List of
|
|
16
|
+
# actions to be built
|
|
17
|
+
# @option options except [Array<Symbol,String>] List of
|
|
18
|
+
# actions to not to be built
|
|
19
|
+
def initialize(options = {})
|
|
20
|
+
check_options(options)
|
|
21
|
+
|
|
9
22
|
super(DEFAULT_OPTIONS.merge(options))
|
|
10
23
|
end
|
|
24
|
+
|
|
25
|
+
# Actions to be built
|
|
26
|
+
#
|
|
27
|
+
# @return [Array<Symbol>]
|
|
28
|
+
def actions
|
|
29
|
+
[only].flatten.map(&:to_sym) - [except].flatten.map(&:to_sym)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# @private
|
|
35
|
+
#
|
|
36
|
+
# check if given options are allowed
|
|
37
|
+
#
|
|
38
|
+
# @raise Azeroth::Exception::InvalidOptions
|
|
39
|
+
#
|
|
40
|
+
# @return [NilClass]
|
|
41
|
+
def check_options(options)
|
|
42
|
+
invalid_keys = options.keys - DEFAULT_OPTIONS.keys
|
|
43
|
+
|
|
44
|
+
return if invalid_keys.empty?
|
|
45
|
+
|
|
46
|
+
raise Azeroth::Exception::InvalidOptions, invalid_keys
|
|
47
|
+
end
|
|
11
48
|
end
|
|
12
49
|
end
|
|
@@ -19,16 +19,14 @@ module Azeroth
|
|
|
19
19
|
#
|
|
20
20
|
# @return [Array<Sinclair::MethodDefinition>]
|
|
21
21
|
def append
|
|
22
|
-
actions
|
|
23
|
-
|
|
24
|
-
actions.each do |route|
|
|
22
|
+
options.actions.each do |route|
|
|
25
23
|
add_method(route, &route_code(route))
|
|
26
24
|
end
|
|
27
25
|
end
|
|
28
26
|
|
|
29
27
|
private
|
|
30
28
|
|
|
31
|
-
attr_reader :model, :builder
|
|
29
|
+
attr_reader :model, :builder, :options
|
|
32
30
|
# @method model
|
|
33
31
|
# @api private
|
|
34
32
|
# @private
|
|
@@ -45,6 +43,14 @@ module Azeroth
|
|
|
45
43
|
#
|
|
46
44
|
# @return [Sinclair]
|
|
47
45
|
|
|
46
|
+
# @method options
|
|
47
|
+
# @api private
|
|
48
|
+
# @private
|
|
49
|
+
#
|
|
50
|
+
# Buiding options
|
|
51
|
+
#
|
|
52
|
+
# @return [Options]
|
|
53
|
+
|
|
48
54
|
delegate :add_method, to: :builder
|
|
49
55
|
# @method add_method
|
|
50
56
|
# @api private
|
data/lib/azeroth/version.rb
CHANGED
data/lib/azeroth.rb
CHANGED
|
@@ -11,6 +11,7 @@ require 'sinclair'
|
|
|
11
11
|
# @see Resourceable
|
|
12
12
|
module Azeroth
|
|
13
13
|
autoload :Decorator, 'azeroth/decorator'
|
|
14
|
+
autoload :Exception, 'azeroth/exception'
|
|
14
15
|
autoload :Model, 'azeroth/model'
|
|
15
16
|
autoload :RequestHandler, 'azeroth/request_handler'
|
|
16
17
|
autoload :Resourceable, 'azeroth/resourceable'
|
|
@@ -9,12 +9,9 @@ describe DocumentsController do
|
|
|
9
9
|
|
|
10
10
|
describe 'GET index' do
|
|
11
11
|
let(:documents_count) { 0 }
|
|
12
|
-
let!(:documents) do
|
|
13
|
-
documents_count.times.map { create(:document) }
|
|
14
|
-
end
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
before do
|
|
14
|
+
documents_count.times.map { create(:document) }
|
|
18
15
|
end
|
|
19
16
|
|
|
20
17
|
context 'when calling on format json' do
|
|
@@ -24,8 +21,8 @@ describe DocumentsController do
|
|
|
24
21
|
|
|
25
22
|
it { expect(response).to be_successful }
|
|
26
23
|
|
|
27
|
-
it 'returns empty
|
|
28
|
-
expect(
|
|
24
|
+
it 'returns empty text' do
|
|
25
|
+
expect(response.body).to eq('')
|
|
29
26
|
end
|
|
30
27
|
|
|
31
28
|
context 'when there is a document' do
|
|
@@ -33,8 +30,8 @@ describe DocumentsController do
|
|
|
33
30
|
|
|
34
31
|
it { expect(response).to be_successful }
|
|
35
32
|
|
|
36
|
-
it '
|
|
37
|
-
expect(
|
|
33
|
+
it 'returns empty text' do
|
|
34
|
+
expect(response.body).to eq('')
|
|
38
35
|
end
|
|
39
36
|
end
|
|
40
37
|
end
|
|
@@ -53,7 +50,6 @@ describe DocumentsController do
|
|
|
53
50
|
describe 'GET show' do
|
|
54
51
|
let(:document) { create(:document) }
|
|
55
52
|
let(:document_id) { document.id }
|
|
56
|
-
|
|
57
53
|
let(:expected_json) do
|
|
58
54
|
Document::Decorator.new(document).as_json
|
|
59
55
|
end
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe IndexDocumentsController 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 { create(:document) }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:expected_json) do
|
|
17
|
+
Document::Decorator.new(documents).as_json
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
context 'when calling on format json' do
|
|
21
|
+
before do
|
|
22
|
+
get :index, params: { format: :json }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it { expect(response).to be_successful }
|
|
26
|
+
|
|
27
|
+
it 'returns empty array' do
|
|
28
|
+
expect(parsed_response).to eq(expected_json)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'when there is a document' do
|
|
32
|
+
let(:documents_count) { 1 }
|
|
33
|
+
|
|
34
|
+
it { expect(response).to be_successful }
|
|
35
|
+
|
|
36
|
+
it 'renders documents json' do
|
|
37
|
+
expect(parsed_response).to eq(expected_json)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
describe 'GET show' do
|
|
44
|
+
let(:document) { create(:document) }
|
|
45
|
+
let(:document_id) { document.id }
|
|
46
|
+
|
|
47
|
+
context 'when calling on format json' do
|
|
48
|
+
let(:parameters) { { id: document_id, format: :json } }
|
|
49
|
+
|
|
50
|
+
it do
|
|
51
|
+
expect { get :show, params: parameters }
|
|
52
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'when calling on an inexistent id' do
|
|
56
|
+
let(:document_id) { :wrong_id }
|
|
57
|
+
|
|
58
|
+
it do
|
|
59
|
+
expect { get :show, params: parameters }
|
|
60
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context 'when calling on format html' do
|
|
66
|
+
let(:parameters) { { id: document_id, format: :html } }
|
|
67
|
+
|
|
68
|
+
it do
|
|
69
|
+
expect { get :show, params: parameters }
|
|
70
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe 'POST create' do
|
|
76
|
+
let(:payload) do
|
|
77
|
+
{
|
|
78
|
+
name: 'My document'
|
|
79
|
+
}
|
|
80
|
+
end
|
|
81
|
+
let(:parameters) do
|
|
82
|
+
{
|
|
83
|
+
format: format,
|
|
84
|
+
document: payload
|
|
85
|
+
}
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
context 'when requesting format json' do
|
|
89
|
+
let(:format) { :json }
|
|
90
|
+
|
|
91
|
+
it do
|
|
92
|
+
expect { get :create, params: parameters }
|
|
93
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe 'PATCH update' do
|
|
99
|
+
let(:document) { create(:document) }
|
|
100
|
+
let(:document_id) { document.id }
|
|
101
|
+
|
|
102
|
+
let(:payload) do
|
|
103
|
+
{
|
|
104
|
+
name: 'My document'
|
|
105
|
+
}
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
let(:parameters) do
|
|
109
|
+
{
|
|
110
|
+
id: document_id,
|
|
111
|
+
format: :json,
|
|
112
|
+
document: payload
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it do
|
|
117
|
+
expect { get :update, params: parameters }
|
|
118
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe 'GET new' do
|
|
123
|
+
context 'when calling with format json' do
|
|
124
|
+
it do
|
|
125
|
+
expect { get :new, params: { format: :json } }
|
|
126
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
context 'when calling with format html' do
|
|
131
|
+
it do
|
|
132
|
+
expect { get :new, params: { format: :html } }
|
|
133
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
describe 'GET edit' do
|
|
139
|
+
let(:document) { create(:document) }
|
|
140
|
+
let(:document_id) { document.id }
|
|
141
|
+
|
|
142
|
+
context 'when calling on format json' do
|
|
143
|
+
let(:parameters) { { id: document_id, format: :json } }
|
|
144
|
+
|
|
145
|
+
it do
|
|
146
|
+
expect { get :edit, params: parameters }
|
|
147
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
context 'when calling on format html' do
|
|
152
|
+
let(:parameters) { { id: document_id, format: :html } }
|
|
153
|
+
|
|
154
|
+
it do
|
|
155
|
+
expect { get :edit, params: parameters }
|
|
156
|
+
.to raise_error(AbstractController::ActionNotFound)
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
data/spec/dummy/config/routes.rb
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Azeroth::Exception::InvalidOptions do
|
|
6
|
+
describe '#message' do
|
|
7
|
+
let(:exception) { described_class.new(%i[invalid options]) }
|
|
8
|
+
let(:expected_message) do
|
|
9
|
+
'Invalid keys on options initialization (invalid options)'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'shows invalid keys' do
|
|
13
|
+
expect(exception.message).to eq(expected_message)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Azeroth::Exception::InvalidOptions do
|
|
6
|
+
describe '#message' do
|
|
7
|
+
let(:exception) { described_class.new(%i[invalid options]) }
|
|
8
|
+
let(:expected_message) do
|
|
9
|
+
'Invalid keys on options initialization (invalid options)'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'shows invalid keys' do
|
|
13
|
+
expect(exception.message).to eq(expected_message)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Azeroth::Options do
|
|
6
|
+
subject(:options) { described_class.new }
|
|
7
|
+
|
|
8
|
+
describe 'validation' do
|
|
9
|
+
context 'when initializing with invalid options' do
|
|
10
|
+
it do
|
|
11
|
+
expect { described_class.new(invalid_option: 1) }
|
|
12
|
+
.to raise_error(Azeroth::Exception::InvalidOptions)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe '#actions' do
|
|
18
|
+
it 'returns default actions' do
|
|
19
|
+
expect(options.actions)
|
|
20
|
+
.to eq(%i[create destroy edit index new show update])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context 'when passing only options' do
|
|
24
|
+
subject(:options) { described_class.new(only: [:index]) }
|
|
25
|
+
|
|
26
|
+
it 'returns defined actions' do
|
|
27
|
+
expect(options.actions)
|
|
28
|
+
.to eq(%i[index])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'when not passing an array' do
|
|
32
|
+
subject(:options) { described_class.new(only: :index) }
|
|
33
|
+
|
|
34
|
+
it 'returns defined actions as array' do
|
|
35
|
+
expect(options.actions)
|
|
36
|
+
.to eq(%i[index])
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'when passing except options' do
|
|
42
|
+
subject(:options) do
|
|
43
|
+
described_class.new(except: %i[index create])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'returns not excluded actions' do
|
|
47
|
+
expect(options.actions)
|
|
48
|
+
.to eq(%i[destroy edit new show update])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context 'when not passing an array' do
|
|
52
|
+
subject(:options) { described_class.new(except: :index) }
|
|
53
|
+
|
|
54
|
+
it 'returns not excluded actions' do
|
|
55
|
+
expect(options.actions)
|
|
56
|
+
.to eq(%i[create destroy edit new show update])
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -19,7 +19,7 @@ require 'rspec/rails'
|
|
|
19
19
|
require 'active_support/railtie'
|
|
20
20
|
|
|
21
21
|
support_files = File.expand_path('spec/support/**/*.rb')
|
|
22
|
-
Dir[support_files].each { |file| require file }
|
|
22
|
+
Dir[support_files].sort.each { |file| require file }
|
|
23
23
|
|
|
24
24
|
RSpec.configure do |config|
|
|
25
25
|
config.infer_spec_type_from_file_location!
|
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.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Darthjee
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -108,6 +108,20 @@ dependencies:
|
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: 5.1.1
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: nokogiri
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - '='
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 1.10.9
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - '='
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 1.10.9
|
|
111
125
|
- !ruby/object:Gem::Dependency
|
|
112
126
|
name: pry
|
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -184,154 +198,154 @@ dependencies:
|
|
|
184
198
|
requirements:
|
|
185
199
|
- - '='
|
|
186
200
|
- !ruby/object:Gem::Version
|
|
187
|
-
version: 5.
|
|
201
|
+
version: 5.6.0
|
|
188
202
|
type: :development
|
|
189
203
|
prerelease: false
|
|
190
204
|
version_requirements: !ruby/object:Gem::Requirement
|
|
191
205
|
requirements:
|
|
192
206
|
- - '='
|
|
193
207
|
- !ruby/object:Gem::Version
|
|
194
|
-
version: 5.
|
|
208
|
+
version: 5.6.0
|
|
195
209
|
- !ruby/object:Gem::Dependency
|
|
196
210
|
name: rspec
|
|
197
211
|
requirement: !ruby/object:Gem::Requirement
|
|
198
212
|
requirements:
|
|
199
213
|
- - '='
|
|
200
214
|
- !ruby/object:Gem::Version
|
|
201
|
-
version: 3.
|
|
215
|
+
version: 3.9.0
|
|
202
216
|
type: :development
|
|
203
217
|
prerelease: false
|
|
204
218
|
version_requirements: !ruby/object:Gem::Requirement
|
|
205
219
|
requirements:
|
|
206
220
|
- - '='
|
|
207
221
|
- !ruby/object:Gem::Version
|
|
208
|
-
version: 3.
|
|
222
|
+
version: 3.9.0
|
|
209
223
|
- !ruby/object:Gem::Dependency
|
|
210
224
|
name: rspec-core
|
|
211
225
|
requirement: !ruby/object:Gem::Requirement
|
|
212
226
|
requirements:
|
|
213
227
|
- - '='
|
|
214
228
|
- !ruby/object:Gem::Version
|
|
215
|
-
version: 3.
|
|
229
|
+
version: 3.9.1
|
|
216
230
|
type: :development
|
|
217
231
|
prerelease: false
|
|
218
232
|
version_requirements: !ruby/object:Gem::Requirement
|
|
219
233
|
requirements:
|
|
220
234
|
- - '='
|
|
221
235
|
- !ruby/object:Gem::Version
|
|
222
|
-
version: 3.
|
|
236
|
+
version: 3.9.1
|
|
223
237
|
- !ruby/object:Gem::Dependency
|
|
224
238
|
name: rspec-expectations
|
|
225
239
|
requirement: !ruby/object:Gem::Requirement
|
|
226
240
|
requirements:
|
|
227
241
|
- - '='
|
|
228
242
|
- !ruby/object:Gem::Version
|
|
229
|
-
version: 3.
|
|
243
|
+
version: 3.9.0
|
|
230
244
|
type: :development
|
|
231
245
|
prerelease: false
|
|
232
246
|
version_requirements: !ruby/object:Gem::Requirement
|
|
233
247
|
requirements:
|
|
234
248
|
- - '='
|
|
235
249
|
- !ruby/object:Gem::Version
|
|
236
|
-
version: 3.
|
|
250
|
+
version: 3.9.0
|
|
237
251
|
- !ruby/object:Gem::Dependency
|
|
238
252
|
name: rspec-mocks
|
|
239
253
|
requirement: !ruby/object:Gem::Requirement
|
|
240
254
|
requirements:
|
|
241
255
|
- - '='
|
|
242
256
|
- !ruby/object:Gem::Version
|
|
243
|
-
version: 3.
|
|
257
|
+
version: 3.9.1
|
|
244
258
|
type: :development
|
|
245
259
|
prerelease: false
|
|
246
260
|
version_requirements: !ruby/object:Gem::Requirement
|
|
247
261
|
requirements:
|
|
248
262
|
- - '='
|
|
249
263
|
- !ruby/object:Gem::Version
|
|
250
|
-
version: 3.
|
|
264
|
+
version: 3.9.1
|
|
251
265
|
- !ruby/object:Gem::Dependency
|
|
252
266
|
name: rspec-rails
|
|
253
267
|
requirement: !ruby/object:Gem::Requirement
|
|
254
268
|
requirements:
|
|
255
269
|
- - '='
|
|
256
270
|
- !ruby/object:Gem::Version
|
|
257
|
-
version: 3.
|
|
271
|
+
version: 3.9.0
|
|
258
272
|
type: :development
|
|
259
273
|
prerelease: false
|
|
260
274
|
version_requirements: !ruby/object:Gem::Requirement
|
|
261
275
|
requirements:
|
|
262
276
|
- - '='
|
|
263
277
|
- !ruby/object:Gem::Version
|
|
264
|
-
version: 3.
|
|
278
|
+
version: 3.9.0
|
|
265
279
|
- !ruby/object:Gem::Dependency
|
|
266
280
|
name: rspec-support
|
|
267
281
|
requirement: !ruby/object:Gem::Requirement
|
|
268
282
|
requirements:
|
|
269
283
|
- - '='
|
|
270
284
|
- !ruby/object:Gem::Version
|
|
271
|
-
version: 3.
|
|
285
|
+
version: 3.9.2
|
|
272
286
|
type: :development
|
|
273
287
|
prerelease: false
|
|
274
288
|
version_requirements: !ruby/object:Gem::Requirement
|
|
275
289
|
requirements:
|
|
276
290
|
- - '='
|
|
277
291
|
- !ruby/object:Gem::Version
|
|
278
|
-
version: 3.
|
|
292
|
+
version: 3.9.2
|
|
279
293
|
- !ruby/object:Gem::Dependency
|
|
280
294
|
name: rubocop
|
|
281
295
|
requirement: !ruby/object:Gem::Requirement
|
|
282
296
|
requirements:
|
|
283
297
|
- - '='
|
|
284
298
|
- !ruby/object:Gem::Version
|
|
285
|
-
version: 0.
|
|
299
|
+
version: 0.80.1
|
|
286
300
|
type: :development
|
|
287
301
|
prerelease: false
|
|
288
302
|
version_requirements: !ruby/object:Gem::Requirement
|
|
289
303
|
requirements:
|
|
290
304
|
- - '='
|
|
291
305
|
- !ruby/object:Gem::Version
|
|
292
|
-
version: 0.
|
|
306
|
+
version: 0.80.1
|
|
293
307
|
- !ruby/object:Gem::Dependency
|
|
294
308
|
name: rubocop-rspec
|
|
295
309
|
requirement: !ruby/object:Gem::Requirement
|
|
296
310
|
requirements:
|
|
297
311
|
- - '='
|
|
298
312
|
- !ruby/object:Gem::Version
|
|
299
|
-
version: 1.
|
|
313
|
+
version: 1.38.1
|
|
300
314
|
type: :development
|
|
301
315
|
prerelease: false
|
|
302
316
|
version_requirements: !ruby/object:Gem::Requirement
|
|
303
317
|
requirements:
|
|
304
318
|
- - '='
|
|
305
319
|
- !ruby/object:Gem::Version
|
|
306
|
-
version: 1.
|
|
320
|
+
version: 1.38.1
|
|
307
321
|
- !ruby/object:Gem::Dependency
|
|
308
322
|
name: rubycritic
|
|
309
323
|
requirement: !ruby/object:Gem::Requirement
|
|
310
324
|
requirements:
|
|
311
325
|
- - '='
|
|
312
326
|
- !ruby/object:Gem::Version
|
|
313
|
-
version: 4.1
|
|
327
|
+
version: 4.4.1
|
|
314
328
|
type: :development
|
|
315
329
|
prerelease: false
|
|
316
330
|
version_requirements: !ruby/object:Gem::Requirement
|
|
317
331
|
requirements:
|
|
318
332
|
- - '='
|
|
319
333
|
- !ruby/object:Gem::Version
|
|
320
|
-
version: 4.1
|
|
334
|
+
version: 4.4.1
|
|
321
335
|
- !ruby/object:Gem::Dependency
|
|
322
336
|
name: simplecov
|
|
323
337
|
requirement: !ruby/object:Gem::Requirement
|
|
324
338
|
requirements:
|
|
325
339
|
- - '='
|
|
326
340
|
- !ruby/object:Gem::Version
|
|
327
|
-
version: 0.17.
|
|
341
|
+
version: 0.17.1
|
|
328
342
|
type: :development
|
|
329
343
|
prerelease: false
|
|
330
344
|
version_requirements: !ruby/object:Gem::Requirement
|
|
331
345
|
requirements:
|
|
332
346
|
- - '='
|
|
333
347
|
- !ruby/object:Gem::Version
|
|
334
|
-
version: 0.17.
|
|
348
|
+
version: 0.17.1
|
|
335
349
|
- !ruby/object:Gem::Dependency
|
|
336
350
|
name: sqlite3
|
|
337
351
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -352,14 +366,14 @@ dependencies:
|
|
|
352
366
|
requirements:
|
|
353
367
|
- - '='
|
|
354
368
|
- !ruby/object:Gem::Version
|
|
355
|
-
version: 0.9.
|
|
369
|
+
version: 0.9.24
|
|
356
370
|
type: :development
|
|
357
371
|
prerelease: false
|
|
358
372
|
version_requirements: !ruby/object:Gem::Requirement
|
|
359
373
|
requirements:
|
|
360
374
|
- - '='
|
|
361
375
|
- !ruby/object:Gem::Version
|
|
362
|
-
version: 0.9.
|
|
376
|
+
version: 0.9.24
|
|
363
377
|
- !ruby/object:Gem::Dependency
|
|
364
378
|
name: yardstick
|
|
365
379
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -402,6 +416,7 @@ files:
|
|
|
402
416
|
- lib/azeroth.rb
|
|
403
417
|
- lib/azeroth/decorator.rb
|
|
404
418
|
- lib/azeroth/decorator/hash_builder.rb
|
|
419
|
+
- lib/azeroth/exception.rb
|
|
405
420
|
- lib/azeroth/model.rb
|
|
406
421
|
- lib/azeroth/options.rb
|
|
407
422
|
- lib/azeroth/request_handler.rb
|
|
@@ -419,6 +434,7 @@ files:
|
|
|
419
434
|
- lib/azeroth/routes_builder.rb
|
|
420
435
|
- lib/azeroth/version.rb
|
|
421
436
|
- spec/controllers/documents_controller_spec.rb
|
|
437
|
+
- spec/controllers/index_documents_controller_spec.rb
|
|
422
438
|
- spec/dummy/.ruby-version
|
|
423
439
|
- spec/dummy/Rakefile
|
|
424
440
|
- spec/dummy/app/assets/config/manifest.js
|
|
@@ -432,6 +448,7 @@ files:
|
|
|
432
448
|
- spec/dummy/app/controllers/application_controller.rb
|
|
433
449
|
- spec/dummy/app/controllers/concerns/.keep
|
|
434
450
|
- spec/dummy/app/controllers/documents_controller.rb
|
|
451
|
+
- spec/dummy/app/controllers/index_documents_controller.rb
|
|
435
452
|
- spec/dummy/app/helpers/application_helper.rb
|
|
436
453
|
- spec/dummy/app/jobs/application_job.rb
|
|
437
454
|
- spec/dummy/app/mailers/application_mailer.rb
|
|
@@ -493,9 +510,12 @@ files:
|
|
|
493
510
|
- spec/dummy/tmp/.keep
|
|
494
511
|
- spec/dummy/tmp/storage/.keep
|
|
495
512
|
- spec/integration/yard/azeroth/decorator_spec.rb
|
|
513
|
+
- spec/integration/yard/azeroth/exception/invalid_options_spec.rb
|
|
496
514
|
- spec/lib/azeroth/decorator/hash_builder_spec.rb
|
|
497
515
|
- spec/lib/azeroth/decorator_spec.rb
|
|
516
|
+
- spec/lib/azeroth/exception/invalid_options_spec.rb
|
|
498
517
|
- spec/lib/azeroth/model_spec.rb
|
|
518
|
+
- spec/lib/azeroth/options_spec.rb
|
|
499
519
|
- spec/lib/azeroth/request_handler/create_spec.rb
|
|
500
520
|
- spec/lib/azeroth/request_handler/destroy_spec.rb
|
|
501
521
|
- spec/lib/azeroth/request_handler/edit_spec.rb
|
|
@@ -543,6 +563,7 @@ specification_version: 4
|
|
|
543
563
|
summary: Azeroth
|
|
544
564
|
test_files:
|
|
545
565
|
- spec/controllers/documents_controller_spec.rb
|
|
566
|
+
- spec/controllers/index_documents_controller_spec.rb
|
|
546
567
|
- spec/dummy/.ruby-version
|
|
547
568
|
- spec/dummy/Rakefile
|
|
548
569
|
- spec/dummy/app/assets/config/manifest.js
|
|
@@ -556,6 +577,7 @@ test_files:
|
|
|
556
577
|
- spec/dummy/app/controllers/application_controller.rb
|
|
557
578
|
- spec/dummy/app/controllers/concerns/.keep
|
|
558
579
|
- spec/dummy/app/controllers/documents_controller.rb
|
|
580
|
+
- spec/dummy/app/controllers/index_documents_controller.rb
|
|
559
581
|
- spec/dummy/app/helpers/application_helper.rb
|
|
560
582
|
- spec/dummy/app/jobs/application_job.rb
|
|
561
583
|
- spec/dummy/app/mailers/application_mailer.rb
|
|
@@ -617,9 +639,12 @@ test_files:
|
|
|
617
639
|
- spec/dummy/tmp/.keep
|
|
618
640
|
- spec/dummy/tmp/storage/.keep
|
|
619
641
|
- spec/integration/yard/azeroth/decorator_spec.rb
|
|
642
|
+
- spec/integration/yard/azeroth/exception/invalid_options_spec.rb
|
|
620
643
|
- spec/lib/azeroth/decorator/hash_builder_spec.rb
|
|
621
644
|
- spec/lib/azeroth/decorator_spec.rb
|
|
645
|
+
- spec/lib/azeroth/exception/invalid_options_spec.rb
|
|
622
646
|
- spec/lib/azeroth/model_spec.rb
|
|
647
|
+
- spec/lib/azeroth/options_spec.rb
|
|
623
648
|
- spec/lib/azeroth/request_handler/create_spec.rb
|
|
624
649
|
- spec/lib/azeroth/request_handler/destroy_spec.rb
|
|
625
650
|
- spec/lib/azeroth/request_handler/edit_spec.rb
|