praxis 2.0.pre.17 → 2.0.pre.21

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 (235) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +54 -0
  3. data/.simplecov +3 -1
  4. data/.travis.yml +2 -1
  5. data/CHANGELOG.md +19 -0
  6. data/CONTRIBUTING.md +2 -79
  7. data/Gemfile +5 -1
  8. data/Guardfile +6 -4
  9. data/LICENSE +0 -2
  10. data/MAINTAINERS.md +1 -0
  11. data/README.md +15 -22
  12. data/Rakefile +4 -2
  13. data/bin/praxis +55 -58
  14. data/lib/praxis/action_definition/headers_dsl_compiler.rb +5 -6
  15. data/lib/praxis/action_definition.rb +65 -95
  16. data/lib/praxis/api_definition.rb +21 -29
  17. data/lib/praxis/api_general_info.rb +55 -66
  18. data/lib/praxis/application.rb +15 -32
  19. data/lib/praxis/blueprint.rb +80 -73
  20. data/lib/praxis/bootloader.rb +24 -33
  21. data/lib/praxis/bootloader_stages/environment.rb +5 -10
  22. data/lib/praxis/bootloader_stages/file_loader.rb +3 -6
  23. data/lib/praxis/bootloader_stages/plugin_config_load.rb +4 -6
  24. data/lib/praxis/bootloader_stages/plugin_config_prepare.rb +2 -2
  25. data/lib/praxis/bootloader_stages/plugin_loader.rb +3 -7
  26. data/lib/praxis/bootloader_stages/plugin_setup.rb +3 -3
  27. data/lib/praxis/bootloader_stages/routing.rb +5 -8
  28. data/lib/praxis/bootloader_stages/subgroup_loader.rb +2 -10
  29. data/lib/praxis/bootloader_stages/warn_unloaded_files.rb +15 -19
  30. data/lib/praxis/callbacks.rb +12 -11
  31. data/lib/praxis/collection.rb +11 -14
  32. data/lib/praxis/config.rb +17 -28
  33. data/lib/praxis/config_hash.rb +2 -1
  34. data/lib/praxis/controller.rb +7 -6
  35. data/lib/praxis/dispatcher.rb +34 -42
  36. data/lib/praxis/docs/open_api/info_object.rb +11 -8
  37. data/lib/praxis/docs/open_api/media_type_object.rb +18 -17
  38. data/lib/praxis/docs/open_api/operation_object.rb +7 -4
  39. data/lib/praxis/docs/open_api/parameter_object.rb +17 -14
  40. data/lib/praxis/docs/open_api/paths_object.rb +11 -9
  41. data/lib/praxis/docs/open_api/request_body_object.rb +14 -13
  42. data/lib/praxis/docs/open_api/response_object.rb +24 -18
  43. data/lib/praxis/docs/open_api/responses_object.rb +3 -1
  44. data/lib/praxis/docs/open_api/schema_object.rb +61 -29
  45. data/lib/praxis/docs/open_api/server_object.rb +5 -2
  46. data/lib/praxis/docs/open_api/tag_object.rb +9 -6
  47. data/lib/praxis/docs/open_api_generator.rb +114 -150
  48. data/lib/praxis/endpoint_definition.rb +60 -77
  49. data/lib/praxis/error_handler.rb +2 -2
  50. data/lib/praxis/exception.rb +2 -0
  51. data/lib/praxis/exceptions/config.rb +3 -1
  52. data/lib/praxis/exceptions/config_load.rb +2 -0
  53. data/lib/praxis/exceptions/config_validation.rb +3 -1
  54. data/lib/praxis/exceptions/invalid_configuration.rb +3 -1
  55. data/lib/praxis/exceptions/invalid_response.rb +3 -1
  56. data/lib/praxis/exceptions/invalid_trait.rb +3 -1
  57. data/lib/praxis/exceptions/stage_not_found.rb +3 -1
  58. data/lib/praxis/exceptions/validation.rb +4 -3
  59. data/lib/praxis/extensions/attribute_filtering/active_record_filter_query_builder.rb +163 -149
  60. data/lib/praxis/extensions/attribute_filtering/active_record_patches/5x.rb +18 -13
  61. data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_0.rb +13 -9
  62. data/lib/praxis/extensions/attribute_filtering/active_record_patches/6_1_plus.rb +14 -11
  63. data/lib/praxis/extensions/attribute_filtering/active_record_patches.rb +12 -9
  64. data/lib/praxis/extensions/attribute_filtering/filter_tree_node.rb +8 -5
  65. data/lib/praxis/extensions/attribute_filtering/filtering_params.rb +89 -65
  66. data/lib/praxis/extensions/attribute_filtering/filters_parser.rb +68 -62
  67. data/lib/praxis/extensions/attribute_filtering.rb +3 -1
  68. data/lib/praxis/extensions/field_expansion.rb +6 -4
  69. data/lib/praxis/extensions/field_selection/active_record_query_selector.rb +10 -8
  70. data/lib/praxis/extensions/field_selection/field_selector.rb +91 -92
  71. data/lib/praxis/extensions/field_selection/sequel_query_selector.rb +12 -12
  72. data/lib/praxis/extensions/field_selection.rb +3 -1
  73. data/lib/praxis/extensions/pagination/active_record_pagination_handler.rb +6 -4
  74. data/lib/praxis/extensions/pagination/header_generator.rb +16 -11
  75. data/lib/praxis/extensions/pagination/ordering_params.rb +29 -28
  76. data/lib/praxis/extensions/pagination/pagination_handler.rb +44 -42
  77. data/lib/praxis/extensions/pagination/pagination_params.rb +29 -48
  78. data/lib/praxis/extensions/pagination/sequel_pagination_handler.rb +8 -7
  79. data/lib/praxis/extensions/pagination.rb +10 -15
  80. data/lib/praxis/extensions/rails_compat/request_methods.rb +3 -4
  81. data/lib/praxis/extensions/rails_compat.rb +2 -0
  82. data/lib/praxis/extensions/rendering.rb +12 -12
  83. data/lib/praxis/field_expander.rb +8 -9
  84. data/lib/praxis/file_group.rb +8 -12
  85. data/lib/praxis/finalizable.rb +1 -0
  86. data/lib/praxis/handlers/json.rb +5 -2
  87. data/lib/praxis/handlers/plain.rb +2 -1
  88. data/lib/praxis/handlers/www_form.rb +6 -3
  89. data/lib/praxis/handlers/{xml-sample.rb → xml_sample.rb} +26 -22
  90. data/lib/praxis/mapper/active_model_compat.rb +13 -10
  91. data/lib/praxis/mapper/resource.rb +196 -181
  92. data/lib/praxis/mapper/selector_generator.rb +106 -112
  93. data/lib/praxis/mapper/sequel_compat.rb +70 -67
  94. data/lib/praxis/media_type.rb +2 -2
  95. data/lib/praxis/media_type_identifier.rb +26 -22
  96. data/lib/praxis/middleware_app.rb +18 -15
  97. data/lib/praxis/multipart/parser.rb +46 -51
  98. data/lib/praxis/multipart/part.rb +78 -110
  99. data/lib/praxis/notifications.rb +2 -4
  100. data/lib/praxis/plugin.rb +11 -18
  101. data/lib/praxis/plugin_concern.rb +12 -15
  102. data/lib/praxis/plugins/mapper_plugin.rb +15 -13
  103. data/lib/praxis/plugins/pagination_plugin.rb +8 -6
  104. data/lib/praxis/plugins/rails_plugin.rb +33 -28
  105. data/lib/praxis/renderer.rb +11 -15
  106. data/lib/praxis/request.rb +48 -44
  107. data/lib/praxis/request_stages/action.rb +4 -6
  108. data/lib/praxis/request_stages/load_request.rb +2 -4
  109. data/lib/praxis/request_stages/request_stage.rb +19 -23
  110. data/lib/praxis/request_stages/response.rb +4 -6
  111. data/lib/praxis/request_stages/validate.rb +3 -5
  112. data/lib/praxis/request_stages/validate_params_and_headers.rb +15 -22
  113. data/lib/praxis/request_stages/validate_payload.rb +25 -28
  114. data/lib/praxis/request_superclassing.rb +3 -3
  115. data/lib/praxis/resource_definition.rb +1 -0
  116. data/lib/praxis/response.rb +24 -26
  117. data/lib/praxis/response_definition.rb +77 -122
  118. data/lib/praxis/response_template.rb +11 -15
  119. data/lib/praxis/responses/http.rb +23 -44
  120. data/lib/praxis/responses/internal_server_error.rb +18 -21
  121. data/lib/praxis/responses/multipart_ok.rb +4 -9
  122. data/lib/praxis/responses/validation_error.rb +8 -15
  123. data/lib/praxis/route.rb +8 -10
  124. data/lib/praxis/router/rack.rb +13 -7
  125. data/lib/praxis/router/simple.rb +10 -5
  126. data/lib/praxis/router.rb +27 -34
  127. data/lib/praxis/routing_config.rb +52 -29
  128. data/lib/praxis/simple_media_type.rb +5 -8
  129. data/lib/praxis/stage.rb +17 -25
  130. data/lib/praxis/tasks/api_docs.rb +17 -16
  131. data/lib/praxis/tasks/console.rb +3 -1
  132. data/lib/praxis/tasks/environment.rb +2 -0
  133. data/lib/praxis/tasks/routes.rb +26 -24
  134. data/lib/praxis/tasks.rb +3 -1
  135. data/lib/praxis/trait.rb +37 -46
  136. data/lib/praxis/types/fuzzy_hash.rb +13 -14
  137. data/lib/praxis/types/media_type_common.rb +11 -10
  138. data/lib/praxis/types/multipart_array/part_definition.rb +14 -17
  139. data/lib/praxis/types/multipart_array.rb +100 -115
  140. data/lib/praxis/validation_handler.rb +5 -3
  141. data/lib/praxis/version.rb +3 -1
  142. data/lib/praxis.rb +4 -5
  143. data/praxis.gemspec +22 -21
  144. data/spec/functional_spec.rb +44 -56
  145. data/spec/praxis/action_definition_spec.rb +39 -48
  146. data/spec/praxis/api_definition_spec.rb +45 -47
  147. data/spec/praxis/api_general_info_spec.rb +28 -29
  148. data/spec/praxis/application_spec.rb +18 -14
  149. data/spec/praxis/blueprint_spec.rb +33 -34
  150. data/spec/praxis/bootloader_spec.rb +32 -30
  151. data/spec/praxis/callbacks_spec.rb +37 -37
  152. data/spec/praxis/collection_spec.rb +18 -25
  153. data/spec/praxis/config_hash_spec.rb +5 -4
  154. data/spec/praxis/config_spec.rb +27 -26
  155. data/spec/praxis/controller_spec.rb +8 -9
  156. data/spec/praxis/endpoint_definition_spec.rb +25 -32
  157. data/spec/praxis/extensions/attribute_filtering/active_record_filter_query_builder_spec.rb +171 -114
  158. data/spec/praxis/extensions/attribute_filtering/filter_tree_node_spec.rb +22 -21
  159. data/spec/praxis/extensions/attribute_filtering/filtering_params_spec.rb +112 -60
  160. data/spec/praxis/extensions/attribute_filtering/filters_parser_spec.rb +37 -38
  161. data/spec/praxis/extensions/field_expansion_spec.rb +8 -10
  162. data/spec/praxis/extensions/field_selection/active_record_query_selector_spec.rb +14 -13
  163. data/spec/praxis/extensions/field_selection/field_selector_spec.rb +9 -16
  164. data/spec/praxis/extensions/field_selection/sequel_query_selector_spec.rb +50 -49
  165. data/spec/praxis/extensions/pagination/active_record_pagination_handler_spec.rb +32 -31
  166. data/spec/praxis/extensions/rendering_spec.rb +9 -9
  167. data/spec/praxis/extensions/support/spec_resources_active_model.rb +32 -49
  168. data/spec/praxis/extensions/support/spec_resources_sequel.rb +48 -48
  169. data/spec/praxis/field_expander_spec.rb +6 -5
  170. data/spec/praxis/file_group_spec.rb +3 -1
  171. data/spec/praxis/handlers/json_spec.rb +6 -5
  172. data/spec/praxis/mapper/resource_spec.rb +39 -29
  173. data/spec/praxis/mapper/selector_generator_spec.rb +80 -46
  174. data/spec/praxis/media_type_identifier_spec.rb +13 -10
  175. data/spec/praxis/media_type_spec.rb +12 -12
  176. data/spec/praxis/middleware_app_spec.rb +23 -22
  177. data/spec/praxis/multipart/parser_spec.rb +7 -9
  178. data/spec/praxis/notifications_spec.rb +4 -4
  179. data/spec/praxis/plugin_concern_spec.rb +5 -6
  180. data/spec/praxis/renderer_spec.rb +10 -9
  181. data/spec/praxis/request_spec.rb +38 -41
  182. data/spec/praxis/request_stages/action_spec.rb +14 -15
  183. data/spec/praxis/request_stages/request_stage_spec.rb +30 -41
  184. data/spec/praxis/request_stages/validate_spec.rb +3 -1
  185. data/spec/praxis/response_definition_spec.rb +79 -92
  186. data/spec/praxis/response_spec.rb +35 -40
  187. data/spec/praxis/responses/internal_server_error_spec.rb +6 -9
  188. data/spec/praxis/responses/validation_error_spec.rb +17 -18
  189. data/spec/praxis/route_spec.rb +4 -7
  190. data/spec/praxis/router_spec.rb +69 -79
  191. data/spec/praxis/routing_config_spec.rb +15 -14
  192. data/spec/praxis/stage_spec.rb +56 -53
  193. data/spec/praxis/trait_spec.rb +17 -17
  194. data/spec/praxis/types/fuzzy_hash_spec.rb +11 -9
  195. data/spec/praxis/types/multipart_array/part_definition_spec.rb +3 -2
  196. data/spec/praxis/types/multipart_array_spec.rb +33 -48
  197. data/spec/spec_app/app/concerns/authenticated.rb +5 -5
  198. data/spec/spec_app/app/concerns/basic_api.rb +3 -1
  199. data/spec/spec_app/app/concerns/log_wrapper.rb +5 -3
  200. data/spec/spec_app/app/controllers/base_class.rb +6 -5
  201. data/spec/spec_app/app/controllers/instances.rb +31 -34
  202. data/spec/spec_app/app/controllers/volumes.rb +6 -6
  203. data/spec/spec_app/app/responses/multipart.rb +1 -2
  204. data/spec/spec_app/app/responses/other_response.rb +2 -2
  205. data/spec/spec_app/config/environment.rb +19 -6
  206. data/spec/spec_app/config.ru +4 -3
  207. data/spec/spec_app/design/api.rb +13 -15
  208. data/spec/spec_app/design/media_types/instance.rb +6 -6
  209. data/spec/spec_app/design/media_types/volume.rb +2 -1
  210. data/spec/spec_app/design/media_types/volume_snapshot.rb +2 -1
  211. data/spec/spec_app/design/resources/instances.rb +11 -17
  212. data/spec/spec_app/design/resources/volume_snapshots.rb +4 -5
  213. data/spec/spec_app/design/resources/volumes.rb +4 -5
  214. data/spec/spec_helper.rb +11 -13
  215. data/spec/support/be_deep_equal_matcher.rb +5 -0
  216. data/spec/support/spec_authorization_plugin.rb +7 -12
  217. data/spec/support/spec_blueprints.rb +5 -4
  218. data/spec/support/spec_complex_authentication_plugin.rb +17 -34
  219. data/spec/support/spec_endpoint_definitions.rb +2 -3
  220. data/spec/support/spec_media_types.rb +28 -35
  221. data/spec/support/spec_resources.rb +22 -16
  222. data/spec/support/spec_simple_authentication_plugin.rb +5 -9
  223. data/tasks/loader.thor +4 -2
  224. data/tasks/thor/app.rb +7 -5
  225. data/tasks/thor/example.rb +23 -22
  226. data/tasks/thor/model.rb +7 -7
  227. data/tasks/thor/scaffold.rb +23 -23
  228. data/tasks/thor/templates/generator/example_app/app/v1/resources/user.rb +0 -8
  229. data/tasks/thor/templates/generator/scaffold/implementation/resources/item.rb +1 -2
  230. metadata +72 -84
  231. data/MAINTAINERS +0 -2
  232. data/TODO.md +0 -25
  233. data/spec/praxis/api_resource_spec.rb +0 -0
  234. data/spec/praxis/dispatcher_spec.rb +0 -0
  235. data/spec/spec_app/app/responses/bulk_response.rb +0 -0
