Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/generators/rspec/scaffold/scaffold_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Rspec
module Generators
# @private
class ScaffoldGenerator < Base
class ScaffoldGenerator < Base # rubocop:disable Metrics/ClassLength
include ::Rails::Generators::ResourceHelpers
source_paths << File.expand_path('../helper/templates', __dir__)
argument :attributes, type: :array, default: [], banner: "field:type field:type"
Expand Down Expand Up @@ -128,8 +128,14 @@ def banner
self.class.banner
end

def show_helper(resource_name = file_name)
"#{singular_route_name}_url(#{resource_name})"
if Rails::VERSION::STRING.to_f < 7.0
def show_helper(resource_name = file_name, type: :url)
"#{singular_route_name}_#{type}(#{resource_name})"
end
else
def show_helper(arg = file_name, type: :url)
super
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it "renders the edit <%= ns_file_name %> form" do
render

assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(<%= singular_table_name %>), "post" do
assert_select "form[action=?][method=?]", <%= show_helper(singular_table_name, type: :path) %>, "post" do
<% for attribute in output_attributes -%>
<%- name = attribute.respond_to?(:column_name) ? attribute.column_name : attribute.name %>
assert_select "<%= attribute.input_type -%>[name=?]", "<%= ns_file_name %>[<%= name %>]"
Expand Down
1 change: 1 addition & 0 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
expect(filename).to contain(/require 'rails_helper'/)
.and(contain(/^RSpec.describe "(.*)\/edit", #{type_metatag(:view)}/))
.and(contain(/assign\(:post, post\)/))
.and(contain(/assert_select "form\[action=\?\]\[method=\?\]", post_path\(post\), "post" do/))
.and(contain(/it "renders the edit (.*) form"/))
end
end
Expand Down