power_api 0.2.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +104 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.rubocop.yml +0 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +19 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +189 -166
- data/README.md +365 -103
- data/app/controllers/power_api/base_controller.rb +0 -1
- data/app/helpers/power_api/application_helper.rb +57 -0
- data/bin/clean_test_app +2 -0
- data/lib/generators/power_api/controller/controller_generator.rb +27 -15
- data/lib/generators/power_api/exposed_api_config/USAGE +5 -0
- data/lib/generators/power_api/exposed_api_config/exposed_api_config_generator.rb +58 -0
- data/lib/generators/power_api/install/install_generator.rb +2 -44
- data/lib/generators/power_api/internal_api_config/USAGE +5 -0
- data/lib/generators/power_api/internal_api_config/internal_api_config_generator.rb +31 -0
- data/lib/generators/power_api/version/version_generator.rb +2 -2
- data/lib/power_api/engine.rb +6 -1
- data/lib/power_api/errors.rb +2 -0
- data/lib/power_api/generator_helper/active_record_resource.rb +10 -6
- data/lib/power_api/generator_helper/ams_helper.rb +5 -11
- data/lib/power_api/generator_helper/api_helper.rb +61 -0
- data/lib/power_api/generator_helper/controller_helper.rb +45 -15
- data/lib/power_api/generator_helper/routes_helper.rb +22 -7
- data/lib/power_api/generator_helper/rspec_controller_helper.rb +306 -0
- data/lib/power_api/generator_helper/swagger_helper.rb +14 -24
- data/lib/power_api/generator_helpers.rb +2 -1
- data/lib/power_api/version.rb +1 -1
- data/power_api.gemspec +3 -2
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/config/manifest.js +0 -2
- data/spec/dummy/app/controllers/api/base_controller.rb +2 -0
- data/spec/dummy/app/controllers/api/internal/base_controller.rb +5 -0
- data/spec/dummy/app/controllers/api/internal/blogs_controller.rb +36 -0
- data/spec/dummy/app/controllers/application_controller.rb +0 -1
- data/spec/dummy/app/{assets/javascripts → javascript/packs}/application.js +2 -0
- data/spec/dummy/app/jobs/application_job.rb +5 -0
- data/spec/dummy/app/serializers/api/internal/blog_serializer.rb +12 -0
- data/spec/dummy/app/views/layouts/application.html.erb +3 -2
- data/spec/dummy/bin/rails +2 -2
- data/spec/dummy/bin/rake +2 -2
- data/spec/dummy/bin/setup +7 -12
- data/spec/dummy/config/application.rb +12 -16
- data/spec/dummy/config/boot.rb +1 -1
- data/spec/dummy/config/cable.yml +2 -2
- data/spec/dummy/config/database.yml +8 -16
- data/spec/dummy/config/environment.rb +1 -1
- data/spec/dummy/config/environments/development.rb +28 -6
- data/spec/dummy/config/environments/production.rb +45 -16
- data/spec/dummy/config/environments/test.rb +24 -7
- data/spec/dummy/config/initializers/active_model_serializers.rb +1 -0
- data/spec/dummy/config/initializers/api_pagination.rb +32 -0
- data/spec/dummy/config/initializers/assets.rb +0 -2
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -3
- data/spec/dummy/config/initializers/content_security_policy.rb +28 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +3 -1
- data/spec/dummy/config/initializers/permissions_policy.rb +11 -0
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/puma.rb +14 -27
- data/spec/dummy/config/routes.rb +2 -7
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +2 -1
- data/spec/dummy/spec/helpers/power_api/application_helper_spec.rb +171 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/ams_helper_spec.rb +50 -12
- data/spec/dummy/spec/lib/power_api/generator_helper/api_helper_spec.rb +115 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/controller_helper_spec.rb +126 -34
- data/spec/dummy/spec/lib/power_api/generator_helper/routes_helper_spec.rb +29 -5
- data/spec/dummy/spec/lib/power_api/generator_helper/rspec_controller_helper_spec.rb +559 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/swagger_helper_spec.rb +10 -20
- data/spec/dummy/spec/support/shared_examples/active_record_resource_atrributes.rb +22 -3
- metadata +114 -87
- data/.hound.yml +0 -4
- data/.travis.yml +0 -16
- data/app/controllers/concerns/api/versioned.rb +0 -36
- data/lib/power_api/generator_helper/version_helper.rb +0 -16
- data/spec/dummy/app/assets/javascripts/cable.js +0 -13
- data/spec/dummy/app/controllers/concerns/api/versioned_spec.rb +0 -64
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/update +0 -29
- data/spec/dummy/bin/yarn +0 -11
- data/spec/dummy/config/secrets.yml +0 -32
- data/spec/dummy/config/spring.rb +0 -6
- data/spec/dummy/spec/lib/power_api/generator_helper/version_helper_spec.rb +0 -55
@@ -0,0 +1,171 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PowerApi::ApplicationHelper do
|
4
|
+
describe "#serialize_resource" do
|
5
|
+
let(:resource) do
|
6
|
+
build(
|
7
|
+
:blog,
|
8
|
+
id: 1,
|
9
|
+
title: "T",
|
10
|
+
portfolio_id: 2,
|
11
|
+
body: "B",
|
12
|
+
created_at: "2022-01-28T20:30:00.000Z",
|
13
|
+
updated_at: "2022-01-28T20:40:00.000Z"
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:options) { {} }
|
18
|
+
|
19
|
+
def data
|
20
|
+
helper.serialize_resource(resource, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:expected_serialized_data) do
|
24
|
+
<<~DATA.strip
|
25
|
+
{\"id\":1,\"title\":\"T\",\"body\":\"B\",\"createdAt\":\"2022-01-28T20:30:00.000Z\",\"updatedAt\":\"2022-01-28T20:40:00.000Z\",\"portfolioId\":2}
|
26
|
+
DATA
|
27
|
+
end
|
28
|
+
|
29
|
+
it { expect(data).to eq(expected_serialized_data) }
|
30
|
+
|
31
|
+
context "with fields option" do
|
32
|
+
let(:options) do
|
33
|
+
{
|
34
|
+
fields: [:id, :body]
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:expected_serialized_data) do
|
39
|
+
<<~DATA.strip
|
40
|
+
{\"id\":1,\"body\":\"B\"}
|
41
|
+
DATA
|
42
|
+
end
|
43
|
+
|
44
|
+
it { expect(data).to eq(expected_serialized_data) }
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with key_transform option" do
|
48
|
+
let(:options) do
|
49
|
+
{
|
50
|
+
key_transform: :unaltered
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:expected_serialized_data) do
|
55
|
+
<<~DATA.strip
|
56
|
+
{\"id\":1,\"title\":\"T\",\"body\":\"B\",\"created_at\":\"2022-01-28T20:30:00.000Z\",\"updated_at\":\"2022-01-28T20:40:00.000Z\",\"portfolio_id\":2}
|
57
|
+
DATA
|
58
|
+
end
|
59
|
+
|
60
|
+
it { expect(data).to eq(expected_serialized_data) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with include_root option" do
|
64
|
+
let(:options) do
|
65
|
+
{
|
66
|
+
include_root: true
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:expected_serialized_data) do
|
71
|
+
<<~DATA.strip
|
72
|
+
{"blog":{"id":1,"title":"T","body":"B","createdAt":"2022-01-28T20:30:00.000Z","updatedAt":"2022-01-28T20:40:00.000Z","portfolioId":2}}
|
73
|
+
DATA
|
74
|
+
end
|
75
|
+
|
76
|
+
it { expect(data).to eq(expected_serialized_data) }
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with collection resource" do
|
80
|
+
let(:options) do
|
81
|
+
{
|
82
|
+
include_root: false,
|
83
|
+
fields: [:body]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
87
|
+
let(:resource) do
|
88
|
+
create_list(:blog, 2)
|
89
|
+
end
|
90
|
+
|
91
|
+
let(:expected_serialized_data) do
|
92
|
+
<<~DATA.strip
|
93
|
+
[{\"body\":\"MyText\"},{\"body\":\"MyText\"}]
|
94
|
+
DATA
|
95
|
+
end
|
96
|
+
|
97
|
+
it { expect(data).to eq(expected_serialized_data) }
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with invalid resource" do
|
101
|
+
let(:resource) do
|
102
|
+
{ invalid: "resource" }
|
103
|
+
end
|
104
|
+
|
105
|
+
it { expect { data }.to raise_error(PowerApi::InvalidSerializableResource, /Invalid Hash/) }
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with hash output_format" do
|
109
|
+
let(:options) do
|
110
|
+
{
|
111
|
+
output_format: :hash
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
115
|
+
let(:expected_serialized_data) do
|
116
|
+
{
|
117
|
+
body: "B",
|
118
|
+
created_at: "2022-01-28 20:30:00.000000000 +0000",
|
119
|
+
id: 1,
|
120
|
+
portfolio_id: 2,
|
121
|
+
title: "T",
|
122
|
+
updated_at: "2022-01-28 20:40:00.000000000 +0000"
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
it { expect(data).to eq(expected_serialized_data) }
|
127
|
+
|
128
|
+
context "with key_transform option" do
|
129
|
+
before { options[:key_transform] = :camel_lower }
|
130
|
+
|
131
|
+
it { expect(data).to eq(expected_serialized_data) }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
context "with invalid output option" do
|
136
|
+
let(:options) do
|
137
|
+
{ output_format: "invalid" }
|
138
|
+
end
|
139
|
+
|
140
|
+
it { expect { data }.to raise_error(PowerApi::InvalidSerializerOutputFormat, /:json, :hash/) }
|
141
|
+
end
|
142
|
+
|
143
|
+
context "with meta option" do
|
144
|
+
let(:options) do
|
145
|
+
{
|
146
|
+
meta: { hola: "platanus" }
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
let(:expected_serialized_data) do
|
151
|
+
<<~DATA.strip
|
152
|
+
{\"id\":1,\"title\":\"T\",\"body\":\"B\",\"createdAt\":\"2022-01-28T20:30:00.000Z\",\"updatedAt\":\"2022-01-28T20:40:00.000Z\",\"portfolioId\":2}
|
153
|
+
DATA
|
154
|
+
end
|
155
|
+
|
156
|
+
it { expect(data).to eq(expected_serialized_data) }
|
157
|
+
|
158
|
+
context "with include_root option" do
|
159
|
+
before { options[:include_root] = true }
|
160
|
+
|
161
|
+
let(:expected_serialized_data) do
|
162
|
+
<<~DATA.strip
|
163
|
+
{\"blog\":{\"id\":1,\"title\":\"T\",\"body\":\"B\",\"createdAt\":\"2022-01-28T20:30:00.000Z\",\"updatedAt\":\"2022-01-28T20:40:00.000Z\",\"portfolioId\":2},\"meta\":{\"hola\":\"platanus\"}}
|
164
|
+
DATA
|
165
|
+
end
|
166
|
+
|
167
|
+
it { expect(data).to eq(expected_serialized_data) }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
@@ -11,7 +11,7 @@ RSpec.describe PowerApi::GeneratorHelper::AmsHelper, type: :generator do
|
|
11
11
|
|
12
12
|
describe "#ams_serializers_path" do
|
13
13
|
let(:expected_path) do
|
14
|
-
"app/serializers/api/v1/.gitkeep"
|
14
|
+
"app/serializers/api/exposed/v1/.gitkeep"
|
15
15
|
end
|
16
16
|
|
17
17
|
def perform
|
@@ -24,7 +24,17 @@ RSpec.describe PowerApi::GeneratorHelper::AmsHelper, type: :generator do
|
|
24
24
|
let(:version_number) { "2" }
|
25
25
|
|
26
26
|
let(:expected_path) do
|
27
|
-
"app/serializers/api/v2/.gitkeep"
|
27
|
+
"app/serializers/api/exposed/v2/.gitkeep"
|
28
|
+
end
|
29
|
+
|
30
|
+
it { expect(perform).to eq(expected_path) }
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with no version" do
|
34
|
+
let(:version_number) { "" }
|
35
|
+
|
36
|
+
let(:expected_path) do
|
37
|
+
"app/serializers/api/internal/.gitkeep"
|
28
38
|
end
|
29
39
|
|
30
40
|
it { expect(perform).to eq(expected_path) }
|
@@ -32,25 +42,29 @@ RSpec.describe PowerApi::GeneratorHelper::AmsHelper, type: :generator do
|
|
32
42
|
end
|
33
43
|
|
34
44
|
describe "#ams_serializer_path" do
|
35
|
-
let(:expected_path) { "app/serializers/api/v1/blog_serializer.rb" }
|
45
|
+
let(:expected_path) { "app/serializers/api/exposed/v1/blog_serializer.rb" }
|
36
46
|
|
37
47
|
def perform
|
38
48
|
generators_helper.ams_serializer_path
|
39
49
|
end
|
40
50
|
|
41
51
|
it { expect(perform).to eq(expected_path) }
|
52
|
+
|
53
|
+
context "with no version" do
|
54
|
+
let(:version_number) { nil }
|
55
|
+
|
56
|
+
let(:expected_path) do
|
57
|
+
"app/serializers/api/internal/blog_serializer.rb"
|
58
|
+
end
|
59
|
+
|
60
|
+
it { expect(perform).to eq(expected_path) }
|
61
|
+
end
|
42
62
|
end
|
43
63
|
|
44
64
|
describe "ams_initializer_tpl" do
|
45
65
|
let(:template) do
|
46
66
|
<<~INITIALIZER
|
47
|
-
|
48
|
-
def self.default_key_transform
|
49
|
-
:unaltered
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
ActiveModelSerializers.config.adapter = :json_api
|
67
|
+
ActiveModelSerializers.config.adapter = :json
|
54
68
|
INITIALIZER
|
55
69
|
end
|
56
70
|
|
@@ -64,11 +78,12 @@ RSpec.describe PowerApi::GeneratorHelper::AmsHelper, type: :generator do
|
|
64
78
|
describe "ams_serializer_tpl" do
|
65
79
|
let(:template) do
|
66
80
|
<<~SERIALIZER
|
67
|
-
class Api::V1::BlogSerializer < ActiveModel::Serializer
|
81
|
+
class Api::Exposed::V1::BlogSerializer < ActiveModel::Serializer
|
68
82
|
type :blog
|
69
83
|
|
70
84
|
attributes(
|
71
|
-
:
|
85
|
+
:id,
|
86
|
+
:title,
|
72
87
|
:body,
|
73
88
|
:created_at,
|
74
89
|
:updated_at,
|
@@ -83,5 +98,28 @@ RSpec.describe PowerApi::GeneratorHelper::AmsHelper, type: :generator do
|
|
83
98
|
end
|
84
99
|
|
85
100
|
it { expect(perform).to eq(template) }
|
101
|
+
|
102
|
+
context "with no version" do
|
103
|
+
let(:version_number) { nil }
|
104
|
+
|
105
|
+
let(:template) do
|
106
|
+
<<~SERIALIZER
|
107
|
+
class Api::Internal::BlogSerializer < ActiveModel::Serializer
|
108
|
+
type :blog
|
109
|
+
|
110
|
+
attributes(
|
111
|
+
:id,
|
112
|
+
:title,
|
113
|
+
:body,
|
114
|
+
:created_at,
|
115
|
+
:updated_at,
|
116
|
+
:portfolio_id
|
117
|
+
)
|
118
|
+
end
|
119
|
+
SERIALIZER
|
120
|
+
end
|
121
|
+
|
122
|
+
it { expect(perform).to eq(template) }
|
123
|
+
end
|
86
124
|
end
|
87
125
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
RSpec.describe PowerApi::GeneratorHelper::ApiHelper, 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 }.not_to raise_error }
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with nil blank number" do
|
30
|
+
let(:version_number) { "" }
|
31
|
+
|
32
|
+
it { expect { generators_helper }.not_to raise_error }
|
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
|
+
|
56
|
+
describe "#versioned_api?" do
|
57
|
+
def perform
|
58
|
+
generators_helper.versioned_api?
|
59
|
+
end
|
60
|
+
|
61
|
+
it { expect(perform).to eq(true) }
|
62
|
+
|
63
|
+
context "when version in not first version" do
|
64
|
+
let(:version_number) { "2" }
|
65
|
+
|
66
|
+
it { expect(perform).to eq(true) }
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when nil version" do
|
70
|
+
let(:version_number) { nil }
|
71
|
+
|
72
|
+
it { expect(perform).to eq(false) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#api_file_path" do
|
77
|
+
def perform
|
78
|
+
generators_helper.api_file_path
|
79
|
+
end
|
80
|
+
|
81
|
+
it { expect(perform).to eq("api/exposed/v1") }
|
82
|
+
|
83
|
+
context "when version in not first version" do
|
84
|
+
let(:version_number) { "2" }
|
85
|
+
|
86
|
+
it { expect(perform).to eq("api/exposed/v2") }
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when nil version" do
|
90
|
+
let(:version_number) { nil }
|
91
|
+
|
92
|
+
it { expect(perform).to eq("api/internal") }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#api_class" do
|
97
|
+
def perform
|
98
|
+
generators_helper.api_class
|
99
|
+
end
|
100
|
+
|
101
|
+
it { expect(perform).to eq("Api::Exposed::V1") }
|
102
|
+
|
103
|
+
context "when version in not first version" do
|
104
|
+
let(:version_number) { "2" }
|
105
|
+
|
106
|
+
it { expect(perform).to eq("Api::Exposed::V2") }
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when nil version" do
|
110
|
+
let(:version_number) { nil }
|
111
|
+
|
112
|
+
it { expect(perform).to eq("Api::Internal") }
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -1,46 +1,68 @@
|
|
1
|
-
|
2
|
-
describe "#
|
1
|
+
describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
2
|
+
describe "#api_main_base_controller_path" do
|
3
3
|
let(:expected_path) { "app/controllers/api/base_controller.rb" }
|
4
4
|
|
5
5
|
def perform
|
6
|
-
generators_helper.
|
6
|
+
generators_helper.api_main_base_controller_path
|
7
7
|
end
|
8
8
|
|
9
9
|
it { expect(perform).to eq(expected_path) }
|
10
10
|
end
|
11
11
|
|
12
|
-
describe "#
|
13
|
-
let(:expected_path) { "app/controllers/api/
|
12
|
+
describe "#exposed_base_controller_path" do
|
13
|
+
let(:expected_path) { "app/controllers/api/exposed/base_controller.rb" }
|
14
14
|
|
15
15
|
def perform
|
16
|
-
generators_helper.
|
16
|
+
generators_helper.exposed_base_controller_path
|
17
17
|
end
|
18
18
|
|
19
19
|
it { expect(perform).to eq(expected_path) }
|
20
20
|
end
|
21
21
|
|
22
|
-
describe "
|
23
|
-
let(:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
CONTROLLER
|
22
|
+
describe "#internal_base_controller_path" do
|
23
|
+
let(:expected_path) { "app/controllers/api/internal/base_controller.rb" }
|
24
|
+
|
25
|
+
def perform
|
26
|
+
generators_helper.internal_base_controller_path
|
28
27
|
end
|
29
28
|
|
29
|
+
it { expect(perform).to eq(expected_path) }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#version_base_controller_path" do
|
33
|
+
let(:expected_path) { "app/controllers/api/exposed/v1/base_controller.rb" }
|
34
|
+
|
30
35
|
def perform
|
31
|
-
generators_helper.
|
36
|
+
generators_helper.version_base_controller_path
|
32
37
|
end
|
33
38
|
|
34
|
-
it { expect(perform).to eq(
|
39
|
+
it { expect(perform).to eq(expected_path) }
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#resource_controller_path" do
|
43
|
+
let(:expected_path) { "app/controllers/api/exposed/v1/blogs_controller.rb" }
|
44
|
+
|
45
|
+
def perform
|
46
|
+
generators_helper.resource_controller_path
|
47
|
+
end
|
48
|
+
|
49
|
+
it { expect(perform).to eq(expected_path) }
|
50
|
+
|
51
|
+
context "without version" do
|
52
|
+
let(:version_number) { "" }
|
53
|
+
let(:expected_path) { "app/controllers/api/internal/blogs_controller.rb" }
|
54
|
+
|
55
|
+
it { expect(perform).to eq(expected_path) }
|
56
|
+
end
|
35
57
|
end
|
36
58
|
|
37
|
-
describe "#
|
59
|
+
describe "#version_base_controller_path" do
|
38
60
|
let(:expected_path) do
|
39
|
-
"app/controllers/api/v1/base_controller.rb"
|
61
|
+
"app/controllers/api/exposed/v1/base_controller.rb"
|
40
62
|
end
|
41
63
|
|
42
64
|
def perform
|
43
|
-
generators_helper.
|
65
|
+
generators_helper.version_base_controller_path
|
44
66
|
end
|
45
67
|
|
46
68
|
it { expect(perform).to eq(expected_path) }
|
@@ -49,17 +71,66 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
49
71
|
let(:version_number) { "2" }
|
50
72
|
|
51
73
|
let(:expected_path) do
|
52
|
-
"app/controllers/api/v2/base_controller.rb"
|
74
|
+
"app/controllers/api/exposed/v2/base_controller.rb"
|
53
75
|
end
|
54
76
|
|
55
77
|
it { expect(perform).to eq(expected_path) }
|
56
78
|
end
|
57
79
|
end
|
58
80
|
|
81
|
+
describe "api_main_base_controller_tpl" do
|
82
|
+
let(:template) do
|
83
|
+
<<~CONTROLLER
|
84
|
+
class Api::BaseController < PowerApi::BaseController
|
85
|
+
end
|
86
|
+
CONTROLLER
|
87
|
+
end
|
88
|
+
|
89
|
+
def perform
|
90
|
+
generators_helper.api_main_base_controller_tpl
|
91
|
+
end
|
92
|
+
|
93
|
+
it { expect(perform).to eq(template) }
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "exposed_base_controller_tpl" do
|
97
|
+
let(:template) do
|
98
|
+
<<~CONTROLLER
|
99
|
+
class Api::Exposed::BaseController < Api::BaseController
|
100
|
+
skip_before_action :verify_authenticity_token
|
101
|
+
end
|
102
|
+
CONTROLLER
|
103
|
+
end
|
104
|
+
|
105
|
+
def perform
|
106
|
+
generators_helper.exposed_base_controller_tpl
|
107
|
+
end
|
108
|
+
|
109
|
+
it { expect(perform).to eq(template) }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "internal_base_controller_tpl" do
|
113
|
+
let(:template) do
|
114
|
+
<<~CONTROLLER
|
115
|
+
class Api::Internal::BaseController < Api::BaseController
|
116
|
+
before_action do
|
117
|
+
self.namespace_for_serializer = ::Api::Internal
|
118
|
+
end
|
119
|
+
end
|
120
|
+
CONTROLLER
|
121
|
+
end
|
122
|
+
|
123
|
+
def perform
|
124
|
+
generators_helper.internal_base_controller_tpl
|
125
|
+
end
|
126
|
+
|
127
|
+
it { expect(perform).to eq(template) }
|
128
|
+
end
|
129
|
+
|
59
130
|
describe "resource_controller_tpl" do
|
60
131
|
let(:template) do
|
61
132
|
<<~CONTROLLER
|
62
|
-
class Api::V1::BlogsController < Api::V1::BaseController
|
133
|
+
class Api::Exposed::V1::BlogsController < Api::Exposed::V1::BaseController
|
63
134
|
def index
|
64
135
|
respond_with Blog.all
|
65
136
|
end
|
@@ -70,7 +141,8 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
70
141
|
respond_with Blog.create!(blog_params)
|
71
142
|
end
|
72
143
|
def update
|
73
|
-
|
144
|
+
blog.update!(blog_params)
|
145
|
+
respond_with blog
|
74
146
|
end
|
75
147
|
def destroy
|
76
148
|
respond_with blog.destroy!
|
@@ -96,6 +168,13 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
96
168
|
|
97
169
|
it { expect(perform).to eq(template) }
|
98
170
|
|
171
|
+
context "without version" do
|
172
|
+
let(:version_number) { nil }
|
173
|
+
let(:expected) { "class Api::Internal::BlogsController < Api::Internal::BaseController" }
|
174
|
+
|
175
|
+
it { expect(perform).to include(expected) }
|
176
|
+
end
|
177
|
+
|
99
178
|
context "with specific attributes" do
|
100
179
|
let(:resource_attributes) do
|
101
180
|
[
|
@@ -207,7 +286,7 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
207
286
|
let(:authenticated_resource) { "user" }
|
208
287
|
let(:template) do
|
209
288
|
<<~CONTROLLER
|
210
|
-
class Api::V1::BlogsController < Api::V1::BaseController
|
289
|
+
class Api::Exposed::V1::BlogsController < Api::Exposed::V1::BaseController
|
211
290
|
acts_as_token_authentication_handler_for User, fallback: :exception
|
212
291
|
|
213
292
|
def index
|
@@ -220,7 +299,8 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
220
299
|
respond_with Blog.create!(blog_params)
|
221
300
|
end
|
222
301
|
def update
|
223
|
-
|
302
|
+
blog.update!(blog_params)
|
303
|
+
respond_with blog
|
224
304
|
end
|
225
305
|
def destroy
|
226
306
|
respond_with blog.destroy!
|
@@ -241,6 +321,15 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
241
321
|
end
|
242
322
|
|
243
323
|
it { expect(perform).to eq(template) }
|
324
|
+
|
325
|
+
context "without version" do
|
326
|
+
let(:version_number) { nil }
|
327
|
+
let(:expected) do
|
328
|
+
"before_action :authenticate_user!"
|
329
|
+
end
|
330
|
+
|
331
|
+
it { expect(perform).to include(expected) }
|
332
|
+
end
|
244
333
|
end
|
245
334
|
|
246
335
|
context "with owned_by_authenticated_resource and authenticated_resource" do
|
@@ -249,7 +338,7 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
249
338
|
|
250
339
|
let(:template) do
|
251
340
|
<<~CONTROLLER
|
252
|
-
class Api::V1::BlogsController < Api::V1::BaseController
|
341
|
+
class Api::Exposed::V1::BlogsController < Api::Exposed::V1::BaseController
|
253
342
|
acts_as_token_authentication_handler_for User, fallback: :exception
|
254
343
|
|
255
344
|
def index
|
@@ -262,7 +351,8 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
262
351
|
respond_with blogs.create!(blog_params)
|
263
352
|
end
|
264
353
|
def update
|
265
|
-
|
354
|
+
blog.update!(blog_params)
|
355
|
+
respond_with blog
|
266
356
|
end
|
267
357
|
def destroy
|
268
358
|
respond_with blog.destroy!
|
@@ -299,7 +389,7 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
299
389
|
let(:parent_resource_name) { "portfolio" }
|
300
390
|
let(:template) do
|
301
391
|
<<~CONTROLLER
|
302
|
-
class Api::V1::BlogsController < Api::V1::BaseController
|
392
|
+
class Api::Exposed::V1::BlogsController < Api::Exposed::V1::BaseController
|
303
393
|
def index
|
304
394
|
respond_with blogs
|
305
395
|
end
|
@@ -310,7 +400,8 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
310
400
|
respond_with blogs.create!(blog_params)
|
311
401
|
end
|
312
402
|
def update
|
313
|
-
|
403
|
+
blog.update!(blog_params)
|
404
|
+
respond_with blog
|
314
405
|
end
|
315
406
|
def destroy
|
316
407
|
respond_with blog.destroy!
|
@@ -345,7 +436,7 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
345
436
|
let(:owned_by_authenticated_resource) { true }
|
346
437
|
let(:template) do
|
347
438
|
<<~CONTROLLER
|
348
|
-
class Api::V1::BlogsController < Api::V1::BaseController
|
439
|
+
class Api::Exposed::V1::BlogsController < Api::Exposed::V1::BaseController
|
349
440
|
acts_as_token_authentication_handler_for User, fallback: :exception
|
350
441
|
|
351
442
|
def index
|
@@ -358,7 +449,8 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
358
449
|
respond_with blogs.create!(blog_params)
|
359
450
|
end
|
360
451
|
def update
|
361
|
-
|
452
|
+
blog.update!(blog_params)
|
453
|
+
respond_with blog
|
362
454
|
end
|
363
455
|
def destroy
|
364
456
|
respond_with blog.destroy!
|
@@ -388,19 +480,19 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
388
480
|
end
|
389
481
|
end
|
390
482
|
|
391
|
-
describe "#
|
483
|
+
describe "#version_base_controller_tpl" do
|
392
484
|
let(:expected_tpl) do
|
393
485
|
<<~CONTROLLER
|
394
|
-
class Api::V1::BaseController < Api::BaseController
|
486
|
+
class Api::Exposed::V1::BaseController < Api::Exposed::BaseController
|
395
487
|
before_action do
|
396
|
-
self.namespace_for_serializer = ::Api::V1
|
488
|
+
self.namespace_for_serializer = ::Api::Exposed::V1
|
397
489
|
end
|
398
490
|
end
|
399
491
|
CONTROLLER
|
400
492
|
end
|
401
493
|
|
402
494
|
def perform
|
403
|
-
generators_helper.
|
495
|
+
generators_helper.version_base_controller_tpl
|
404
496
|
end
|
405
497
|
|
406
498
|
it { expect(perform).to eq(expected_tpl) }
|
@@ -410,9 +502,9 @@ RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
|
410
502
|
|
411
503
|
let(:expected_tpl) do
|
412
504
|
<<~CONTROLLER
|
413
|
-
class Api::V2::BaseController < Api::BaseController
|
505
|
+
class Api::Exposed::V2::BaseController < Api::Exposed::BaseController
|
414
506
|
before_action do
|
415
|
-
self.namespace_for_serializer = ::Api::V2
|
507
|
+
self.namespace_for_serializer = ::Api::Exposed::V2
|
416
508
|
end
|
417
509
|
end
|
418
510
|
CONTROLLER
|