azeroth 1.1.0 → 2.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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +16 -2
  5. data/Dockerfile +2 -2
  6. data/Gemfile +30 -0
  7. data/Makefile +6 -0
  8. data/README.md +5 -3
  9. data/azeroth.gemspec +6 -36
  10. data/lib/azeroth/controller_interface.rb +3 -4
  11. data/lib/azeroth/decorator/hash_builder.rb +1 -0
  12. data/lib/azeroth/decorator.rb +5 -8
  13. data/lib/azeroth/model.rb +1 -0
  14. data/lib/azeroth/options.rb +16 -0
  15. data/lib/azeroth/params_builder.rb +13 -3
  16. data/lib/azeroth/request_handler.rb +3 -2
  17. data/lib/azeroth/resource_builder.rb +15 -3
  18. data/lib/azeroth/resourceable/class_methods.rb +15 -2
  19. data/lib/azeroth/resourceable/endpoints_builder.rb +104 -0
  20. data/lib/azeroth/resourceable/{builder.rb → resources_builder.rb} +8 -19
  21. data/lib/azeroth/resourceable.rb +17 -2
  22. data/lib/azeroth/version.rb +1 -1
  23. data/spec/dummy/config/environments/production.rb +2 -2
  24. data/spec/dummy/config/puma.rb +3 -3
  25. data/spec/dummy/db/schema.rb +1 -1
  26. data/spec/integration/readme/controllers/games_controller_spec.rb +1 -1
  27. data/spec/integration/yard/controllers/games_controller_spec.rb +1 -1
  28. data/spec/integration/yard/controllers/paginated_documents_controller_spec.rb +1 -1
  29. data/spec/lib/azeroth/controller_interface_spec.rb +1 -1
  30. data/spec/lib/azeroth/decorator_spec.rb +0 -2
  31. data/spec/lib/azeroth/params_builder_spec.rb +49 -33
  32. data/spec/lib/azeroth/request_handler/update_spec.rb +1 -1
  33. data/spec/lib/azeroth/resource_builder_spec.rb +41 -17
  34. data/spec/lib/azeroth/resourceable/endpoints_builder_spec.rb +90 -0
  35. data/spec/lib/azeroth/resourceable/resources_builder_spec.rb +32 -0
  36. data/spec/lib/azeroth/resourceable_spec.rb +37 -37
  37. data/spec/spec_helper.rb +1 -1
  38. data/spec/support/app/controllers/controller.rb +1 -0
  39. data/spec/support/app/controllers/params_builder_controller.rb +2 -2
  40. data/spec/support/matchers/add_method.rb +6 -4
  41. data/spec/support/shared_examples/request_handler.rb +1 -5
  42. metadata +15 -575
  43. data/spec/lib/azeroth/resourceable/builder_spec.rb +0 -19
@@ -16,13 +16,16 @@ module Azeroth
16
16
  rescue_from ActiveRecord::RecordNotFound, with: :not_found
17
17
  end
18
18
 
19
- autoload :Builder, 'azeroth/resourceable/builder'
20
- autoload :ClassMethods, 'azeroth/resourceable/class_methods'
19
+ autoload :ClassMethods, 'azeroth/resourceable/class_methods'
20
+ autoload :EndpointsBuilder, 'azeroth/resourceable/endpoints_builder'
21
+ autoload :ResourcesBuilder, 'azeroth/resourceable/resources_builder'
21
22
 
22
23
  class << self
23
24
  # @method self.resource_for(name, **options)
24
25
  # @api public
25
26
  #
27
+ # Adds resource and routes methods for resource
28
+ #
26
29
  # @param name [String, Symbol] Name of the resource
27
30
  # @param options [Hash] resource building options
28
31
  # @option options only [Array<Symbol,String>,Symbol,String] List of
@@ -45,6 +48,8 @@ module Azeroth
45
48
  # endpoint should be paginated
46
49
  # @option options per_page [Integer] number of entries returned per
47
50
  # page on index
51
+ # @option options id_key [Symbol] key used to find a model. id by default
52
+ # @option options param_key [Symbol] parameter key used to find the model
48
53
  #
49
54
  # @return [Array<MethodDefinition>] list of methods created
50
55
  #
@@ -209,6 +214,16 @@ module Azeroth
209
214
  # 'per_page' => 20,
210
215
  # 'page' => 2
211
216
  # }
