graphiti_scaffold_generator 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/graphiti_resource_generator/rspec/templates/resource_spec.rb +0 -1
- data/lib/graphiti_scaffold_generator/generators/rails/scaffold_controller_generator.rb +3 -0
- data/lib/graphiti_scaffold_generator/generators/rails/templates/api_controller.rb +9 -9
- data/lib/graphiti_scaffold_generator/generators/rails/templates/api_request_spec.rb +14 -4
- data/lib/graphiti_scaffold_generator/generators/rails/templates/routing_spec.rb +53 -0
- data/lib/graphiti_scaffold_generator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1ea8070e7c4359a2c5021e027d896d7ddc2d5055a27fcb0a281a27f12f7edbc
|
4
|
+
data.tar.gz: b2f5e9abd43cd2abf1fc5ea0a7ef61c02684baef7a449cd563be747c516ca0bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3cd793d22c65a2179381eb348676b83310eacc49f0d746bcd741b38cc21ec0b4dc1452f2cea9b394a0d7d08b72ef4a1654b01ca3a0cedad6210e3b8220c660d
|
7
|
+
data.tar.gz: b33848f4ac20285cfe7a9de732042c89c4557b2c286eac6d6ebeb8930396e3fce74a2212e8230e00ee56dc0bc379ea1b242bfa89b0b60e112797be8822da5387
|
data/Gemfile.lock
CHANGED
@@ -17,6 +17,9 @@ end
|
|
17
17
|
module Rspec
|
18
18
|
module Generators
|
19
19
|
class ScaffoldGenerator < Base
|
20
|
+
class_option :api_version, type: :string,
|
21
|
+
desc: "Defines the version of the api'",
|
22
|
+
default: 'v1'
|
20
23
|
source_paths.unshift File.expand_path('../templates', __FILE__)
|
21
24
|
end
|
22
25
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
<% resource = class_name + 'Resource' -%>
|
2
2
|
<% pundit = defined?(Pundit) -%>
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
class <%= controller_class_name %>Controller <
|
5
|
-
before_action :set_<%= pundit ? '
|
4
|
+
class <%= controller_class_name %>Controller < GraphitiApiController
|
5
|
+
before_action :set_<%= pundit ? 'and_authorize_' : '' %><%= singular_table_name %>, only: %i[show update destroy]
|
6
6
|
|
7
7
|
# GET <%= route_url %>
|
8
8
|
def index
|
@@ -23,18 +23,18 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
23
23
|
<% end -%>
|
24
24
|
|
25
25
|
if @<%= singular_table_name %>.save
|
26
|
-
render jsonapi:
|
26
|
+
render jsonapi: @<%= singular_table_name %>, status: :created
|
27
27
|
else
|
28
|
-
render jsonapi_errors:
|
28
|
+
render jsonapi_errors: @<%= singular_table_name %>
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
# PATCH/PUT <%= route_url %>/1
|
33
33
|
def update
|
34
34
|
if @<%= singular_table_name %>.update_attributes
|
35
|
-
render jsonapi:
|
35
|
+
render jsonapi: @<%= singular_table_name %>
|
36
36
|
else
|
37
|
-
render jsonapi_errors:
|
37
|
+
render jsonapi_errors: @<%= singular_table_name %>
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -46,10 +46,10 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
46
46
|
private
|
47
47
|
|
48
48
|
# Use callbacks to share common setup or constraints between actions.
|
49
|
-
def set_<%= pundit ? '
|
49
|
+
def set_<%= pundit ? 'and_authorize_' : '' %><%= singular_table_name %>
|
50
50
|
@<%= singular_table_name %> = <%= resource %>.find(params)
|
51
51
|
<% if pundit -%>
|
52
|
-
authorize @<%= singular_table_name
|
52
|
+
authorize @<%= singular_table_name %>.data
|
53
53
|
<% end -%>
|
54
54
|
end
|
55
55
|
|
@@ -61,7 +61,7 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
61
61
|
list = %i[
|
62
62
|
<%= attributes_names.join(' ') %>
|
63
63
|
]
|
64
|
-
params.require(
|
64
|
+
params.require(:data).require(:attributes).permit(*list)
|
65
65
|
<%- end -%>
|
66
66
|
end
|
67
67
|
end
|
@@ -57,6 +57,16 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
|
|
57
57
|
{}
|
58
58
|
}
|
59
59
|
|
60
|
+
<% if pundit -%>
|
61
|
+
before do
|
62
|
+
allow_any_instance_of(GraphitiApiController).to receive(:authorize)
|
63
|
+
.and_return UserAbsence
|
64
|
+
allow_any_instance_of(GraphitiApiController).to receive(:current_user)
|
65
|
+
.and_return(user)
|
66
|
+
allow_any_instance_of(GraphitiApiController).to receive :authenticate_user!
|
67
|
+
end
|
68
|
+
<% end -%>
|
69
|
+
|
60
70
|
<% unless options[:singleton] -%>
|
61
71
|
describe 'GET /index' do
|
62
72
|
it "renders a successful response" do
|
@@ -152,17 +162,17 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
|
|
152
162
|
attributes: new_attributes,
|
153
163
|
}
|
154
164
|
end
|
155
|
-
let(:new_attributes)
|
165
|
+
let(:new_attributes) do
|
156
166
|
skip("Add a hash of attributes valid for <%= class_name %>")
|
157
|
-
{
|
158
|
-
|
167
|
+
{ <%= attribute_name %>: 'New <%= attribute_name %>' }
|
168
|
+
end
|
159
169
|
|
160
170
|
context "with valid parameters" do
|
161
171
|
it "updates the requested <%= file_name %>" do
|
162
172
|
patch_update
|
163
173
|
<%= file_name %>.reload
|
164
174
|
skip("Add assertions for updated state")
|
165
|
-
<%= file_name %>.<%= attribute_name %>
|
175
|
+
expect(<%= file_name %>.<%= attribute_name %>). to eq 'New <%= attribute_name %>'
|
166
176
|
end
|
167
177
|
|
168
178
|
it 'returns :ok' do
|
@@ -0,0 +1,53 @@
|
|
1
|
+
<% prefix = "/api/#{options[:api_version]}" if options[:api] -%>
|
2
|
+
require "rails_helper"
|
3
|
+
|
4
|
+
<% module_namespacing do -%>
|
5
|
+
describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
|
6
|
+
describe "routing" do
|
7
|
+
<% unless options[:singleton] -%>
|
8
|
+
it "routes to #index" do
|
9
|
+
expect(get: "<%= prefix %>/<%= ns_table_name %>")
|
10
|
+
.to route_to "<%= ns_table_name %>#index", "format"=>:jsonapi
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
<% unless options[:api] -%>
|
15
|
+
it "routes to #new" do
|
16
|
+
expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
|
17
|
+
end
|
18
|
+
|
19
|
+
<% end -%>
|
20
|
+
it "routes to #show" do
|
21
|
+
expect(get: "<%= prefix %>/<%= ns_table_name %>/1")
|
22
|
+
.to route_to "<%= ns_table_name %>#show", id: "1", "format"=>:jsonapi
|
23
|
+
end
|
24
|
+
|
25
|
+
<% unless options[:api] -%>
|
26
|
+
it "routes to #edit" do
|
27
|
+
expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
|
28
|
+
end
|
29
|
+
|
30
|
+
<% end -%>
|
31
|
+
|
32
|
+
it "routes to #create" do
|
33
|
+
expect(post: "<%= prefix %>/<%= ns_table_name %>")
|
34
|
+
.to route_to "<%= ns_table_name %>#create", "format"=>:jsonapi
|
35
|
+
end
|
36
|
+
|
37
|
+
it "routes to #update via PUT" do
|
38
|
+
expect(put: "<%= prefix %>/<%= ns_table_name %>/1")
|
39
|
+
.to route_to "<%= ns_table_name %>#update", id: "1", "format"=>:jsonapi
|
40
|
+
end
|
41
|
+
|
42
|
+
it "routes to #update via PATCH" do
|
43
|
+
expect(patch: "<%= prefix %>/<%= ns_table_name %>/1")
|
44
|
+
.to route_to "<%= ns_table_name %>#update", id: "1", "format"=>:jsonapi
|
45
|
+
end
|
46
|
+
|
47
|
+
it "routes to #destroy" do
|
48
|
+
expect(delete: "<%= prefix %>/<%= ns_table_name %>/1")
|
49
|
+
.to route_to "<%= ns_table_name %>#destroy", id: "1", "format"=>:jsonapi
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
<% end -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphiti_scaffold_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Kulikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
The graphiti gem has no support for scaffold generator.
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- lib/graphiti_scaffold_generator/generators/rails/scaffold_controller_generator.rb
|
38
38
|
- lib/graphiti_scaffold_generator/generators/rails/templates/api_controller.rb
|
39
39
|
- lib/graphiti_scaffold_generator/generators/rails/templates/api_request_spec.rb
|
40
|
+
- lib/graphiti_scaffold_generator/generators/rails/templates/routing_spec.rb
|
40
41
|
- lib/graphiti_scaffold_generator/railtie.rb
|
41
42
|
- lib/graphiti_scaffold_generator/version.rb
|
42
43
|
homepage: https://github.com/dima4p/graphiti_scaffold_generator
|