graphiti_scaffold_generator 0.1.1 → 0.1.2
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/templates/api_controller.rb +9 -9
- data/lib/graphiti_scaffold_generator/generators/rails/templates/api_request_spec.rb +12 -2
- data/lib/graphiti_scaffold_generator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe50af1227fbf67ae6966ebdc03b8d61ed12fc9bcc9aaa08137a93df3845fb73
|
4
|
+
data.tar.gz: 05e51a9ace3926e919aa34248f238736495f2768e5c67fb99fa590431fe7b69c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14cfcd09d212a2658df7be76d8d20543b85a516fb373475785f2d21e837e7c8efd8ae151d413bb323b99dddd29130c9d41bdff45a1bd1d636dec0048017409d4
|
7
|
+
data.tar.gz: ecb3429e7e30718baa38955bf64a45d913b7b559ce9e96bb2d99dc2e2df99fe8e85ffded52fa63f99a581f27cd77c1806495556a8405a040ffb7e14fcbe5a1b4
|
data/Gemfile.lock
CHANGED
@@ -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,10 +162,10 @@ 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
167
|
{ <%= attribute_name %>: 'New <%= attribute_name %>' }
|
158
|
-
|
168
|
+
end
|
159
169
|
|
160
170
|
context "with valid parameters" do
|
161
171
|
it "updates the requested <%= file_name %>" do
|