217
+
218
+ # @method self.model_for(name, **options)
219
+ # @api public
220
+ #
221
+ # Adds resource and routes methods for resource
222
+ #
223
+ # @param name [String, Symbol] Name of the resource
224
+ # @param options [Hash] resource building options
225
+ # @option options id_key [Symbol] key used to find a model. id by default
226
+ # @option options param_key [Symbol] parameter key used to find the model
212
227
  end
213
228
 
214
229
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Azeroth
4
- VERSION = '1.1.0'
4
+ VERSION = '2.1.0'
5
5
  end
@@ -89,7 +89,7 @@ Rails.application.configure do
89
89
  config.active_support.deprecation = :notify
90
90
 
91
91
  # Use default logging formatter so that PID and timestamp are not suppressed.
92
- config.log_formatter = ::Logger::Formatter.new
92
+ config.log_formatter = Logger::Formatter.new
93
93
 
94
94
  # Use a different logger for distributed setups.
95
95
  # require 'syslog/logger'
@@ -98,7 +98,7 @@ Rails.application.configure do
98
98
  # )
99
99
 
100
100
  if ENV['RAILS_LOG_TO_STDOUT'].present?
101
- logger = ActiveSupport::Logger.new(STDOUT)
101
+ logger = ActiveSupport::Logger.new($stdout)
102
102
  logger.formatter = config.log_formatter
103
103
  config.logger = ActiveSupport::TaggedLogging.new(logger)
104
104
  end
@@ -6,17 +6,17 @@
6
6
  # the maximum value specified for Puma. Default is set to 5 threads for minimum
7
7
  # and maximum; this matches the default thread size of Active Record.
8
8
  #
9
- threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
9
+ threads_count = ENV.fetch('RAILS_MAX_THREADS', 5)
10
10
  threads threads_count, threads_count
11
11
 
12
12
  # Specifies the `port` that Puma will listen on to receive requests;
13
13
  # default is 3000.
14
14
  #
15
- port ENV.fetch('PORT') { 3000 }
15
+ port ENV.fetch('PORT', 3000)
16
16
 
17
17
  # Specifies the `environment` that Puma will run in.
18
18
  #
19
- environment ENV.fetch('RAILS_ENV') { 'development' }
19
+ environment ENV.fetch('RAILS_ENV', 'development')
20
20
 
21
21
  # Specifies the number of `workers` to boot in clustered mode.
22
22
  # Workers are forked webserver processes. If using threads and workers together
@@ -54,7 +54,7 @@ ActiveRecord::Schema.define do
54
54
 
55
55
  create_table :websites, force: true do |t|
56
56
  t.string :domain, null: false
57
- t.integer :port, limit: 2, unsigned: true
57
+ t.integer :port, limit: 2
58
58
  t.string :protocol, limit: 5
59
59
  end
60
60
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe GamesController, controller: true do
5
+ describe GamesController, :controller do
6
6
  describe 'readme' do
7
7
  describe 'POST create' do
8
8
  it 'create game' do
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe GamesController, controller: true do
5
+ describe GamesController, :controller do
6
6
  describe 'yard' do
7
7
  describe 'POST create' do
8
8
  it 'create game' do
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe PaginatedDocumentsController, controller: true do
5
+ describe PaginatedDocumentsController, :controller do
6
6
  describe 'yard' do
7
7
  describe 'GET index' do
8
8
  before { create_list(:document, 30) }
@@ -11,7 +11,7 @@ describe Azeroth::ControllerInterface do
11
11
  describe '#add_headers' do
12
12
  let(:controller_headers) do
13
13
  {
14
- 'old_key': 100
14
+ old_key: 100
15
15
  }
16
16
  end
17
17
 
@@ -416,12 +416,10 @@ describe Azeroth::Decorator do
416
416
  end
417
417
 
418
418
  context 'when method is private and passing include_private' do
419
- # rubocop:disable RSpec/PredicateMatcher
420
419
  it do
421
420
  expect(decorator.respond_to?(:private_name, true))
422
421
  .to be_truthy
423
422
  end
424
- # rubocop:enable RSpec/PredicateMatcher
425
423
  end
426
424
 
427
425
  context 'when object does not respond to it' do
@@ -4,55 +4,71 @@ require 'spec_helper'
4
4
 
5
5
  describe Azeroth::ParamsBuilder do
6
6
  subject(:params_builder) do
7
- described_class.new(model: model, builder: builder)
7
+ described_class.new(model: model, builder: builder, options: options)
8
8
  end
9
9
 
10
- let(:model) { Azeroth::Model.new(:document, options) }
11
- let(:options) { Azeroth::Options.new }
12
- let(:builder) { Sinclair.new(klass) }
13
- let(:klass) { Class.new(ParamsBuilderController) }
10
+ let(:model) { Azeroth::Model.new(:document, options) }
11
+ let(:options) { Azeroth::Options.new(options_hash) }
12
+ let(:options_hash) { {} }
13
+ let(:builder) { Sinclair.new(klass) }
14
+ let(:klass) { Class.new(ParamsBuilderController) }
15
+ let(:controller) { klass.new(id, attributes) }
16
+ let(:attributes) { document.attributes }
17
+ let(:document) { create(:document) }
18
+ let(:id) { Random.rand(10..100) }
14
19
 
15
20
  before do
16
21
  params_builder.append
17
22
  end
18
23
 
19
24
  describe '#append' do
20
- it 'adds id method' do
21
- expect { builder.build }
22
- .to add_method(:document_id).to(klass)
23
- end
24
-
25
- it 'adds params method' do
26
- expect { builder.build }
27
- .to add_method(:document_params).to(klass)
28
- end
25
+ context 'when no options are given' do
26
+ it 'adds id method' do
27
+ expect { builder.build }
28
+ .to add_method(:document_id).to(klass)
29
+ end
29
30
 
30
- describe 'after the build' do
31
- let(:controller) { klass.new(id, attributes) }
32
- let(:document) { create(:document) }
33
- let(:attributes) { document.attributes }
34
- let(:id) { Random.rand(10..100) }
35
- let(:expected_attributes) do
36
- {
37
- 'name' => document.name,
38
- 'reference' => document.reference
39
- }
31
+ it 'adds params method' do
32
+ expect { builder.build }
33
+ .to add_method(:document_params).to(klass)
40
34
  end
41
35
 
42
- before { builder.build }
36
+ describe 'after the build' do
37
+ let(:expected_attributes) do
38
+ {
39
+ 'name' => document.name,
40
+ 'reference' => document.reference
41
+ }
42
+ end
43
+
44
+ before { builder.build }
43
45
 
44
- context 'when requesting id' do
45
- it 'returns id from request path' do
46
- expect(controller.document_id).to eq(id)
46
+ context 'when requesting id' do
47
+ it 'returns id from request path' do
48
+ expect(controller.document_id).to eq(id)
49
+ end
47
50
  end
48
- end
49
51
 
50
- context 'when requesting params' do
51
- it 'returns payload' do
52
- expect(controller.document_params.to_h)
53
- .to eq(expected_attributes)
52
+ context 'when requesting params' do
53
+ it 'returns payload' do
54
+ expect(controller.document_params.to_h)
55
+ .to eq(expected_attributes)
56
+ end
54
57
  end
55
58
  end
56
59
  end
57
60
  end
61
+
62
+ context 'when no options are given' do
63
+ let(:options_hash) { { param_key: :document_id } }
64
+ let(:controller) { klass.new(id, attributes, param_id: :document_id) }
65
+
66
+ before { builder.build }
67
+
68
+ context 'when requesting id' do
69
+ it 'returns id from request path' do
70
+ expect(controller.document_id).to eq(id)
71
+ end
72
+ end
73
+ end
58
74
  end
@@ -30,7 +30,7 @@ describe Azeroth::RequestHandler::Update do
30
30
  end
31
31
  end
32
32
 
33
- context 'when update_with option is given ' do
33
+ context 'when update_with option is given' do
34
34
  context 'with block' do
35
35
  it_behaves_like 'a request handler' do
36
36
  let(:block) do
@@ -4,13 +4,14 @@ require 'spec_helper'
4
4
 
5
5
  describe Azeroth::ResourceBuilder do
6
6
  subject(:resource_builder) do
7
- described_class.new(model: model, builder: builder)
7
+ described_class.new(model: model, builder: builder, options: options)
8
8
  end
9
9
 
10
- let(:model) { Azeroth::Model.new(:document, options) }
11
- let(:options) { Azeroth::Options.new }
12
- let(:builder) { Sinclair.new(klass) }
13
- let(:klass) { Class.new(ResourceBuilderController) }
10
+ let(:model) { Azeroth::Model.new(:document, options) }
11
+ let(:options) { Azeroth::Options.new(options_hash) }
12
+ let(:options_hash) { {} }
13
+ let(:builder) { Sinclair.new(klass) }
14
+ let(:klass) { Class.new(ResourceBuilderController) }
14
15
 