@@ -1,24 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Praxis::Bootloader do
4
6
  let(:application) do
5
- instance_double("Praxis::Application", config: "config", root: "root", plugins: {}, file_layout: {} )
7
+ instance_double('Praxis::Application', config: 'config', root: 'root', plugins: {}, file_layout: {})
6
8
  end
7
9
 
8
- subject(:bootloader) {Praxis::Bootloader.new(application)}
10
+ subject(:bootloader) { Praxis::Bootloader.new(application) }
9
11
 
10
12
  context 'attributes' do
11
- its(:application) {should be(application)}
13
+ its(:application) { should be(application) }
12
14
  it 'stages' do
13
- init_stages = [:environment, :plugins, :initializers, :lib, :design, :app, :routing, :warn_unloaded_files]
14
- expect(bootloader.stages.map {|s| s.name}).to eq(init_stages)
15
+ init_stages = %i[environment plugins initializers lib design app routing warn_unloaded_files]
16
+ expect(bootloader.stages.map(&:name)).to eq(init_stages)
15
17
  end
16
- its(:config) {should be(application.config)}
17
- its(:root) {should be(application.root)}
18
+ its(:config) { should be(application.config) }
19
+ its(:root) { should be(application.root) }
18
20
  end
19
21
 
20
- context ".run" do
21
- it "should call setup and run for all the stages" do
22
+ context '.run' do
23
+ it 'should call setup and run for all the stages' do
22
24
  bootloader.stages.each do |s|
