Skip to content

Commit e697a1e

Browse files
committed
Update request spec scaffold template
Currently, when scaffolds are generated inside a Rails Engine, it generates requests specs that fail without modification. This happens because the Engine routes are not mounted under Rails.application. To fix this, Engine routes have to be included so that url and path helpers can be usable from within the spec file.
1 parent 5d76f46 commit e697a1e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/generators/rspec/scaffold/templates/request_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
1717
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
1818
# adjust the attributes here as well.
19+
<% if mountable_engine? -%>
20+
include Engine.routes.url_helpers
21+
22+
<% end -%>
23+
1924
let(:valid_attributes) {
2025
skip("Add a hash of attributes valid for your model")
2126
}

0 commit comments

Comments
 (0)