15
16
  before do
16
17
  resource_builder.append
@@ -18,21 +19,44 @@ describe Azeroth::ResourceBuilder do
18
19
  end
19
20
 
20
21
  describe '#append' do
21
- it 'adds the listing method' do
22
- expect { builder.build }
23
- .to change { klass.new.respond_to?(:documents) }
24
- .to(true)
25
- end
22
+ context 'when no option is given' do
23
+ it 'adds the listing method' do
24
+ expect { builder.build }
25
+ .to change { klass.new.respond_to?(:documents) }
26
+ .to(true)
27
+ end
28
+
29
+ it 'adds the fetching method' do
30
+ expect { builder.build }
31
+ .to change { klass.new.respond_to?(:document) }
32
+ .to(true)
33
+ end
34
+
35
+ describe 'after the build' do
36
+ let(:controller) { klass.new(document_id: document.id) }
37
+ let(:document) { create(:document) }
38
+
39
+ before { builder.build }
26
40
 
27
- it 'adds the fetching method' do
28
- expect { builder.build }
29
- .to change { klass.new.respond_to?(:document) }
30
- .to(true)
41
+ context 'when requesting the list of documents' do
42
+ it 'returns the list of documents' do
43
+ expect(controller.documents).to eq(Document.all)
44
+ end
45
+ end
46
+
47
+ context 'when requesting one document' do
48
+ it 'returns the requested document' do
49
+ expect(controller.document).to eq(document)
50
+ end
51
+ end
52
+ end
31
53
  end
32
54
 
33
- describe 'after the build' do
34
- let(:controller) { klass.new(document_id: document.id) }
35
- let(:document) { create(:document) }
55
+ context 'when id_key option is given' do
56
+ let(:options_hash) { { id_key: :reference } }
57
+
58
+ let(:controller) { klass.new(document_id: document.reference) }
59
+ let(:document) { create(:document, reference: SecureRandom.hex(20)) }
36
60
 
37
61
  before { builder.build }
38
62
 
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Azeroth::Resourceable::EndpointsBuilder do
6
+ subject(:builder) { described_class.new(klass, :document, options) }
7
+
8
+ let(:options) { Azeroth::Options.new(options_hash) }
9
+ let(:options_hash) { {} }
10
+
11
+ let(:klass) do
12
+ Class.new(Controller) do
13
+ end
14
+ end
15
+
16
+ describe '#build' do
17
+ let(:available_routes) { %i[index show new destroy create update] }
18
+ let(:expected_params_methods) { %i[document_id document_params] }
19
+ let(:expected_routes_methods) { available_routes }
20
+ let(:expected_resource_methods) { %i[document documents] }
21
+
22
+ context 'when no option is given' do
23
+ it 'adds params methods' do
24
+ expect { builder.build }
25
+ .to change { (klass.instance_methods & expected_params_methods).sort }
26
+ .from([]).to(expected_params_methods.sort)
27
+ end
28
+
29
+ it 'adds routes methods' do
30
+ expect { builder.build }
31
+ .to change { (klass.instance_methods & available_routes).sort }
32
+ .from([]).to(expected_routes_methods.sort)
33
+ end
34
+
35
+ it 'adds resource methods' do
36
+ expect { builder.build }
37
+ .to change { (klass.instance_methods & expected_resource_methods).sort }
38
+ .from([]).to(expected_resource_methods.sort)
39
+ end
40
+ end
41
+
42
+ context 'when only option is given for a route' do
43
+ let(:options_hash) { { only: route } }
44
+ let(:route) { available_routes.sample }
45
+ let(:expected_routes_methods) { [route] }
46
+
47
+ it 'adds routes methods' do
48
+ expect { builder.build }
49
+ .to change { (klass.instance_methods & available_routes).sort }
50
+ .from([]).to(expected_routes_methods.sort)
51
+ end
52
+ end
53
+
54
+ context 'when only option as array is given for a route' do
55
+ let(:options_hash) { { only: routes } }
56
+ let(:routes) { [available_routes.sample, available_routes.sample].uniq }
57
+ let(:expected_routes_methods) { routes }
58
+
59
+ it 'adds routes methods' do
60
+ expect { builder.build }
61
+ .to change { (klass.instance_methods & available_routes).sort }
62
+ .from([]).to(expected_routes_methods.sort)
63
+ end
64
+ end
65
+
66
+ context 'when except option is given for a route' do
67
+ let(:options_hash) { { except: route } }
68
+ let(:route) { available_routes.sample }
69
+ let(:expected_routes_methods) { available_routes - [route] }
70
+
71
+ it 'adds routes methods' do
72
+ expect { builder.build }
73
+ .to change { (klass.instance_methods & available_routes).sort }
74
+ .from([]).to(expected_routes_methods.sort)
75
+ end
76
+ end
77
+
78
+ context 'when except option as array is given for a route' do
79
+ let(:options_hash) { { except: routes } }
80
+ let(:routes) { [available_routes.sample, available_routes.sample].uniq }
81
+ let(:expected_routes_methods) { available_routes - routes }
82
+
83
+ it 'adds routes methods' do
84
+ expect { builder.build }
85
+ .to change { (klass.instance_methods & available_routes).sort }
86
+ .from([]).to(expected_routes_methods.sort)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Azeroth::Resourceable::ResourcesBuilder do
6
+ subject(:builder) { described_class.new(klass, :document, options) }
7
+
8
+ let(:options) { Azeroth::Options.new(options_hash) }
9
+ let(:options_hash) { {} }
10
+
11
+ let(:klass) do
12
+ Class.new(Controller) do
13
+ end
14
+ end
15
+
16
+ describe '#build' do
17
+ let(:expected_resource_methods) { %i[document documents] }
18
+ let(:expected_params_methods) { %i[document_id document_params] }
19
+
20
+ it 'adds params methods' do
21
+ expect { builder.build }
22
+ .to change { (klass.instance_methods & expected_params_methods).sort }
23
+ .from([]).to(expected_params_methods.sort)
24
+ end
25
+
26
+ it 'adds resource methods' do
27
+ expect { builder.build }
28
+ .to change { (klass.instance_methods & expected_resource_methods).sort }
29
+ .from([]).to(expected_resource_methods.sort)
30
+ end
31
+ end
32
+ end
@@ -10,54 +10,41 @@ describe Azeroth::Resourceable do
10
10
  end