23
25
  expect(s).to receive(:setup!).once
24
26
  expect(s).to receive(:run).once
@@ -26,46 +28,46 @@ describe Praxis::Bootloader do
26
28
  bootloader.run
27
29
  end
28
30
  end
29
- context ".delete_stage" do
30
- it "delete valid stage" do
31
+ context '.delete_stage' do
32
+ it 'delete valid stage' do
31
33
  bootloader.delete_stage(:app)
32
34
  expect(bootloader.stages.include?(:app)).to be(false)
33
35
  end
34
36
 
35
- it "raise errors when deleting invalid stage" do
36
- expect{bootloader.delete_stage(:unexistent_stage)}.to raise_error(Praxis::Exceptions::StageNotFound)
37
+ it 'raise errors when deleting invalid stage' do
38
+ expect { bootloader.delete_stage(:unexistent_stage) }.to raise_error(Praxis::Exceptions::StageNotFound)
37
39
  end
38
40
  end
39
41
 
40
- context ".before" do
41
- it "run before block of first element in stage_path" do
42
+ context '.before' do
43
+ it 'run before block of first element in stage_path' do
42
44
  stage = bootloader.stages.first
43
45
  allow(stage).to receive(:before).and_return('before!')
44
46
  expect(bootloader.before(stage.name)).to eq('before!')
