power_api 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +93 -90
  5. data/README.md +329 -75
  6. data/app/helpers/power_api/application_helper.rb +57 -0
  7. data/bin/clean_test_app +2 -0
  8. data/lib/generators/power_api/controller/controller_generator.rb +27 -15
  9. data/lib/generators/power_api/exposed_api_config/USAGE +5 -0
  10. data/lib/generators/power_api/exposed_api_config/exposed_api_config_generator.rb +58 -0
  11. data/lib/generators/power_api/install/install_generator.rb +2 -44
  12. data/lib/generators/power_api/internal_api_config/USAGE +5 -0
  13. data/lib/generators/power_api/internal_api_config/internal_api_config_generator.rb +31 -0
  14. data/lib/generators/power_api/version/version_generator.rb +2 -2
  15. data/lib/power_api/engine.rb +8 -1
  16. data/lib/power_api/errors.rb +2 -0
  17. data/lib/power_api/generator_helper/active_record_resource.rb +10 -6
  18. data/lib/power_api/generator_helper/ams_helper.rb +5 -11
  19. data/lib/power_api/generator_helper/api_helper.rb +61 -0
  20. data/lib/power_api/generator_helper/controller_helper.rb +45 -15
  21. data/lib/power_api/generator_helper/routes_helper.rb +22 -7
  22. data/lib/power_api/generator_helper/rspec_controller_helper.rb +306 -0
  23. data/lib/power_api/generator_helper/swagger_helper.rb +14 -24
  24. data/lib/power_api/generator_helpers.rb +2 -1
  25. data/lib/power_api/version.rb +1 -1
  26. data/spec/dummy/app/controllers/api/base_controller.rb +2 -0
  27. data/spec/dummy/app/controllers/api/internal/base_controller.rb +5 -0
  28. data/spec/dummy/app/controllers/api/internal/blogs_controller.rb +36 -0
  29. data/spec/dummy/app/serializers/api/internal/blog_serializer.rb +12 -0
  30. data/spec/dummy/config/initializers/active_model_serializers.rb +1 -0
  31. data/spec/dummy/config/initializers/api_pagination.rb +32 -0
  32. data/spec/dummy/config/routes.rb +2 -7
  33. data/spec/dummy/spec/helpers/power_api/application_helper_spec.rb +171 -0
  34. data/spec/dummy/spec/lib/power_api/generator_helper/ams_helper_spec.rb +50 -12
  35. data/spec/dummy/spec/lib/power_api/generator_helper/api_helper_spec.rb +115 -0
  36. data/spec/dummy/spec/lib/power_api/generator_helper/controller_helper_spec.rb +126 -34
  37. data/spec/dummy/spec/lib/power_api/generator_helper/routes_helper_spec.rb +29 -5
  38. data/spec/dummy/spec/lib/power_api/generator_helper/rspec_controller_helper_spec.rb +559 -0
  39. data/spec/dummy/spec/lib/power_api/generator_helper/swagger_helper_spec.rb +10 -20
  40. data/spec/dummy/spec/support/shared_examples/active_record_resource_atrributes.rb +22 -3
  41. metadata +27 -5
  42. data/lib/power_api/generator_helper/version_helper.rb +0 -16
  43. data/spec/dummy/spec/lib/power_api/generator_helper/version_helper_spec.rb +0 -55
@@ -3,6 +3,7 @@ shared_examples 'ActiveRecord resource attributes' do |attributes_key|
3
3
  describe "#resource_attributes" do
4
4
  let(:expected_attributes) do