11
11
 
12
12
  describe '.resource_for' do
13
- let(:params) { { id: model.id, format: :json } }
14
- let(:model_name) { :document }
15
- let(:model) { create(model_name) }
16
- let(:controller) { controller_class.new(params) }
17
- let(:decorator) { Document::Decorator }
13
+ let(:available_routes) { %i[index show new destroy create update] }
14
+ let(:params) { { id: model.id, format: :json } }
15
+ let(:model_name) { :document }
16
+ let(:model) { create(model_name) }
17
+ let(:controller) { controller_class.new(params) }
18
+ let(:decorator) { Document::Decorator }
18
19
 
19
20
  context 'when no special option is given' do
20
- %i[index show new edit update destroy].each do |method_name|
21
- it do
22
- expect { controller_class.resource_for(model_name) }
23
- .to add_method(method_name).to(controller_class)
24
- end
21
+ it 'add routes methods' do
22
+ expect { controller_class.resource_for(model_name) }
23
+ .to change { (controller.methods & available_routes).sort }
24
+ .from([]).to(available_routes.sort)
25
25
  end
26
26
  end
27
27
 
28
28
  context 'when passing the only option' do
29
- let(:options) { { only: %i[index show] } }
30
-
31
- %i[index show].each do |method_name|
32
- it do
33
- expect { controller_class.resource_for(model_name, **options) }
34
- .to add_method(method_name).to(controller_class)
35
- end
36
- end
29
+ let(:options) { { only: expected_routes_methods } }
30
+ let(:expected_routes_methods) { %i[index show] }
37
31
 
38
- %i[new edit update destroy].each do |method_name|
39
- it do
40
- expect { controller_class.resource_for(model_name, **options) }
41
- .not_to add_method(method_name).to(controller_class)
42
- end
32
+ it 'add routes methods' do
33
+ expect { controller_class.resource_for(model_name, **options) }
34
+ .to change { (controller.methods & available_routes).sort }
35
+ .from([]).to(expected_routes_methods.sort)
43
36
  end
44
37
  end
45
38
 
46
39
  context 'when passing the except option' do