45
47
  end
46
48
 
47
- it "raises when given an invalid stage name" do
48
- expect{
49
+ it 'raises when given an invalid stage name' do
50
+ expect do
49
51
  bootloader.before('nope!')
50
- }.to raise_error(Praxis::Exceptions::StageNotFound,/Error running a before block for stage nope!/)
52
+ end.to raise_error(Praxis::Exceptions::StageNotFound, /Error running a before block for stage nope!/)
51
53
  end
52
54
  end
53
55
 
54
- context ".after" do
55
- it "run before block of first element in stage_path" do
56
+ context '.after' do
57
+ it 'run before block of first element in stage_path' do
56
58
  stage = bootloader.stages.first
57
59
  allow(stage).to receive(:after).and_return('after!')
58
60
  expect(bootloader.after(stage.name)).to eq('after!')
59
61
  end
60
62
 
61
- it "raises when given an invalid stage name" do
62
- expect{
63
+ it 'raises when given an invalid stage name' do
64
+ expect do
63
65
  bootloader.after('nope!')
64
- }.to raise_error(Praxis::Exceptions::StageNotFound,/Error running an after block for stage nope!/)
66
+ end.to raise_error(Praxis::Exceptions::StageNotFound, /Error running an after block for stage nope!/)
65
67
  end
