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
aff5ef79
Commit
aff5ef79
authored
Dec 17, 2019
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix spec generator use resource model name
parent
31a98a9e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
simple_controller_generator.rb
...nerators/simple_controller/simple_controller_generator.rb
+8
-0
spec.rb.tt
lib/generators/simple_controller/templates/specs/spec.rb.tt
+7
-7
No files found.
lib/generators/simple_controller/simple_controller_generator.rb
View file @
aff5ef79
...
@@ -141,6 +141,14 @@ class SimpleControllerGenerator < Rails::Generators::NamedBase
...
@@ -141,6 +141,14 @@ class SimpleControllerGenerator < Rails::Generators::NamedBase
options
.
resource
&
.
singularize
||
resource_class
&
.
model_name
&
.
element
&
.
singularize
options
.
resource
&
.
singularize
||
resource_class
&
.
model_name
&
.
element
&
.
singularize
end
end
def
resource_model_plural
resource_class
&
.
model_name
&
.
plural
end
def
resource_model_singular
resource_class
&
.
model_name
&
.
singular
end
def
resource_collection
def
resource_collection
resource_class
&
.
model_name
&
.
collection
resource_class
&
.
model_name
&
.
collection
end
end
...
...
lib/generators/simple_controller/templates/specs/spec.rb.tt
View file @
aff5ef79
...
@@ -15,15 +15,15 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
...
@@ -15,15 +15,15 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
}
}
}
}
}
}
<%= resource_singular %>_value = FactoryBot.attributes_for(:<%= resource_singular %>)
<%= resource_singular %>_value = FactoryBot.attributes_for(:<%= resource_
model_
singular %>)
before :each do
before :each do
<% if auth.present? -%>
<% if auth.present? -%>
@<%= auth_singular %> = <%= auth %>.register "<%= auth_singular %>", "password"
@<%= auth_singular %> = <%= auth %>.register "<%= auth_singular %>", "password"
@<%= auth_singular %>_token = <%= auth %>.login "<%= auth_singular %>", "password"
@<%= auth_singular %>_token = <%= auth %>.login "<%= auth_singular %>", "password"
<% end -%>
<% end -%>
@<%= resource_singular %>_count = 5
@<%= resource_
model_
singular %>_count = 5
@<%= resource_
plural %> = FactoryBot.create_list(:<%= resource_singular %>, @<%= resource
_singular %>_count)
@<%= resource_
model_plural %> = FactoryBot.create_list(:<%= resource_model_singular %>, @<%= resource_model
_singular %>_count)
end
end
<% @routes.each do | template, path_item | -%>
<% @routes.each do | template, path_item | -%>
...
@@ -50,7 +50,7 @@ resource_singular %>_ref
...
@@ -50,7 +50,7 @@ resource_singular %>_ref
response(<%= response_status action %>, description: 'successful') do
response(<%= response_status action %>, description: 'successful') do
<% path_item[:params].each do |param| -%>
<% path_item[:params].each do |param| -%>
<% if param == 'id' -%>
<% if param == 'id' -%>
let(:<%= param %>) { @<%= resource_plural %>.first.id }
let(:<%= param %>) { @<%= resource_
model_
plural %>.first.id }
<% elsif param.end_with? '_id' -%>
<% elsif param.end_with? '_id' -%>
<% model_name = param.sub('_id', '') -%>
<% model_name = param.sub('_id', '') -%>
let(:<%= param %>) { @<%= model_name %>.id }
let(:<%= param %>) { @<%= model_name %>.id }
...
@@ -71,16 +71,16 @@ resource_singular %>_ref
...
@@ -71,16 +71,16 @@ resource_singular %>_ref
<% elsif details[:summary].start_with?("list") -%>
<% elsif details[:summary].start_with?("list") -%>
it {
it {
body = JSON.parse(response.body)
body = JSON.parse(response.body)
expect(body['<%= resource_plural %>'].count).to eq @<%= resource_singular %>_count
expect(body['<%= resource_plural %>'].count).to eq @<%= resource_
model_
singular %>_count
}
}
<% elsif details[:summary].start_with?("delete") -%>
<% elsif details[:summary].start_with?("delete") -%>
it {
it {
expect(<%= resource_class %>.count).to eq(@<%= resource_singular %>_count-1)
expect(<%= resource_class %>.count).to eq(@<%= resource_
model_
singular %>_count-1)
}
}
<% elsif details[:summary].start_with?("show") -%>
<% elsif details[:summary].start_with?("show") -%>
it {
it {
body = JSON.parse(response.body)
body = JSON.parse(response.body)
<%= resource_singular %> = @<%= resource_plural %>.first
<%= resource_singular %> = @<%= resource_
model_
plural %>.first
<% attributes_names.each do |attr| -%>
<% attributes_names.each do |attr| -%>
expect(body['<%= attr %>']).to eq <%= resource_singular %>.<%= attr %>
expect(body['<%= attr %>']).to eq <%= resource_singular %>.<%= 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