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
cfb6c84b
Commit
cfb6c84b
authored
7 years ago
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec expect to template
parent
a0d7cf8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
3 deletions
+33
-3
simple_controller_generator.rb
...nerators/simple_controller/simple_controller_generator.rb
+2
-1
spec.rb.tt
lib/generators/simple_controller/templates/specs/spec.rb.tt
+31
-2
No files found.
lib/generators/simple_controller/simple_controller_generator.rb
View file @
cfb6c84b
...
@@ -82,7 +82,8 @@ class SimpleControllerGenerator < Rails::Generators::NamedBase
...
@@ -82,7 +82,8 @@ class SimpleControllerGenerator < Rails::Generators::NamedBase
namespaced_classes
=
controller_class_name
.
split
(
'::'
)
namespaced_classes
=
controller_class_name
.
split
(
'::'
)
namespaced_classes
.
delete_at
(
1
)
namespaced_classes
.
delete_at
(
1
)
namespaced_class
=
namespaced_classes
.
join
(
'::'
).
singularize
namespaced_class
=
namespaced_classes
.
join
(
'::'
).
singularize
namespaced_class
.
constantize
resource_class
=
namespaced_class
.
constantize
raise
NameError
if
resource_class
.
is_a?
Module
rescue
NameError
rescue
NameError
nil
nil
end
end
...
...
This diff is collapsed.
Click to expand it.
lib/generators/simple_controller/templates/specs/spec.rb.tt
View file @
cfb6c84b
...
@@ -23,7 +23,8 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
...
@@ -23,7 +23,8 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
@auth = <%= auth %>.register "auth", "password"
@auth = <%= auth %>.register "auth", "password"
@auth_token = <%= auth %>.login "auth", "password"
@auth_token = <%= auth %>.login "auth", "password"
<% end -%>
<% end -%>
@<%= resource_plural %> = FactoryBot.create_list(:<%= resource_singular %>, 5)
@entity_count = 5
@<%= resource_plural %> = FactoryBot.create_list(:<%= resource_singular %>, @entity_count)
end
end
<% @routes.each do | template, path_item | -%>
<% @routes.each do | template, path_item | -%>
...
@@ -37,7 +38,12 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
...
@@ -37,7 +38,12 @@ RSpec.describe '<%= controller_path %>', type: :request, capture_examples: true,
parameter '<%= param %>', in: :path, type: :string
parameter '<%= param %>', in: :path, type: :string
<% end -%>
<% end -%>
<% path_item[:params].each do |param| -%>
<% path_item[:params].each do |param| -%>
<% if param == 'id' -%>
let(:<%= param %>) { @<%= resource_plural %>.first.id }
let(:<%= param %>) { @<%= resource_plural %>.first.id }
<% elsif param.end_with? '_id' -%>
<% model_name = param.sub('_id', '') -%>
let(:<%= param %>) { @<%= model_name %>.id }
<% end -%>
<% end -%>
<% end -%>
<% end -%>
<% end -%>
...
@@ -55,7 +61,30 @@ resource_singular.upcase %>_REF
...
@@ -55,7 +61,30 @@ resource_singular.upcase %>_REF
end
end
<% end -%>
<% end -%>
response(<%= response_status action %>, description: 'successful') do
response(<%= response_status action %>, description: 'successful') do
# it { p JSON.parse(response.body) }
<% if details[:summary].start_with?("create") -%>
it {
body = JSON.parse(response.body)
<% attributes_names.each do |attr| -%>
expect(body['<%= attr %>']).to eq <%= resource_singular.upcase %>_VALUE[:<%= attr %>]
<% end -%>
}
<% elsif details[:summary].start_with?("list") -%>
it {
body = JSON.parse(response.body)
expect(body['<%= resource_plural %>'].count).to eq @entity_count
}
<% elsif details[:summary].start_with?("delete") -%>
it {
expect(<%= resource_class %>.count).to eq(@entity_count-1)
}
<% elsif details[:summary].start_with?("show") -%>
it {
body = JSON.parse(response.body)
<% attributes_names.each do |attr| -%>
expect(body['<%= attr %>']).to eq <%= resource_singular.upcase %>_VALUE[:<%= attr %>]
<% end -%>
}
<% end -%>
end
end
end
end
<% end -%>
<% end -%>
...
...
This diff is collapsed.
Click to expand it.
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