66
68
  end
67
69
 
68
- context ".use" do
70
+ context '.use' do
69
71
  let(:plugin) do
70
72
  Class.new(Praxis::Plugin) do
71
73
  def config_key
@@ -74,27 +76,27 @@ describe Praxis::Bootloader do
74
76
  end
75
77
  end
76
78
 
77
- it "plugin add to application" do
79
+ it 'plugin add to application' do
78
80
  bootloader.use(plugin)
79
81
  expect(bootloader.application.plugins[:foo].class).to be(plugin)
80
82
  end
81
83
 
82
- it "complains if a plugin with same name already registered" do
84
+ it 'complains if a plugin with same name already registered' do
83
85
  bootloader.use(plugin)
84
86
  expect do
85
87
  bootloader.use(plugin)
86
- end.to raise_error /another plugin (.*) is already registered with key: foo/
88
+ end.to raise_error(/another plugin (.*) is already registered with key: foo/)
87
89
  end
88
- context "defaults config_key" do
90
+ context 'defaults config_key' do
89
91
  let(:plugin_two) do
90
92
  Class.new(Praxis::Plugin) do
91
93
  def self.name
92
- "Two" # Need this to avoid creating a true named class.
94
+ 'Two' # Need this to avoid creating a true named class.
93
95
  end
94
96
  end
95
97
  end
96
98
 
97
- it "to the class name" do
99
+ it 'to the class name' do
98
100
  bootloader.use(plugin_two)
99
101
  expect(bootloader.application.plugins[:two].class).to be(plugin_two)
100
102
  end
@@ -1,41 +1,43 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Praxis::Callbacks do
4
- let(:controller){ double("controller", request: "request") }
5
-
6
+ let(:controller) { double('controller', request: 'request') }
7
+
6
8
  subject do
7
- Class.new {
9
+ Class.new do
8
10
  include Praxis::Callbacks
9
11
 
10
- # implements PeopleResource
12
+ # implements PeopleResource
11
13
 
12
- before :validate, actions: [:index] do |controller|
13
- "before"
14
+ before :validate, actions: [:index] do |_controller|
15
+ 'before'
14
16
  end
15
17
 
16
18
  before actions: [:show] do |controller|
17
19
  end
18
20
 
19
- after :response, actions: [:show] do |controller|
20
- "after"
21
+ after :response, actions: [:show] do |_controller|
22
+ 'after'
21
23
  end
22
24
 
23
- around :action , actions: [:foobar] do |controller, callee|
25
+ around :action, actions: [:foobar] do |controller, callee|
24
26
  controller.request
25
27
  callee.call
26
28
  end
27
- }
29
+ end
28
30
  end
29
-
31
+
30
32
  context '.before' do
31
33
  let(:validate_conditions) { subject.before_callbacks[[:validate]][0][0] }
32
34
  let(:validate_block) { subject.before_callbacks[[:validate]][0][1] }
33
35
 
34
36
  it 'sets up the before_callbacks' do
35
37
  expect(subject.before_callbacks.keys).to match_array([[:validate], [:action]])
36
- expect(validate_conditions).to eq({:actions => [:index]})
38
+ expect(validate_conditions).to eq({ actions: [:index] })
37
39
  expect(validate_block).to be_kind_of(Proc)
