api_scaffold 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -4
- data/lib/api_scaffold/version.rb +1 -1
- data/lib/generators/api_scaffold/api_scaffold_generator.rb +5 -5
- data/lib/generators/api_scaffold/generator_helpers.rb +3 -3
- data/lib/generators/api_scaffold/templates/controllers/controller.rb +1 -1
- data/lib/generators/api_scaffold/templates/controllers/serializer_controller.rb +1 -1
- data/lib/generators/api_scaffold/templates/tests/rspec/controller_spec.rb +2 -2
- data/lib/generators/api_scaffold/templates/tests/test_unit/controller_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b849a097b4d3de796e261221a6d46245f92eb5abf6cdc5b169b6113896612594
|
4
|
+
data.tar.gz: a9c0066a65c33bd6a5a95b72af2e231df9a472c3dd7fdc42431c5c07f165e68c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4fd95d6617e0286e26c07f80be7930731643bf8c4f84970a5c1224a4b28dc7050eb983487d8dfa9de42822a945554ed4a1dc80b79e77c0b60c1704241b2c984
|
7
|
+
data.tar.gz: 8c33ea95c27483219ee09595956486556b36716bc28e43c81be98398d7854cc047ebebed894296dc9f6b5d222eebe4771ed7615070ec5b26d107c42ca042ecf1
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ApiScaffold
|
2
2
|
|
3
|
-
A useful Rails API generator for scaffolding. Compatible with
|
3
|
+
A useful Rails API generator for scaffolding. Compatible with :
|
4
4
|
- Fast JSON API/Active Model Serializers
|
5
5
|
- Rspec/TestUnit/Fixtures/FactoryBot
|
6
6
|
- Api Pagination
|
@@ -26,7 +26,7 @@ Or install it yourself as:
|
|
26
26
|
Add this code to config/routes.rb if you want your routes to be inserted under the v1 namespace.
|
27
27
|
|
28
28
|
```ruby
|
29
|
-
|
29
|
+
namespace :api, defaults: { format: :json } do
|
30
30
|
namespace :v1 do
|
31
31
|
end
|
32
32
|
end
|
@@ -42,8 +42,7 @@ If you wish to specify the api version:
|
|
42
42
|
|
43
43
|
## TODO
|
44
44
|
- Make compatible with nested resources
|
45
|
-
- Add
|
46
|
-
- create individual scaffolds for controller, authentication and tests
|
45
|
+
- Add api docs to controller scaffold
|
47
46
|
|
48
47
|
## Contributing
|
49
48
|
|
data/lib/api_scaffold/version.rb
CHANGED
@@ -25,17 +25,17 @@ module ApiScaffold
|
|
25
25
|
|
26
26
|
def create_controller_files
|
27
27
|
if gem_available?('fast_jsonapi') || gem_available?('active_model_serializers')
|
28
|
-
template "controllers/serializer_controller.rb", File.join("app/controllers/", prefix, "#{controller_file_name}_controller.rb")
|
28
|
+
template "controllers/serializer_controller.rb", File.join("app/controllers/api/", prefix, "#{controller_file_name}_controller.rb")
|
29
29
|
else
|
30
|
-
template "controllers/controller.rb", File.join("app/controllers/", prefix, "#{controller_file_name}_controller.rb")
|
30
|
+
template "controllers/controller.rb", File.join("app/controllers/api", prefix, "#{controller_file_name}_controller.rb")
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
def create_controller_test_files
|
35
35
|
if test_framework == :rspec
|
36
|
-
template "tests/rspec/controller_spec.rb", File.join("spec/controllers", prefix, "#{controller_file_name}_controller_spec.rb")
|
36
|
+
template "tests/rspec/controller_spec.rb", File.join("spec/controllers/api", prefix, "#{controller_file_name}_controller_spec.rb")
|
37
37
|
else
|
38
|
-
template "tests/test_unit/controller_spec.rb", File.join("test/controllers", prefix, "#{controller_file_name}_controller_test.rb")
|
38
|
+
template "tests/test_unit/controller_spec.rb", File.join("test/controllers/api", prefix, "#{controller_file_name}_controller_test.rb")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -43,7 +43,7 @@ module ApiScaffold
|
|
43
43
|
# Include tabs and line break for proper formatting
|
44
44
|
routes_string = " resources :#{controller_file_name}, except: [:new, :edit]\n"
|
45
45
|
# Inject into file following the api scope and v1 namespace
|
46
|
-
inject_into_file 'config/routes.rb', after: "
|
46
|
+
inject_into_file 'config/routes.rb', after: " namespace :api, defaults: { format: :json } do\n namespace :#{prefix} do\n" do
|
47
47
|
routes_string
|
48
48
|
end
|
49
49
|
end
|
@@ -7,15 +7,15 @@ module ApiScaffold
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def prefixed_class_name
|
10
|
-
"
|
10
|
+
"Api::#{prefix.capitalize}::#{class_name}"
|
11
11
|
end
|
12
12
|
|
13
13
|
def prefixed_controller_class_name
|
14
|
-
"
|
14
|
+
"Api::#{prefix.capitalize}::#{controller_class_name}"
|
15
15
|
end
|
16
16
|
|
17
17
|
def prefixed_url(resource)
|
18
|
-
[prefix, resource, 'url'].join('_')
|
18
|
+
['api', prefix, resource, 'url'].join('_')
|
19
19
|
end
|
20
20
|
|
21
21
|
def gem_available?(gem_name)
|
@@ -19,7 +19,7 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
19
19
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
20
20
|
|
21
21
|
if @<%= orm_instance.save %>
|
22
|
-
render json: <%= "@#{singular_table_name}" %>, status: :created, location: [:<%= prefix %>, <%= "@#{singular_table_name}" %>]
|
22
|
+
render json: <%= "@#{singular_table_name}" %>, status: :created, location: [:api, :<%= prefix %>, <%= "@#{singular_table_name}" %>]
|
23
23
|
else
|
24
24
|
render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
|
25
25
|
end
|
@@ -19,7 +19,7 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
19
19
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
20
20
|
|
21
21
|
if @<%= orm_instance.save %>
|
22
|
-
render json: <%= class_name %>Serializer.new(<%= "@#{singular_table_name}" %>), status: :created, location: [:<%= prefix %>, <%= "@#{singular_table_name}" %>]
|
22
|
+
render json: <%= class_name %>Serializer.new(<%= "@#{singular_table_name}" %>), status: :created, location: [:api, :<%= prefix %>, <%= "@#{singular_table_name}" %>]
|
23
23
|
else
|
24
24
|
render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity
|
25
25
|
end
|
@@ -85,7 +85,7 @@ RSpec.describe <%= prefixed_controller_class_name %>Controller, type: :controlle
|
|
85
85
|
<% end -%>
|
86
86
|
expect(response).to have_http_status(:created)
|
87
87
|
expect(response.content_type).to eq('application/json')
|
88
|
-
expect(response.location).to eq(<%= prefix %>_<%= file_name %>_url(<%= class_name %>.last))
|
88
|
+
expect(response.location).to eq(api_<%= prefix %>_<%= file_name %>_url(<%= class_name %>.last))
|
89
89
|
end
|
90
90
|
end
|
91
91
|
context "with invalid params" do
|
@@ -154,4 +154,4 @@ RSpec.describe <%= prefixed_controller_class_name %>Controller, type: :controlle
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
157
|
-
<% end -%>
|
157
|
+
<% end -%>
|
@@ -11,34 +11,34 @@ class <%= prefixed_controller_class_name %>ControllerTest < ActionDispatch::Inte
|
|
11
11
|
end
|
12
12
|
|
13
13
|
test "should get index" do
|
14
|
-
get <%= [prefix, index_helper].join('_') %>_url, as: :json
|
14
|
+
get <%= ['api', prefix, index_helper].join('_') %>_url, as: :json
|
15
15
|
assert_response :success
|
16
16
|
end
|
17
17
|
|
18
18
|
test "should create <%= singular_table_name %>" do
|
19
19
|
assert_difference('<%= class_name %>.count') do
|
20
|
-
post <%= [prefix, index_helper].join('_') %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
|
20
|
+
post <%= ['api', prefix, index_helper].join('_') %>_url, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
|
21
21
|
end
|
22
22
|
|
23
23
|
assert_response 201
|
24
24
|
end
|
25
25
|
|
26
26
|
test "should show <%= singular_table_name %>" do
|
27
|
-
get <%= [prefix, show_helper].join('_') %>, as: :json
|
27
|
+
get <%= ['api', prefix, show_helper].join('_') %>, as: :json
|
28
28
|
assert_response :success
|
29
29
|
end
|
30
30
|
|
31
31
|
test "should update <%= singular_table_name %>" do
|
32
|
-
patch <%= [prefix, show_helper].join('_') %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
|
32
|
+
patch <%= ['api', prefix, show_helper].join('_') %>, params: { <%= "#{singular_table_name}: { #{attributes_string} }" %> }, as: :json
|
33
33
|
assert_response 200
|
34
34
|
end
|
35
35
|
|
36
36
|
test "should destroy <%= singular_table_name %>" do
|
37
37
|
assert_difference('<%= class_name %>.count', -1) do
|
38
|
-
delete <%= [prefix, show_helper].join('_') %>, as: :json
|
38
|
+
delete <%= ['api', prefix, show_helper].join('_') %>, as: :json
|
39
39
|
end
|
40
40
|
|
41
41
|
assert_response 204
|
42
42
|
end
|
43
43
|
end
|
44
|
-
<% end -%>
|
44
|
+
<% end -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Atkinson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|