power_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.hound.yml +4 -0
- data/.rspec +3 -0
- data/.rubocop.yml +479 -0
- data/.ruby-version +1 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +310 -0
- data/Guardfile +15 -0
- data/LICENSE.txt +21 -0
- data/README.md +904 -0
- data/Rakefile +10 -0
- data/app/assets/config/power_api_manifest.js +2 -0
- data/app/assets/images/power_api/.keep +0 -0
- data/app/assets/javascripts/power_api/application.js +13 -0
- data/app/assets/stylesheets/power_api/application.css +15 -0
- data/app/controllers/concerns/api/deprecated.rb +23 -0
- data/app/controllers/concerns/api/error.rb +37 -0
- data/app/controllers/concerns/api/filtered.rb +15 -0
- data/app/controllers/concerns/api/versioned.rb +36 -0
- data/app/controllers/power_api/base_controller.rb +14 -0
- data/app/helpers/power_api/application_helper.rb +4 -0
- data/app/jobs/power_api/application_job.rb +4 -0
- data/app/mailers/power_api/application_mailer.rb +6 -0
- data/app/models/power_api/application_record.rb +5 -0
- data/app/responders/api_responder.rb +13 -0
- data/app/views/layouts/power_api/application.html.erb +14 -0
- data/bin/rails +14 -0
- data/config/routes.rb +2 -0
- data/lib/generators/power_api/controller/USAGE +5 -0
- data/lib/generators/power_api/controller/controller_generator.rb +152 -0
- data/lib/generators/power_api/install/USAGE +5 -0
- data/lib/generators/power_api/install/install_generator.rb +67 -0
- data/lib/generators/power_api/version/USAGE +5 -0
- data/lib/generators/power_api/version/version_generator.rb +54 -0
- data/lib/power_api.rb +35 -0
- data/lib/power_api/engine.rb +28 -0
- data/lib/power_api/errors.rb +4 -0
- data/lib/power_api/generator_helper/active_record_resource.rb +192 -0
- data/lib/power_api/generator_helper/ams_helper.rb +43 -0
- data/lib/power_api/generator_helper/controller_helper.rb +184 -0
- data/lib/power_api/generator_helper/pagination_helper.rb +48 -0
- data/lib/power_api/generator_helper/resource_helper.rb +33 -0
- data/lib/power_api/generator_helper/routes_helper.rb +91 -0
- data/lib/power_api/generator_helper/rubocop_helper.rb +11 -0
- data/lib/power_api/generator_helper/simple_token_auth_helper.rb +124 -0
- data/lib/power_api/generator_helper/swagger_helper.rb +463 -0
- data/lib/power_api/generator_helper/template_builder_helper.rb +23 -0
- data/lib/power_api/generator_helper/version_helper.rb +16 -0
- data/lib/power_api/generator_helpers.rb +25 -0
- data/lib/power_api/version.rb +3 -0
- data/lib/tasks/power_api_tasks.rake +4 -0
- data/power_api.gemspec +44 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +5 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/concerns/api/deprecated_spec.rb +37 -0
- data/spec/dummy/app/controllers/concerns/api/error_spec.rb +97 -0
- data/spec/dummy/app/controllers/concerns/api/filtered_spec.rb +42 -0
- data/spec/dummy/app/controllers/concerns/api/versioned_spec.rb +64 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/blog.rb +5 -0
- data/spec/dummy/app/models/portfolio.rb +5 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +38 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/config/application.rb +26 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +91 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/assets.rb +14 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +56 -0
- data/spec/dummy/config/routes.rb +12 -0
- data/spec/dummy/config/secrets.yml +32 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/db/migrate/20190322205209_create_blogs.rb +10 -0
- data/spec/dummy/db/migrate/20200215225917_create_users.rb +9 -0
- data/spec/dummy/db/migrate/20200227150449_create_portfolios.rb +10 -0
- data/spec/dummy/db/migrate/20200227150548_add_portfolio_id_blogs.rb +5 -0
- data/spec/dummy/db/schema.rb +38 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/assets/image.png +0 -0
- data/spec/dummy/spec/assets/video.mp4 +0 -0
- data/spec/dummy/spec/factories/blogs.rb +7 -0
- data/spec/dummy/spec/factories/portfolios.rb +6 -0
- data/spec/dummy/spec/factories/users.rb +5 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/ams_helper_spec.rb +87 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/controller_helper_spec.rb +361 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/pagination_helper_spec.rb +56 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/resource_helper_spec.rb +31 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/routes_helper_spec.rb +179 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/simple_token_auth_helper_spec.rb +164 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/swagger_helper_spec.rb +451 -0
- data/spec/dummy/spec/lib/power_api/generator_helper/version_helper_spec.rb +55 -0
- data/spec/dummy/spec/support/shared_examples/active_record_resource.rb +101 -0
- data/spec/dummy/spec/support/shared_examples/active_record_resource_atrributes.rb +164 -0
- data/spec/dummy/spec/support/test_generator_helpers.rb +29 -0
- data/spec/dummy/spec/support/test_helpers.rb +11 -0
- data/spec/rails_helper.rb +49 -0
- data/spec/spec_helper.rb +9 -0
- metadata +602 -0
@@ -0,0 +1,66 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
.rails-default-error-page {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
.rails-default-error-page div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
.rails-default-error-page div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
.rails-default-error-page h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
.rails-default-error-page div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
54
|
+
</style>
|
55
|
+
</head>
|
56
|
+
|
57
|
+
<body class="rails-default-error-page">
|
58
|
+
<!-- This file lives in public/500.html -->
|
59
|
+
<div class="dialog">
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
64
|
+
</div>
|
65
|
+
</body>
|
66
|
+
</html>
|
File without changes
|
File without changes
|
File without changes
|
Binary file
|
Binary file
|
@@ -0,0 +1,87 @@
|
|
1
|
+
RSpec.describe PowerApi::GeneratorHelper::AmsHelper, type: :generator do
|
2
|
+
describe "#ams_initializer_path" do
|
3
|
+
let(:expected_path) { "config/initializers/active_model_serializers.rb" }
|
4
|
+
|
5
|
+
def perform
|
6
|
+
generators_helper.ams_initializer_path
|
7
|
+
end
|
8
|
+
|
9
|
+
it { expect(perform).to eq(expected_path) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#ams_serializers_path" do
|
13
|
+
let(:expected_path) do
|
14
|
+
"app/serializers/api/v1/.gitkeep"
|
15
|
+
end
|
16
|
+
|
17
|
+
def perform
|
18
|
+
subject.ams_serializers_path
|
19
|
+
end
|
20
|
+
|
21
|
+
it { expect(perform).to eq(expected_path) }
|
22
|
+
|
23
|
+
context "with another version" do
|
24
|
+
let(:version_number) { "2" }
|
25
|
+
|
26
|
+
let(:expected_path) do
|
27
|
+
"app/serializers/api/v2/.gitkeep"
|
28
|
+
end
|
29
|
+
|
30
|
+
it { expect(perform).to eq(expected_path) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#ams_serializer_path" do
|
35
|
+
let(:expected_path) { "app/serializers/api/v1/blog_serializer.rb" }
|
36
|
+
|
37
|
+
def perform
|
38
|
+
generators_helper.ams_serializer_path
|
39
|
+
end
|
40
|
+
|
41
|
+
it { expect(perform).to eq(expected_path) }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "ams_initializer_tpl" do
|
45
|
+
let(:template) do
|
46
|
+
<<~INITIALIZER
|
47
|
+
class ActiveModelSerializers::Adapter::JsonApi
|
48
|
+
def self.default_key_transform
|
49
|
+
:unaltered
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
ActiveModelSerializers.config.adapter = :json_api
|
54
|
+
INITIALIZER
|
55
|
+
end
|
56
|
+
|
57
|
+
def perform
|
58
|
+
generators_helper.ams_initializer_tpl
|
59
|
+
end
|
60
|
+
|
61
|
+
it { expect(perform).to eq(template) }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "ams_serializer_tpl" do
|
65
|
+
let(:template) do
|
66
|
+
<<~SERIALIZER
|
67
|
+
class Api::V1::BlogSerializer < ActiveModel::Serializer
|
68
|
+
type :blog
|
69
|
+
|
70
|
+
attributes(
|
71
|
+
:title,
|
72
|
+
:body,
|
73
|
+
:created_at,
|
74
|
+
:updated_at,
|
75
|
+
:portfolio_id
|
76
|
+
)
|
77
|
+
end
|
78
|
+
SERIALIZER
|
79
|
+
end
|
80
|
+
|
81
|
+
def perform
|
82
|
+
generators_helper.ams_serializer_tpl
|
83
|
+
end
|
84
|
+
|
85
|
+
it { expect(perform).to eq(template) }
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,361 @@
|
|
1
|
+
RSpec.describe PowerApi::GeneratorHelper::ControllerHelper, type: :generator do
|
2
|
+
describe "#api_base_controller_path" do
|
3
|
+
let(:expected_path) { "app/controllers/api/base_controller.rb" }
|
4
|
+
|
5
|
+
def perform
|
6
|
+
generators_helper.api_base_controller_path
|
7
|
+
end
|
8
|
+
|
9
|
+
it { expect(perform).to eq(expected_path) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#resource_controller_path" do
|
13
|
+
let(:expected_path) { "app/controllers/api/v1/blogs_controller.rb" }
|
14
|
+
|
15
|
+
def perform
|
16
|
+
generators_helper.resource_controller_path
|
17
|
+
end
|
18
|
+
|
19
|
+
it { expect(perform).to eq(expected_path) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "api_base_controller_tpl" do
|
23
|
+
let(:template) do
|
24
|
+
<<~CONTROLLER
|
25
|
+
class Api::BaseController < PowerApi::BaseController
|
26
|
+
end
|
27
|
+
CONTROLLER
|
28
|
+
end
|
29
|
+
|
30
|
+
def perform
|
31
|
+
generators_helper.api_base_controller_tpl
|
32
|
+
end
|
33
|
+
|
34
|
+
it { expect(perform).to eq(template) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#base_controller_path" do
|
38
|
+
let(:expected_path) do
|
39
|
+
"app/controllers/api/v1/base_controller.rb"
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform
|
43
|
+
generators_helper.base_controller_path
|
44
|
+
end
|
45
|
+
|
46
|
+
it { expect(perform).to eq(expected_path) }
|
47
|
+
|
48
|
+
context "with another version" do
|
49
|
+
let(:version_number) { "2" }
|
50
|
+
|
51
|
+
let(:expected_path) do
|
52
|
+
"app/controllers/api/v2/base_controller.rb"
|
53
|
+
end
|
54
|
+
|
55
|
+
it { expect(perform).to eq(expected_path) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "resource_controller_tpl" do
|
60
|
+
let(:template) do
|
61
|
+
<<~CONTROLLER
|
62
|
+
class Api::V1::BlogsController < Api::V1::BaseController
|
63
|
+
def index
|
64
|
+
respond_with Blog.all
|
65
|
+
end
|
66
|
+
def show
|
67
|
+
respond_with blog
|
68
|
+
end
|
69
|
+
def create
|
70
|
+
respond_with Blog.create!(blog_params)
|
71
|
+
end
|
72
|
+
def update
|
73
|
+
respond_with blog.update!(blog_params)
|
74
|
+
end
|
75
|
+
def destroy
|
76
|
+
respond_with blog.destroy!
|
77
|
+
end
|
78
|
+
private
|
79
|
+
def blog
|
80
|
+
@blog ||= Blog.find_by!(id: params[:id])
|
81
|
+
end
|
82
|
+
def blog_params
|
83
|
+
params.require(:blog).permit(
|
84
|
+
:title,
|
85
|
+
:body,
|
86
|
+
:portfolio_id
|
87
|
+
)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
CONTROLLER
|
91
|
+
end
|
92
|
+
|
93
|
+
def perform
|
94
|
+
generators_helper.resource_controller_tpl
|
95
|
+
end
|
96
|
+
|
97
|
+
it { expect(perform).to eq(template) }
|
98
|
+
|
99
|
+
context "with specific attributes" do
|
100
|
+
let(:resource_attributes) do
|
101
|
+
[
|
102
|
+
"title",
|
103
|
+
"created_at",
|
104
|
+
"portfolio_id"
|
105
|
+
]
|
106
|
+
end
|
107
|
+
|
108
|
+
let(:expected) do
|
109
|
+
":title"
|
110
|
+
end
|
111
|
+
|
112
|
+
it { expect(perform).to include(expected) }
|
113
|
+
end
|
114
|
+
|
115
|
+
context "with true use_paginator option" do
|
116
|
+
let(:use_paginator) { true }
|
117
|
+
let(:expected) do
|
118
|
+
"respond_with paginate(Blog.all)"
|
119
|
+
end
|
120
|
+
|
121
|
+
it { expect(perform).to include(expected) }
|
122
|
+
end
|
123
|
+
|
124
|
+
context "with true allow_filters option" do
|
125
|
+
let(:allow_filters) { true }
|
126
|
+
let(:expected) do
|
127
|
+
"respond_with filtered_collection(Blog.all)"
|
128
|
+
end
|
129
|
+
|
130
|
+
it { expect(perform).to include(expected) }
|
131
|
+
end
|
132
|
+
|
133
|
+
context "with true allow_filters and use_paginator options" do
|
134
|
+
let(:allow_filters) { true }
|
135
|
+
let(:use_paginator) { true }
|
136
|
+
let(:expected) do
|
137
|
+
"respond_with paginate(filtered_collection(Blog.all))"
|
138
|
+
end
|
139
|
+
|
140
|
+
it { expect(perform).to include(expected) }
|
141
|
+
end
|
142
|
+
|
143
|
+
context "with authenticated_resource option" do
|
144
|
+
let(:authenticated_resource) { "user" }
|
145
|
+
let(:template) do
|
146
|
+
<<~CONTROLLER
|
147
|
+
class Api::V1::BlogsController < Api::V1::BaseController
|
148
|
+
acts_as_token_authentication_handler_for User, fallback: :exception
|
149
|
+
|
150
|
+
def index
|
151
|
+
respond_with Blog.all
|
152
|
+
end
|
153
|
+
def show
|
154
|
+
respond_with blog
|
155
|
+
end
|
156
|
+
def create
|
157
|
+
respond_with Blog.create!(blog_params)
|
158
|
+
end
|
159
|
+
def update
|
160
|
+
respond_with blog.update!(blog_params)
|
161
|
+
end
|
162
|
+
def destroy
|
163
|
+
respond_with blog.destroy!
|
164
|
+
end
|
165
|
+
private
|
166
|
+
def blog
|
167
|
+
@blog ||= Blog.find_by!(id: params[:id])
|
168
|
+
end
|
169
|
+
def blog_params
|
170
|
+
params.require(:blog).permit(
|
171
|
+
:title,
|
172
|
+
:body,
|
173
|
+
:portfolio_id
|
174
|
+
)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
CONTROLLER
|
178
|
+
end
|
179
|
+
|
180
|
+
it { expect(perform).to eq(template) }
|
181
|
+
end
|
182
|
+
|
183
|
+
context "with owned_by_authenticated_resource and authenticated_resource" do
|
184
|
+
let(:authenticated_resource) { "user" }
|
185
|
+
let(:owned_by_authenticated_resource) { true }
|
186
|
+
|
187
|
+
let(:template) do
|
188
|
+
<<~CONTROLLER
|
189
|
+
class Api::V1::BlogsController < Api::V1::BaseController
|
190
|
+
acts_as_token_authentication_handler_for User, fallback: :exception
|
191
|
+
|
192
|
+
def index
|
193
|
+
respond_with blogs
|
194
|
+
end
|
195
|
+
def show
|
196
|
+
respond_with blog
|
197
|
+
end
|
198
|
+
def create
|
199
|
+
respond_with blogs.create!(blog_params)
|
200
|
+
end
|
201
|
+
def update
|
202
|
+
respond_with blog.update!(blog_params)
|
203
|
+
end
|
204
|
+
def destroy
|
205
|
+
respond_with blog.destroy!
|
206
|
+
end
|
207
|
+
private
|
208
|
+
def blog
|
209
|
+
@blog ||= blogs.find_by!(id: params[:id])
|
210
|
+
end
|
211
|
+
def blogs
|
212
|
+
@blogs ||= current_user.blogs
|
213
|
+
end
|
214
|
+
def blog_params
|
215
|
+
params.require(:blog).permit(
|
216
|
+
:title,
|
217
|
+
:body,
|
218
|
+
:portfolio_id
|
219
|
+
)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
CONTROLLER
|
223
|
+
end
|
224
|
+
|
225
|
+
it { expect(perform).to eq(template) }
|
226
|
+
end
|
227
|
+
|
228
|
+
context "with owned_by_authenticated_resource but authenticated_resource" do
|
229
|
+
let(:authenticated_resource) { nil }
|
230
|
+
let(:owned_by_authenticated_resource) { true }
|
231
|
+
|
232
|
+
it { expect(perform).to eq(template) }
|
233
|
+
end
|
234
|
+
|
235
|
+
context "with parent_resource option" do
|
236
|
+
let(:parent_resource_name) { "portfolio" }
|
237
|
+
let(:template) do
|
238
|
+
<<~CONTROLLER
|
239
|
+
class Api::V1::BlogsController < Api::V1::BaseController
|
240
|
+
def index
|
241
|
+
respond_with blogs
|
242
|
+
end
|
243
|
+
def show
|
244
|
+
respond_with blog
|
245
|
+
end
|
246
|
+
def create
|
247
|
+
respond_with blogs.create!(blog_params)
|
248
|
+
end
|
249
|
+
def update
|
250
|
+
respond_with blog.update!(blog_params)
|
251
|
+
end
|
252
|
+
def destroy
|
253
|
+
respond_with blog.destroy!
|
254
|
+
end
|
255
|
+
private
|
256
|
+
def blog
|
257
|
+
@blog ||= Blog.find_by!(id: params[:id])
|
258
|
+
end
|
259
|
+
def blogs
|
260
|
+
@blogs ||= portfolio.blogs
|
261
|
+
end
|
262
|
+
def portfolio
|
263
|
+
@portfolio ||= Portfolio.find_by!(id: params[:portfolio_id])
|
264
|
+
end
|
265
|
+
def blog_params
|
266
|
+
params.require(:blog).permit(
|
267
|
+
:title,
|
268
|
+
:body,
|
269
|
+
:portfolio_id
|
270
|
+
)
|
271
|
+
end
|
272
|
+
end
|
273
|
+
CONTROLLER
|
274
|
+
end
|
275
|
+
|
276
|
+
it { expect(perform).to eq(template) }
|
277
|
+
end
|
278
|
+
|
279
|
+
context "with parent_resource owned by authenticated_resource" do
|
280
|
+
let(:parent_resource_name) { "portfolio" }
|
281
|
+
let(:authenticated_resource) { "user" }
|
282
|
+
let(:owned_by_authenticated_resource) { true }
|
283
|
+
let(:template) do
|
284
|
+
<<~CONTROLLER
|
285
|
+
class Api::V1::BlogsController < Api::V1::BaseController
|
286
|
+
acts_as_token_authentication_handler_for User, fallback: :exception
|
287
|
+
|
288
|
+
def index
|
289
|
+
respond_with blogs
|
290
|
+
end
|
291
|
+
def show
|
292
|
+
respond_with blog
|
293
|
+
end
|
294
|
+
def create
|
295
|
+
respond_with blogs.create!(blog_params)
|
296
|
+
end
|
297
|
+
def update
|
298
|
+
respond_with blog.update!(blog_params)
|
299
|
+
end
|
300
|
+
def destroy
|
301
|
+
respond_with blog.destroy!
|
302
|
+
end
|
303
|
+
private
|
304
|
+
def blog
|
305
|
+
@blog ||= Blog.find_by!(id: params[:id])
|
306
|
+
end
|
307
|
+
def blogs
|
308
|
+
@blogs ||= portfolio.blogs
|
309
|
+
end
|
310
|
+
def portfolio
|
311
|
+
@portfolio ||= Portfolio.find_by!(id: params[:portfolio_id])
|
312
|
+
end
|
313
|
+
def blog_params
|
314
|
+
params.require(:blog).permit(
|
315
|
+
:title,
|
316
|
+
:body,
|
317
|
+
:portfolio_id
|
318
|
+
)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
CONTROLLER
|
322
|
+
end
|
323
|
+
|
324
|
+
it { expect(perform).to eq(template) }
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
describe "#base_controller_tpl" do
|
329
|
+
let(:expected_tpl) do
|
330
|
+
<<~CONTROLLER
|
331
|
+
class Api::V1::BaseController < Api::BaseController
|
332
|
+
before_action do
|
333
|
+
self.namespace_for_serializer = ::Api::V1
|
334
|
+
end
|
335
|
+
end
|
336
|
+
CONTROLLER
|
337
|
+
end
|
338
|
+
|
339
|
+
def perform
|
340
|
+
generators_helper.base_controller_tpl
|
341
|
+
end
|
342
|
+
|
343
|
+
it { expect(perform).to eq(expected_tpl) }
|
344
|
+
|
345
|
+
context "with another version" do
|
346
|
+
let(:version_number) { "2" }
|
347
|
+
|
348
|
+
let(:expected_tpl) do
|
349
|
+
<<~CONTROLLER
|
350
|
+
class Api::V2::BaseController < Api::BaseController
|
351
|
+
before_action do
|
352
|
+
self.namespace_for_serializer = ::Api::V2
|
353
|
+
end
|
354
|
+
end
|
355
|
+
CONTROLLER
|
356
|
+
end
|
357
|
+
|
358
|
+
it { expect(perform).to eq(expected_tpl) }
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|