38
- expect(validate_block.call(controller)).to eq("before")
40
+ expect(validate_block.call(controller)).to eq('before')
39
41
  end
40
42
  end
41
43
 
@@ -45,63 +47,61 @@ describe Praxis::Callbacks do
45
47
 
46
48
  it 'sets up the after_callbacks' do
47
49
  expect(subject.after_callbacks.keys).to match_array([[:response]])
48
- expect(response_conditions).to eq({:actions => [:show]})
50
+ expect(response_conditions).to eq({ actions: [:show] })
49
51
  expect(response_block).to be_kind_of(Proc)
50
- expect(response_block.call(controller)).to eq("after")
52
+ expect(response_block.call(controller)).to eq('after')
51
53
  end
52
54
  end
53
-
54
55
 
55
56
  context '.around' do
56
- let(:callee_result){ "result" }
57
- let(:callee){ double("callee", call: callee_result) }
57
+ let(:callee_result) { 'result' }
58
+ let(:callee) { double('callee', call: callee_result) }
58
59
  let(:around_conditions) { subject.around_callbacks[[:action]][0][0] }
59
60
  let(:around_block) { subject.around_callbacks[[:action]][0][1] }
60
61
 
61
62
  it 'sets up the before_callbacks' do
62
63
  expect(subject.around_callbacks.keys).to match_array([[:action]])
63
- expect(around_conditions).to eq({:actions => [:foobar]})
64
+ expect(around_conditions).to eq({ actions: [:foobar] })
64
65
  expect(around_block).to be_kind_of(Proc)
65
66
  end
66
67
  it 'passes the right parameters to the block call' do
67
68
  expect(controller).to receive(:request)
68
69
  expect(callee).to receive(:call)
69
- expect(around_block.call( controller,callee )).to eq(callee_result)
70
+ expect(around_block.call(controller, callee)).to eq(callee_result)
70
71
  end
71
72
  end
72
-
73
+
73
74
  # DONT DO THIS...this is just a test to show what would happen
74
75
  context 'inheriting callbacks from base classes ' do
75
- let!(:child1) {
76
+ let!(:child1) do
76
77
  Class.new(subject) do
77
- before actions: [:child1] do |controller|
78
- "before show child1"
78
+ before actions: [:child1] do |_controller|
79
+ 'before show child1'
79
80
  end
80
81
  end
81
- }
82
- let!(:child2) {
82
+ end
83
+ let!(:child2) do
83
84
  Class.new(subject) do
84
- before actions: [:child2] do |controller|
85
- "before show child2"
85
+ before actions: [:child2] do |_controller|
86
+ 'before show child2'
86
87
  end
87
88
  end
88
- }
89
+ end
89
90
 
90
91
  describe '.before_callbacks (but same for after and around)' do
91
92
  context 'for child1 (and viceversa for child2)' do
92
- let(:inherited_callbacks){ child1.before_callbacks }
93
- it "will inherits not just the base callbacks, but child2 also!" do
93
+ let(:inherited_callbacks) { child1.before_callbacks }
94
+ it 'will inherits not just the base callbacks, but child2 also!' do
94
95
  expect(inherited_callbacks).to be_a(Hash)
95
- expect(inherited_callbacks.keys).to eq([[:validate],[:action]])
96
+ expect(inherited_callbacks.keys).to eq([[:validate], [:action]])
96
97
  action_callbacks = inherited_callbacks[[:action]]
97
98
  expect(action_callbacks).to have(3).items
98
- action_callback_options = action_callbacks.map{|options, block| options}
99
- expect(action_callback_options).to eq([{:actions=>[:show]},
100
- {:actions=>[:child1]},
101
- {:actions=>[:child2]}])
99
+ action_callback_options = action_callbacks.map { |options, _block| options }
100
+ expect(action_callback_options).to eq([{ actions: [:show] },
101
+ { actions: [:child1] },
102
+ { actions: [:child2] }])
102
103
  end
103
104
  end
104
105
  end
105
-
106
106
  end
107
107
  end
@@ -1,10 +1,10 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- describe Praxis::Collection do
3
+ require 'spec_helper'
4
4
 
5
+ describe Praxis::Collection do
5
6
  let(:member_type) { Volume }
6
7
 
7
-
8
8
  subject!(:collection) do
9
9
  Praxis::Collection.of(member_type)
10
10
  end
@@ -40,15 +40,14 @@ describe Praxis::Collection do
40
40
 
41
41
  context '.member_type' do
42
42
  subject(:collection) do
43
- class Team < Praxis::Collection
43
+ Class.new(Praxis::Collection) do
44
44
  member_type Person
45
45
  end
46
- Team
47
46
  end
48
- its(:member_type){ should be(Person) }
49
- its(:member_attribute){ should be_kind_of(Attributor::Attribute) }
50
- its('member_attribute.type'){ should be(Person) }
51
- its(:identifier) { should eq Person.identifier + "; type=collection" }
47
+ its(:member_type) { should be(Person) }
48
+ its(:member_attribute) { should be_kind_of(Attributor::Attribute) }
49
+ its('member_attribute.type') { should be(Person) }
50
+ its(:identifier) { should eq Person.identifier + '; type=collection' } # rubocop:disable Style/StringConcatenation
52
51
  end
53
52
 
54
53
  context '.load' do
@@ -60,15 +59,14 @@ describe Praxis::Collection do
60
59
  }
61
60
  end
62
61
 
63
- let(:snapshots_data) {
62
+ let(:snapshots_data) do
64
63
  nil
65
- }
66
-
64
+ end
67
65
 
68
66
  context 'loading an array' do
69
67
  let(:snapshots_data) do
70
- [{id: 1, name: 'snapshot-1'},
71
- {id: 2, name: 'snapshot-2'}]
68
+ [{ id: 1, name: 'snapshot-1' },
69
+ { id: 2, name: 'snapshot-2' }]
72
70
  end
73
71
 
74
72
  let(:volume) { Volume.load(volume_data) }
@@ -82,12 +80,9 @@ describe Praxis::Collection do
82
80
  expect(snapshots[1].id).to eq(2)
83
81
  expect(snapshots[1].name).to eq('snapshot-2')
84
82
  end
85
-
86
83
  end
87
84
  end
88
85
 
89
-
90
-
91
86
  context '#render' do
92
87
  context 'for members' do
93
88
  let(:example) { Volume.example('example-volume') }
@@ -110,15 +105,14 @@ describe Praxis::Collection do
110
105
  }
111
106
  end
112
107
 
113
- let(:snapshots_data) {
108
+ let(:snapshots_data) do
114
109
  nil
115
- }
116
-
110
+ end
117
111
 
118
112
  context 'for an array' do
119
113
  let(:snapshots_data) do
120
- [{id: 1, name: 'snapshot-1'},
121
- {id: 2, name: 'snapshot-2'}]
114
+ [{ id: 1, name: 'snapshot-1' },
115
+ { id: 2, name: 'snapshot-2' }]
122
116
  end
123
117
 
124
118
  let(:volume) { Volume.load(volume_data) }
@@ -130,8 +124,8 @@ describe Praxis::Collection do
130
124
 
131
125
  context 'with invalid members' do
132
126
  let(:snapshots_data) do
133
- [{id: 1, name: 'invalid-1'},
134
- {id: 2, name: 'snapshot-2'}]
127
+ [{ id: 1, name: 'invalid-1' },
128
+ { id: 2, name: 'snapshot-2' }]
135
129
  end
136
130
 
137
131
  it 'returns the error' do
@@ -141,5 +135,4 @@ describe Praxis::Collection do
141
135
  end
142
136
  end
143
137
  end
144
-
145
138
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
3
4
 
4
5
  describe Praxis::ConfigHash do
5
6
  subject(:instance) { Praxis::ConfigHash.new(hash, &block) }
@@ -45,12 +46,12 @@ describe Praxis::ConfigHash do
45
46
  end
46
47
  context 'when keys already exist in the hash key' do
47
48
  it 'adds one value to the hash' do
48
- subject.one'newval'
49
- expect(subject.hash[:one]).to match_array(%w(existing newval))
49
+ subject.one 'newval'
50
+ expect(subject.hash[:one]).to match_array(%w[existing newval])
50
51
  end
51
52
  it 'adds multiple values to the hash key' do
52
53
  subject.one 'newval', 'other1', 'other2'
53
- expect(subject.hash[:one]).to match_array(%w(existing newval other1 other2))
54
+ expect(subject.hash[:one]).to match_array(%w[existing newval other1 other2])
54
55
  end
55
56
  context 'when passing a value and a block' do
56
57
  let(:my_block) { proc {} }
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Praxis::Config do
@@ -7,7 +9,7 @@ describe Praxis::Config do
7
9
 
8
10
  describe '#initialize' do
9
11
  it 'its type is a Struct type' do
10
- expect( config.attribute.type < Attributor::Struct).to be(true)
12
+ expect(config.attribute.type < Attributor::Struct).to be(true)
11
13
  end
12
14
  it 'has no value' do
13
15
  expect(config.get.attributes).to eq({})
@@ -17,26 +19,26 @@ describe Praxis::Config do
17
19
  describe '#define' do
18
20
  context 'using a block' do
19
21
  context 'at the top level' do
20
- let(:key) { nil}
22
+ let(:key) { nil }
21
23
  before do
22
24
  config.define key do
23
25
  attribute :foo, String
24
26
  end
25
27
  end
26
-
28
+
27
29
  it 'defines a Struct-type configuration under :foo' do
28
30
  expect(config.attribute.attributes.keys).to eq [:foo]
29
31
  end
30
-
32
+
31
33
  context 'called again with new attributes' do
