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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
14 deletions
+12
-14
spec.rb.tt
lib/generators/simple_controller/templates/specs/spec.rb.tt
+12
-14
No files found.
lib/generators/simple_controller/templates/specs/spec.rb.tt
View file @
a105dda0
require 'swagger_helper'
<%= resource_singular.upcase %>_REF = {
RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true, tags: ["<%= controller_class_path.join(' ') %>"] do
<%= resource_singular %>_ref = {
type: :object, properties: {
<%= resource_singular %>: {
type: :object, properties: {
<% if resource_class&.columns_hash.present? -%>
<% resource_class.columns_hash.except('id', 'created_at', 'updated_at').values.each do |column| -%>
<% if resource_class&.columns_hash.present? -%>
<% resource_class.columns_hash.except('id', 'created_at', 'updated_at').values.each do |column| -%>
<%= column.name %>: { type: :<%= column.type %>, description: '' },
<% end -%>
<% end -%>
<% end -%>
<% end -%>
}
}
}
}
<%= resource_singular.upcase %>_VALUE = FactoryBot.attributes_for(:<%=
resource_singular %>)
}
<%= resource_singular %>_value = FactoryBot.attributes_for(:<%= resource_singular %>)
RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true, tags: ["<%= controller_class_path.join(' ') %>"] do
before :each do
<% if auth.present? -%>
@auth = <%= auth %>.register "auth", "password"
...
...
@@ -55,9 +53,9 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
<% if ['post', 'patch'].include? action -%>
parameter :<%= resource_singular %>, in: :body, schema: <%=
resource_singular
.upcase %>_REF
resource_singular
%>_ref
let(:<%= resource_singular %>) do
{ <%= resource_singular %>: <%= resource_singular
.upcase %>_VALUE
}
{ <%= resource_singular %>: <%= resource_singular
%>_value
}
end
<% end -%>
response(<%= response_status action %>, description: 'successful') do
...
...
@@ -65,7 +63,7 @@ resource_singular.upcase %>_REF
it {
body = JSON.parse(response.body)
<% 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 -%>
}
<% elsif details[:summary].start_with?("list") -%>
...
...
@@ -81,7 +79,7 @@ resource_singular.upcase %>_REF
it {
body = JSON.parse(response.body)
<% 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 -%>
...
...
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