Skip to content

Support chages to show_helper in Rails 7 #2833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
@@ -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"
@@ -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
2 changes: 1 addition & 1 deletion lib/generators/rspec/scaffold/templates/edit_spec.rb
Original file line number Diff line number Diff line change
@@ -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 %>]"
1 change: 1 addition & 0 deletions spec/generators/rspec/scaffold/scaffold_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -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