32
34
  before do
33
35
  config.define key do
34
36
  attribute :bar, String
35
37
  end
36
38
  end
37
-
39
+
38
40
  it 'adds the additional attributes to the Struct under :bar' do
39
- expect(config.attribute.attributes.keys).to eq [:foo, :bar]
41
+ expect(config.attribute.attributes.keys).to eq %i[foo bar]
40
42
  end
41
43
  end
42
44
  end
@@ -48,34 +50,33 @@ describe Praxis::Config do
48
50
  end
49
51
  end
50
52
  it 'when it does not exist, it creates a whole new subkey Struct containing one key' do
51
- expect(config.attribute.attributes[:subkey].attributes.keys).to eq [:inside]
53
+ expect(config.attribute.attributes[:subkey].attributes.keys).to eq [:inside]
52
54
  end
53
55
  it 'when it already exists, will fail if it is of a different type' do
54
- expect{
56
+ expect do
55
57
  config.define key, Attributor::Hash
56
- }.to raise_error(/Incompatible type received for extending configuration key/)
58
+ end.to raise_error(/Incompatible type received for extending configuration key/)
57
59
  end
58
60
  it 'when it already exists, it add another subkey to the existing Struct' do
59
61
  config.define key do
60
- attribute :inside2, String
61
- end
62
- expect(config.attribute.attributes[:subkey].attributes.keys).to eq [:inside,:inside2]
62
+ attribute :inside2, String
63
+ end
64
+ expect(config.attribute.attributes[:subkey].attributes.keys).to eq %i[inside inside2]
63
65
  end
64
-
65
66
  end
66
67
  end
67
-
68
+
68
69
  context 'using a direct type' do
69
- let(:config_type){ Attributor::Hash.of(key:String) }
70
- let(:config_opts){ {} }
71
- let(:config_key){ :foo }
72
-
70
+ let(:config_type) { Attributor::Hash.of(key: String) }
71
+ let(:config_opts) { {} }
72
+ let(:config_key) { :foo }
73
+
73
74
  it 'it is not allowed if its for the top key' do
74
- expect{
75
+ expect do
75
76
  config.define nil, config_type, **config_opts
76
- }.to raise_error(/You cannot define the top level configuration with a non-Struct type/)
77
+ end.to raise_error(/You cannot define the top level configuration with a non-Struct type/)
77
78
  end
78
-
79
+
79
80
  before do
80
81
  config.define config_key, config_type, **config_opts
81
82
  end
@@ -84,10 +85,10 @@ describe Praxis::Config do
84
85
  expect(config.attribute.attributes[config_key].type).to be(config_type)
85
86
  end
86
87
  it 'does not allow to redefine types that are not Structs' do
87
- expect{
88
+ expect do
88
89
  config.define config_key, Attributor::Hash
89
- }.to raise_error(Praxis::Exceptions::InvalidConfiguration,
90
- /Incompatible type received for extending configuration key/)
90
+ end.to raise_error(Praxis::Exceptions::InvalidConfiguration,
91
+ /Incompatible type received for extending configuration key/)
91
92
  end
92
93
  end
93
94
  end
@@ -105,14 +106,14 @@ describe Praxis::Config do
105
106
  config.define do
106
107
  attribute :foo, String, required: true
107
108
  end
108
- expect{ config.set({}) }.to raise_error(Praxis::Exceptions::ConfigValidation)
109
+ expect { config.set({}) }.to raise_error(Praxis::Exceptions::ConfigValidation)
109
110
  end
110
111
 
111
112
  it 'fails when config cannot be loaded' do
112
113
  config.define do
113
114
  attribute :foo, Integer, required: true
114
115
  end
115
- expect{ config.set({foo: 'five'}) }.to raise_error(Praxis::Exceptions::ConfigLoad)
116
+ expect { config.set({ foo: 'five' }) }.to raise_error(Praxis::Exceptions::ConfigLoad)
116
117
  end
117
118
  end
118
119
  end
@@ -1,29 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Praxis::Controller do
4
6
  subject do
5
- Class.new {
7
+ Class.new do
6
8
  include Praxis::Controller
7
9
 
8
10
  implements PeopleResource
9
11
 
10
12
  before :validate, actions: [:index] do
11
- "before"
13
+ 'before'
12
14
  end
13
15
 
14
16
  before actions: [:show] do
15
17
  end
16
18
 
17
19
  after :response, actions: [:show] do
18
- "after"
20
+ 'after'
19
21
  end
20
22
 
21
- def index
22
- end
23
+ def index; end
23
24
 
24
- def show
25
- end
26
- }
25
+ def show; end
26
+ end
27
27
  end
28
28
 
29
29
  context '.implements' do
@@ -31,5 +31,4 @@ describe Praxis::Controller do
31
31
  expect(subject).to eq(PeopleResource.controller)
32
32
  end
33
33
  end
34
-
35
34
  end