5
5
  [
6
+ { name: :id, type: :integer, swagger_type: :integer, example: kind_of(Integer), required: false },
6
7
  { name: :title, type: :string, swagger_type: :string, example: "'Some title'", required: true },
7
8
  { name: :body, type: :text, swagger_type: :string, example: "'Some body'", required: true },
8
9
  { name: :created_at, type: :datetime, swagger_type: :string, example: "'1984-06-04 09:00'", required: false },
@@ -21,27 +22,30 @@ shared_examples 'ActiveRecord resource attributes' do |attributes_key|
21
22
  let(attributes_key) { %w{title body} }
22
23
  let(:expected_attributes) do
23
24
  [
25
+ { name: :id, type: :integer, swagger_type: :integer, example: kind_of(Integer), required: false },
24
26
  { name: :title, type: :string, swagger_type: :string, example: "'Some title'", required: true },
25
27
  { name: :body, type: :text, swagger_type: :string, example: "'Some body'", required: true }
26
28
  ]
27
29
  end
28
30
 
29
- it { expect(perform).to eq(expected_attributes) }
31
+ it { expect(perform).to match(expected_attributes) }
30
32
  end
31
33
 
32
34
  context "with attributes not present in model" do
33
35
  let(attributes_key) { %w{title bloody} }
34
36
  let(:expected_attributes) do
35
37
  [
38
+ { name: :id, type: :integer, swagger_type: :integer, example: kind_of(Integer), required: false },
36
39
  { name: :title, type: :string, swagger_type: :string, example: "'Some title'", required: true }
37
40
  ]
38
41
  end
39
42
 
40
- it { expect(perform).to eq(expected_attributes) }
43
+ it { expect(perform).to match(expected_attributes) }
41
44
  end
42
45
  end
43
46
 
44
47
  describe "#required_resource_attributes" do
48
+ let(:include_id) { false }
45
49
  let(:expected_attributes) do
46
50
  [
47
51
  { name: :title, type: :string, swagger_type: :string, example: "'Some title'", required: true },
@@ -50,10 +54,23 @@ shared_examples 'ActiveRecord resource attributes' do |attributes_key|
50
54
  end
51
55
 
52
56
  def perform
53
- resource.required_resource_attributes
57
+ resource.required_resource_attributes(include_id: include_id)
54
58
  end
55
59
 
56
60
  it { expect(perform).to eq(expected_attributes) }
61
+
62
+ context "with included id" do
63
+ let(:include_id) { true }
64
+ let(:expected_attributes) do
65
+ [
66
+ { name: :id, type: :integer, swagger_type: :integer, example: kind_of(Integer), required: false },
67
+ { name: :title, type: :string, swagger_type: :string, example: "'Some title'", required: true },
68
+ { name: :body, type: :text, swagger_type: :string, example: "'Some body'", required: true }
69
+ ]
70
+ end
71
+
72
+ it { expect(perform).to match(expected_attributes) }
73
+ end
57
74
  end
58
75
 
59
76
  describe "#required_attributes_names" do
@@ -88,6 +105,7 @@ shared_examples 'ActiveRecord resource attributes' do |attributes_key|
88
105
  describe "#attributes_names" do
89
106
  let(:expected_attributes) do
90
107
  [
108
+ :id,
91
109
  :title,
92
110
  :body,
93
111
  :created_at,
@@ -138,6 +156,7 @@ shared_examples 'ActiveRecord resource attributes' do |attributes_key|
138
156
  describe "#attributes_symbols_text_list" do
139
157
  let(:expected_result) do
140
158
  <<~ATTRS
159
+ :id,
141
160
  :title,
142
161
  :body,
143
162
  :created_at,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Platanus
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-06-22 00:00:00.000000000 Z
12
+ date: 2022-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -342,12 +342,17 @@ files:
342
342
  - app/models/power_api/application_record.rb
343
343
  - app/responders/api_responder.rb
344
344
  - app/views/layouts/power_api/application.html.erb
345
+ - bin/clean_test_app
345
346
  - bin/rails
346
347
  - config/routes.rb
347
348
  - lib/generators/power_api/controller/USAGE
348
349
  - lib/generators/power_api/controller/controller_generator.rb
350
+ - lib/generators/power_api/exposed_api_config/USAGE
351
+ - lib/generators/power_api/exposed_api_config/exposed_api_config_generator.rb
349
352
  - lib/generators/power_api/install/USAGE
350
353
  - lib/generators/power_api/install/install_generator.rb
354
+ - lib/generators/power_api/internal_api_config/USAGE
355
+ - lib/generators/power_api/internal_api_config/internal_api_config_generator.rb
351
356
  - lib/generators/power_api/version/USAGE
352
357
  - lib/generators/power_api/version/version_generator.rb
353
358
  - lib/power_api.rb
@@ -355,16 +360,17 @@ files:
355
360
  - lib/power_api/errors.rb
356
361
  - lib/power_api/generator_helper/active_record_resource.rb
357
362
  - lib/power_api/generator_helper/ams_helper.rb
363
+ - lib/power_api/generator_helper/api_helper.rb
358
364
  - lib/power_api/generator_helper/controller_actions_helper.rb
359
365
  - lib/power_api/generator_helper/controller_helper.rb
360
366
  - lib/power_api/generator_helper/pagination_helper.rb
361
367
  - lib/power_api/generator_helper/resource_helper.rb
362
368
  - lib/power_api/generator_helper/routes_helper.rb
369
+ - lib/power_api/generator_helper/rspec_controller_helper.rb
363
370
  - lib/power_api/generator_helper/rubocop_helper.rb
364
371
  - lib/power_api/generator_helper/simple_token_auth_helper.rb
365
372
  - lib/power_api/generator_helper/swagger_helper.rb
366
373
  - lib/power_api/generator_helper/template_builder_helper.rb
367
- - lib/power_api/generator_helper/version_helper.rb
368
374
  - lib/power_api/generator_helpers.rb
369
375
  - lib/power_api/version.rb
370
376
  - lib/tasks/power_api_tasks.rake
@@ -374,6 +380,9 @@ files:
374
380
  - spec/dummy/app/assets/stylesheets/application.css
375
381
  - spec/dummy/app/channels/application_cable/channel.rb
376
382
  - spec/dummy/app/channels/application_cable/connection.rb
383
+ - spec/dummy/app/controllers/api/base_controller.rb
384
+ - spec/dummy/app/controllers/api/internal/base_controller.rb
385
+ - spec/dummy/app/controllers/api/internal/blogs_controller.rb
377
386
  - spec/dummy/app/controllers/application_controller.rb
378
387
  - spec/dummy/app/controllers/concerns/api/deprecated_spec.rb
379
388
  - spec/dummy/app/controllers/concerns/api/error_spec.rb
@@ -386,6 +395,7 @@ files:
386
395
  - spec/dummy/app/models/blog.rb
387
396
  - spec/dummy/app/models/portfolio.rb
388
397
  - spec/dummy/app/models/user.rb
398
+ - spec/dummy/app/serializers/api/internal/blog_serializer.rb
389
399
  - spec/dummy/app/views/layouts/application.html.erb
390
400
  - spec/dummy/app/views/layouts/mailer.html.erb
391
401
  - spec/dummy/app/views/layouts/mailer.text.erb
@@ -401,6 +411,8 @@ files:
401
411
  - spec/dummy/config/environments/development.rb
402
412
  - spec/dummy/config/environments/production.rb
403
413
  - spec/dummy/config/environments/test.rb
414
+ - spec/dummy/config/initializers/active_model_serializers.rb
415
+ - spec/dummy/config/initializers/api_pagination.rb
404
416
  - spec/dummy/config/initializers/application_controller_renderer.rb
405
417
  - spec/dummy/config/initializers/assets.rb
406
418
  - spec/dummy/config/initializers/backtrace_silencers.rb
@@ -432,15 +444,17 @@ files:
432
444
  - spec/dummy/spec/factories/blogs.rb
433
445
  - spec/dummy/spec/factories/portfolios.rb
434
446
  - spec/dummy/spec/factories/users.rb
447
+ - spec/dummy/spec/helpers/power_api/application_helper_spec.rb
435
448
  - spec/dummy/spec/lib/power_api/generator_helper/ams_helper_spec.rb
449
+ - spec/dummy/spec/lib/power_api/generator_helper/api_helper_spec.rb
436
450
  - spec/dummy/spec/lib/power_api/generator_helper/controller_actions_helper_spec.rb
437
451
  - spec/dummy/spec/lib/power_api/generator_helper/controller_helper_spec.rb
438
452
  - spec/dummy/spec/lib/power_api/generator_helper/pagination_helper_spec.rb
439
453
  - spec/dummy/spec/lib/power_api/generator_helper/resource_helper_spec.rb
440
454
  - spec/dummy/spec/lib/power_api/generator_helper/routes_helper_spec.rb
455
+ - spec/dummy/spec/lib/power_api/generator_helper/rspec_controller_helper_spec.rb
441
456
  - spec/dummy/spec/lib/power_api/generator_helper/simple_token_auth_helper_spec.rb
442
457
  - spec/dummy/spec/lib/power_api/generator_helper/swagger_helper_spec.rb
443
- - spec/dummy/spec/lib/power_api/generator_helper/version_helper_spec.rb
444
458
  - spec/dummy/spec/support/shared_examples/active_record_resource.rb
445
459
  - spec/dummy/spec/support/shared_examples/active_record_resource_atrributes.rb
446
460
  - spec/dummy/spec/support/test_generator_helpers.rb
@@ -476,6 +490,9 @@ test_files:
476
490
  - spec/dummy/app/assets/stylesheets/application.css
477
491
  - spec/dummy/app/channels/application_cable/channel.rb
478
492
  - spec/dummy/app/channels/application_cable/connection.rb
493
+ - spec/dummy/app/controllers/api/base_controller.rb
494
+ - spec/dummy/app/controllers/api/internal/base_controller.rb
495
+ - spec/dummy/app/controllers/api/internal/blogs_controller.rb
479
496
  - spec/dummy/app/controllers/application_controller.rb
480
497
  - spec/dummy/app/controllers/concerns/api/deprecated_spec.rb
481
498
  - spec/dummy/app/controllers/concerns/api/error_spec.rb
@@ -488,6 +505,7 @@ test_files:
488
505
  - spec/dummy/app/models/blog.rb
489
506
  - spec/dummy/app/models/portfolio.rb
490
507
  - spec/dummy/app/models/user.rb
508
+ - spec/dummy/app/serializers/api/internal/blog_serializer.rb
491
509
  - spec/dummy/app/views/layouts/application.html.erb
492
510
  - spec/dummy/app/views/layouts/mailer.html.erb
493
511
  - spec/dummy/app/views/layouts/mailer.text.erb
@@ -503,6 +521,8 @@ test_files:
503
521
  - spec/dummy/config/environments/development.rb
504
522
  - spec/dummy/config/environments/production.rb
505
523
  - spec/dummy/config/environments/test.rb
524
+ - spec/dummy/config/initializers/active_model_serializers.rb
525
+ - spec/dummy/config/initializers/api_pagination.rb
506
526
  - spec/dummy/config/initializers/application_controller_renderer.rb
507
527
  - spec/dummy/config/initializers/assets.rb
508
528
  - spec/dummy/config/initializers/backtrace_silencers.rb
@@ -534,15 +554,17 @@ test_files:
534
554
  - spec/dummy/spec/factories/blogs.rb
535
555
  - spec/dummy/spec/factories/portfolios.rb
536
556
  - spec/dummy/spec/factories/users.rb
557
+ - spec/dummy/spec/helpers/power_api/application_helper_spec.rb
537
558
  - spec/dummy/spec/lib/power_api/generator_helper/ams_helper_spec.rb
559
+ - spec/dummy/spec/lib/power_api/generator_helper/api_helper_spec.rb
538
560
  - spec/dummy/spec/lib/power_api/generator_helper/controller_actions_helper_spec.rb
539
561
  - spec/dummy/spec/lib/power_api/generator_helper/controller_helper_spec.rb
540
562
  - spec/dummy/spec/lib/power_api/generator_helper/pagination_helper_spec.rb
541
563
  - spec/dummy/spec/lib/power_api/generator_helper/resource_helper_spec.rb
542
564
  - spec/dummy/spec/lib/power_api/generator_helper/routes_helper_spec.rb
565
+ - spec/dummy/spec/lib/power_api/generator_helper/rspec_controller_helper_spec.rb
543
566
  - spec/dummy/spec/lib/power_api/generator_helper/simple_token_auth_helper_spec.rb
544
567
  - spec/dummy/spec/lib/power_api/generator_helper/swagger_helper_spec.rb
545
- - spec/dummy/spec/lib/power_api/generator_helper/version_helper_spec.rb
546
568
  - spec/dummy/spec/support/shared_examples/active_record_resource.rb
547
569
  - spec/dummy/spec/support/shared_examples/active_record_resource_atrributes.rb
548
570
  - spec/dummy/spec/support/test_generator_helpers.rb
@@ -1,16 +0,0 @@
1
- module PowerApi::GeneratorHelper::VersionHelper
2
- extend ActiveSupport::Concern
3
-
4
- included do
5
- attr_reader :version_number
6
- end
7
-
8
- def version_number=(value)
9
- @version_number = value.to_s.to_i
10
- raise PowerApi::GeneratorError.new("invalid version number") if version_number < 1
11
- end
12
-
13
- def first_version?
14
- version_number.to_i == 1
15
- end
16
- end
@@ -1,55 +0,0 @@
1
- RSpec.describe PowerApi::GeneratorHelper::VersionHelper, type: :generator do
2
- describe "#version_number" do
3
- def perform
4
- generators_helper.version_number
5
- end
6
-
7
- it { expect(perform).to eq(1) }
8
- end
9
-
10
- describe "version_number=" do
11
- context "with invalid version number" do
12
- let(:version_number) { "A" }
13
-
14
- it { expect { generators_helper }.to raise_error("invalid version number") }
15
- end
16
-
17
- context "with zero version number" do
18
- let(:version_number) { 0 }
19
-
20
- it { expect { generators_helper }.to raise_error("invalid version number") }
21
- end
22
-
23
- context "with nil version number" do
24
- let(:version_number) { nil }
25
-
26
- it { expect { generators_helper }.to raise_error("invalid version number") }
27
- end
28
-
29
- context "with nil blank number" do
30
- let(:version_number) { "" }
31
-
32
- it { expect { generators_helper }.to raise_error("invalid version number") }
33
- end
34
-
35
- context "with negative version number" do
36
- let(:version_number) { -1 }
37
-
38
- it { expect { generators_helper }.to raise_error("invalid version number") }
39
- end
40
- end
41
-
42
- describe "#first_version?" do
43
- def perform
44
- generators_helper.first_version?
45
- end
46
-
47
- it { expect(perform).to eq(true) }
48
-
49
- context "when version in not first version" do
50
- let(:version_number) { "2" }
51
-
52
- it { expect(perform).to eq(false) }
53
- end
54
- end
55
- end