Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
simple_controller
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
simple_controller
Commits
a105dda0
Commit
a105dda0
authored
Jan 07, 2018
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use variable instead of static
parent
2e68c016
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
18 deletions
+16
-18
spec.rb.tt
lib/generators/simple_controller/templates/specs/spec.rb.tt
+16
-18
No files found.
lib/generators/simple_controller/templates/specs/spec.rb.tt
View file @
a105dda0
require 'swagger_helper'
require 'swagger_helper'
<%= resource_singular.upcase %>_REF = {
RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true, tags: ["<%= controller_class_path.join(' ') %>"] do
type: :object, properties: {
<%= resource_singular %>_ref = {
<%= resource_singular %>: {
type: :object, properties: {
type: :object, properties: {
<%= resource_singular %>: {
<% if resource_class&.columns_hash.present? -%>
type: :object, properties: {
<% resource_class.columns_hash.except('id', 'created_at', 'updated_at').values.each do |column| -%>
<% if resource_class&.columns_hash.present? -%>
<%= column.name %>: { type: :<%= column.type %>, description: '' },
<% resource_class.columns_hash.except('id', 'created_at', 'updated_at').values.each do |column| -%>
<% end -%>
<%= column.name %>: { type: :<%= column.type %>, description: '' },
<% end -%>
<% end -%>
<% end -%>
}
}
}
}
}
}
}
}
<%= resource_singular %>_value = FactoryBot.attributes_for(:<%= resource_singular %>)
<%= resource_singular.upcase %>_VALUE = FactoryBot.attributes_for(:<%=
resource_singular %>)
RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true, tags: ["<%= controller_class_path.join(' ') %>"] do
before :each do
before :each do
<% if auth.present? -%>
<% if auth.present? -%>
@auth = <%= auth %>.register "auth", "password"
@auth = <%= auth %>.register "auth", "password"
...
@@ -55,9 +53,9 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
...
@@ -55,9 +53,9 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
<% if ['post', 'patch'].include? action -%>
<% if ['post', 'patch'].include? action -%>
parameter :<%= resource_singular %>, in: :body, schema: <%=
parameter :<%= resource_singular %>, in: :body, schema: <%=
resource_singular
.upcase %>_REF
resource_singular
%>_ref
let(:<%= resource_singular %>) do
let(:<%= resource_singular %>) do
{ <%= resource_singular %>: <%= resource_singular
.upcase %>_VALUE
}
{ <%= resource_singular %>: <%= resource_singular
%>_value
}
end
end
<% end -%>
<% end -%>
response(<%= response_status action %>, description: 'successful') do
response(<%= response_status action %>, description: 'successful') do
...
@@ -65,7 +63,7 @@ resource_singular.upcase %>_REF
...
@@ -65,7 +63,7 @@ resource_singular.upcase %>_REF
it {
it {
body = JSON.parse(response.body)
body = JSON.parse(response.body)
<% attributes_names.each do |attr| -%>
<% attributes_names.each do |attr| -%>
expect(body['<%= attr %>']).to eq <%= resource_singular
.upcase %>_VALUE
[:<%= attr %>]
expect(body['<%= attr %>']).to eq <%= resource_singular
%>_value
[:<%= attr %>]
<% end -%>
<% end -%>
}
}
<% elsif details[:summary].start_with?("list") -%>
<% elsif details[:summary].start_with?("list") -%>
...
@@ -81,7 +79,7 @@ resource_singular.upcase %>_REF
...
@@ -81,7 +79,7 @@ resource_singular.upcase %>_REF
it {
it {
body = JSON.parse(response.body)
body = JSON.parse(response.body)
<% attributes_names.each do |attr| -%>
<% attributes_names.each do |attr| -%>
expect(body['<%= attr %>']).to eq <%= resource_singular
.upcase %>_VALUE
[:<%= attr %>]
expect(body['<%= attr %>']).to eq <%= resource_singular
%>_value
[:<%= attr %>]
<% end -%>
<% end -%>
}
}
<% end -%>
<% end -%>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment