graphiti_scaffold_generator 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe50af1227fbf67ae6966ebdc03b8d61ed12fc9bcc9aaa08137a93df3845fb73
4
- data.tar.gz: 05e51a9ace3926e919aa34248f238736495f2768e5c67fb99fa590431fe7b69c
3
+ metadata.gz: d2718e44766428effbfed02407b623b01cbcd17ecd046ce3da9b3284fe6302dc
4
+ data.tar.gz: 565bcc3aaa7933d18c34971203cb93220de791b6f1a1d788f4a8f67f7bfd4ea4
5
5
  SHA512:
6
- metadata.gz: 14cfcd09d212a2658df7be76d8d20543b85a516fb373475785f2d21e837e7c8efd8ae151d413bb323b99dddd29130c9d41bdff45a1bd1d636dec0048017409d4
7
- data.tar.gz: ecb3429e7e30718baa38955bf64a45d913b7b559ce9e96bb2d99dc2e2df99fe8e85ffded52fa63f99a581f27cd77c1806495556a8405a040ffb7e14fcbe5a1b4
6
+ metadata.gz: 7248f258a895f6f0229ddaa43f299d7195aa4830c4c3ca37e8c134c8a934b4b7cd0d3b257b8d5229ade79ed20cae82a6b2067ef57e2948e4995f09a81a865133
7
+ data.tar.gz: bfc15159d09c2b6e16cf1e2d4603dd0514070032a74b667be4646c9f8670797af36b4ce3711f4a8785576dbf72bd04a9b7d7811a3c7e304cef028f81eeb79b80
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphiti_scaffold_generator (0.1.2)
4
+ graphiti_scaffold_generator (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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
@@ -9,12 +9,12 @@ require 'spec_helper'
9
9
  <% module_namespacing do -%>
10
10
  describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
11
11
  <% if fbot -%>
12
- let(:<%= file_name %>) { create :<%= file_name %> }
12
+ let(:<%= singular_name %>) { create :<%= singular_name %> }
13
13
  <% if pundit -%>
14
14
  let(:user) { create :user }
15
15
  <% end -%>
16
16
  <% else -%>
17
- let(:<%= file_name %>) { <%= class_name %>.create! valid_attributes }
17
+ let(:<%= singular_name %>) { <%= class_name %>.create! valid_attributes }
18
18
  <% end -%>
19
19
 
20
20
  # This should return the minimal set of attributes required to create a valid
@@ -27,7 +27,7 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
27
27
  <% attribute_name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name -%>
28
28
  <% if links.present? -%>
29
29
  let(:valid_attributes) do
30
- attributes_for(:<%=file_name%>)
30
+ attributes_for(:<%=singular_name%>)
31
31
  .slice(*%i[<%= attribute_name %>])
32
32
  .merge(
33
33
  <% links.each do |relation| -%>
@@ -36,7 +36,7 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
36
36
  )
37
37
  end
38
38
  <% else -%>
39
- let(:valid_attributes) {attributes_for(:<%=file_name%>).slice *%i[<%= attribute_name %>]}
39
+ let(:valid_attributes) {attributes_for(:<%=singular_name%>).slice *%i[<%= attribute_name %>]}
40
40
  <% end -%>
41
41
  <% else -%>
42
42
  let(:valid_attributes) {
@@ -69,21 +69,51 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
69
69
 
70
70
  <% unless options[:singleton] -%>
71
71
  describe 'GET /index' do
72
+ subject(:get_index) do
73
+ get <%= plural_name %>_url, headers: valid_headers, as: :json
74
+ end
75
+
76
+ before do
77
+ <%= singular_name %>
78
+ end
79
+
72
80
  it "renders a successful response" do
73
- <%= class_name %>.create! valid_attributes
74
- get <%= index_helper %>_url, headers: valid_headers, as: :json
81
+ get_index
75
82
  expect(response).to be_successful
76
83
  end
84
+
85
+ it 'renders content_type "application/vnd.api+json; charset=utf-8"' do
86
+ get_index
87
+ expect(response.content_type).to eq("application/vnd.api+json; charset=utf-8")
88
+ end
89
+
90
+ it "renders a JSON response with an Array of UserAbsences" do
91
+ get_index
92
+ expect(JSON.parse(response.body)['data']).to be_an Array
93
+ expect(JSON.parse(response.body)['data'].first['id']).to eq <%= singular_name %>.id
94
+ end
77
95
  end
78
96
  <% end -%>
79
97
 
80
98
  describe 'GET /show' do
81
- subject(:get_show) { get <%= show_helper %> }
99
+ subject(:get_show) do
100
+ get <%= singular_name %>_url(<%= singular_name %>), headers: valid_headers, as: :json
101
+ end
82
102
 
83
103
  it "renders a successful response" do
84
104
  get_show
85
105
  expect(response).to be_successful
86
106
  end
107
+
108
+ it 'renders content_type "application/vnd.api+json; charset=utf-8"' do
109
+ get_show
110
+ expect(response.content_type).to eq("application/vnd.api+json; charset=utf-8")
111
+ end
112
+
113
+ it "renders a JSON response with the requested <%= singular_name %>" do
114
+ get_show
115
+ expect(JSON.parse(response.body)['data']['id']).to eq <%= singular_name %>.id
116
+ end
87
117
  end
88
118
 
89
119
  describe 'POST /create' do
@@ -116,7 +146,7 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
116
146
  expect(response.content_type).to eq("application/vnd.api+json; charset=utf-8")
117
147
  end
118
148
 
119
- it "renders a JSON response with the new <%= file_name %>" do
149
+ it "renders a JSON response with the new <%= singular_name %>" do
120
150
  post_create
121
151
  expect(JSON.parse(response.body)['data']['id'])
122
152
  .to eq <%= class_name %>.order(:created_at).last.id
@@ -140,7 +170,7 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
140
170
  expect(response.content_type).to eq("application/vnd.api+json; charset=utf-8")
141
171
  end
142
172
 
143
- it 'renders a JSON response with errors for the new <%= file_name %>' do
173
+ it 'renders a JSON response with errors for the new <%= singular_name %>' do
144
174
  post_create
145
175
  expect(JSON.parse(response.body).dig 'errors', 0, 'meta', 'attribute')
146
176
  .to be_present
@@ -150,29 +180,29 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
150
180
 
151
181
  describe 'PATCH /update' do
152
182
  subject(:patch_update) do
153
- patch <%= file_name %>_url(<%= file_name %>),
183
+ patch <%= singular_name %>_url(<%= singular_name %>),
154
184
  params: { data: data },
155
185
  headers: valid_headers,
156
186
  as: :json
157
187
  end
158
188
  let(:data) do
159
189
  {
160
- id: <%= file_name %>.id.to_s,
161
- type: '<%= file_name %>s',
190
+ id: <%= singular_name %>.id.to_s,
191
+ type: '<%= singular_name %>s',
162
192
  attributes: new_attributes,
163
193
  }
164
194
  end
165
195
  let(:new_attributes) do
166
196
  skip("Add a hash of attributes valid for <%= class_name %>")
167
- { <%= attribute_name %>: 'New <%= attribute_name %>' }
197
+ { <%= attribute_name %>: 'New <%= attribute_name %>' }
168
198
  end
169
199
 
170
200
  context "with valid parameters" do
171
- it "updates the requested <%= file_name %>" do
201
+ it "updates the requested <%= singular_name %>" do
172
202
  patch_update
173
- <%= file_name %>.reload
203
+ <%= singular_name %>.reload
174
204
  skip("Add assertions for updated state")
175
- <%= file_name %>.<%= attribute_name %> == 'New <%= attribute_name %>'
205
+ expect(<%= singular_name %>.<%= attribute_name %>). to eq 'New <%= attribute_name %>'
176
206
  end
177
207
 
178
208
  it 'returns :ok' do
@@ -185,17 +215,17 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
185
215
  expect(response.content_type).to eq("application/vnd.api+json; charset=utf-8")
186
216
  end
187
217
 
188
- it "renders a JSON response with the <%= file_name %>" do
218
+ it "renders a JSON response with the <%= singular_name %>" do
189
219
  patch_update
190
- expect(JSON.parse(response.body)['data']['id']).to eq <%= file_name %>.id
220
+ expect(JSON.parse(response.body)['data']['id']).to eq <%= singular_name %>.id
191
221
  end
192
222
  end
193
223
 
194
224
  context "with invalid parameters" do
195
225
  let(:new_attributes) { invalid_attributes }
196
226
 
197
- it "does not update the requested <%= file_name %>" do
198
- expect { patch_update }.not_to change <%= file_name %>, :reload
227
+ it "does not update the requested <%= singular_name %>" do
228
+ expect { patch_update }.not_to change <%= singular_name %>, :reload
199
229
  end
200
230
 
201
231
  it 'returns :unprocessable_entity' do
@@ -208,7 +238,7 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
208
238
  expect(response.content_type).to eq("application/vnd.api+json; charset=utf-8")
209
239
  end
210
240
 
211
- it "renders a JSON response with errors for the new <%= file_name %>" do
241
+ it "renders a JSON response with errors for the new <%= singular_name %>" do
212
242
  patch_update
213
243
  expect(JSON.parse(response.body).dig 'errors', 0, 'meta', 'attribute')
214
244
  .to be_present
@@ -218,14 +248,14 @@ describe "Request /<%= name.underscore.pluralize %>", <%= type_metatag(:request)
218
248
 
219
249
  describe "DELETE /destroy" do
220
250
  subject(:delete_destroy) do
221
- delete <%= file_name %>_url(id: <%= file_name %>.to_param)
251
+ delete <%= singular_name %>_url(id: <%= singular_name %>.to_param)
222
252
  end
223
253
 
224
254
  before do
225
- <%= file_name %> # we need something to destroy
255
+ <%= singular_name %> # we need something to destroy
226
256
  end
227
257
 
228
- it "destroys the requested <%= file_name %>" do
258
+ it "destroys the requested <%= singular_name %>" do
229
259
  expect { delete_destroy }.to change(<%= class_name %>, :count).by -1
230
260
  end
231
261
 
@@ -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 -%>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GraphitiScaffoldGenerator
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  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.2
4
+ version: 0.1.4
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-21 00:00:00.000000000 Z
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
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
62
  requirements: []
62
- rubygems_version: 3.1.4
63
+ rubygems_version: 3.4.12
63
64
  signing_key:
64
65
  specification_version: 4
65
66
  summary: When gem 'graphiti' is in use generates code for app/resources and /spec/resources