47
- let(:options) { { except: %i[index show] } }
48
-
49
- %i[index show].each do |method_name|
50
- it do
51
- expect { controller_class.resource_for(model_name, **options) }
52
- .not_to add_method(method_name).to(controller_class)
53
- end
54
- end
55
-
56
- %i[new edit update destroy].each do |method_name|
57
- it do
58
- expect { controller_class.resource_for(model_name, **options) }
59
- .to add_method(method_name).to(controller_class)
60
- end
40
+ let(:options) { { except: skipped_routes } }
41
+ let(:skipped_routes) { %i[index show] }
42
+ let(:expected_routes_methods) { available_routes - skipped_routes }
43
+
44
+ it 'add routes methods' do
45
+ expect { controller_class.resource_for(model_name, **options) }
46
+ .to change { (controller.methods & available_routes).sort }
47
+ .from([]).to(expected_routes_methods.sort)
61
48
  end
62
49
  end
63
50
 
@@ -105,4 +92,17 @@ describe Azeroth::Resourceable do
105
92
  end
106
93
  end
107
94
  end
95
+
96
+ describe '.model_for' do
97
+ let(:model_name) { :document }
98
+ let(:model) { create(model_name) }
99
+ let(:controller) { controller_class.new({}) }
100
+ let(:expected_resource_methods) { %i[document documents] }
101
+
102
+ it 'adds resource methods' do
103
+ expect { controller_class.model_for(model_name) }
104
+ .to change { (controller.methods & expected_resource_methods).sort }
105
+ .from([]).to(expected_resource_methods.sort)
106
+ end
107
+ end
108
108
  end
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,7 @@ require 'shoulda-matchers'
22
22
  require 'rspec/collection_matchers'
23
23
 
24
24
  support_files = File.expand_path('spec/support/**/*.rb')
25
- Dir[support_files].sort.each { |file| require file }
25
+ Dir[support_files].each { |file| require file }
26
26
 
27
27
  RSpec::Matchers.define_negated_matcher :not_change, :change
28
28
  RSpec::Matchers.define_negated_matcher :not_add_method, :add_method
@@ -4,6 +4,7 @@ require 'action_controller'
4
4
 
5
5
  class Controller < ActionController::Base
6
6
  def initialize(params = {})
7
+ super()
7
8
  @params = ActionController::Parameters.new(params)
8
9
  end
9
10
 
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParamsBuilderController
4
- def initialize(id, attributes)
4
+ def initialize(id, attributes, param_id: :id)
5
5
  @params = ActionController::Parameters.new(
6
- id: id,
6
+ param_id => id,
7
7
  document: attributes
8
8
  )
9
9
  end
@@ -6,11 +6,12 @@ module RSpec
6
6
  attr_reader :method
7
7
 
8
8
  def initialize(method = nil)
9
+ super
9
10
  @method = method
10
11
  end
11
12
 
12
- def to(instance = nil, &block)
13
- AddMethodTo.new(instance, method, &block)
13
+ def to(instance = nil, &)
14
+ AddMethodTo.new(instance, method, &)
14
15
  end
15
16
  end
16
17
 
@@ -18,6 +19,7 @@ module RSpec
18
19
  attr_reader :method, :instance, :block
19
20
 
20
21
  def initialize(instance, method, &block)
22
+ super
21
23
  @instance = instance
22
24
  @method = method
23
25
  @block = block
@@ -68,8 +70,8 @@ module RSpec
68
70
 
69
71
  def raise_block_syntax_error
70
72
  raise SyntaxError, 'Block not received by the' \
71
- '`add_method_to` matcher. ' \
72
- 'Perhaps you want to use `{ ... }` instead of do/end?'
73
+ '`add_method_to` matcher. ' \
74
+ 'Perhaps you want to use `{ ... }` instead of do/end?'
73
75
  end
74
76
  end
75
77
  end
@@ -29,15 +29,11 @@ shared_examples 'a request handler' do |status: :ok|
29
29
  before do
30
30
  create_list(:document, documents_count)
31
31
 
32
- allow(controller).to receive(:params)
33
- .and_return(params)
34
-
35
32
  allow(controller).to receive(:render)
36
33
  .with(json: expected_json, status: status)
37
34
  .and_return(expected_json)
38
35
 
39
- allow(controller).to receive(:headers)
40
- .and_return(controller_headers)
36
+ allow(controller).to receive_messages(params: params, headers: controller_headers)
41
37
  end
42
38
 
43
39
  it 'returns all documents json' do