Skip to content

Commit

Permalink
Add missing ':see_other' status code in generated destroy controller …
Browse files Browse the repository at this point in the history
…method (#538)

* Add missing ':see_other' status code when redirecting in the generated destroy controller method

* Mistake

---------

Co-authored-by: David Heinemeier Hansson <[email protected]>
  • Loading branch information
ldeld and dhh authored Sep 14, 2024
1 parent 0adeb96 commit acf44b8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/generators/rails/templates/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def destroy
@<%= orm_instance.destroy %>

respond_to do |format|
format.html { redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %> }
format.html { redirect_to <%= index_helper %>_path, status: :see_other, notice: <%= %("#{human_name} was successfully destroyed.") %> }
format.json { head :no_content }
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/scaffold_controller_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase

assert_instance_method :destroy, content do |m|
assert_match %r{@post\.destroy}, m
assert_match %r{format\.html \{ redirect_to posts_path, notice: "Post was successfully destroyed\." \}}, m
assert_match %r{format\.html \{ redirect_to posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m
assert_match %r{format\.json \{ head :no_content \}}, m
end

Expand All @@ -72,7 +72,7 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
end

assert_instance_method :destroy, content do |m|
assert_match %r{format\.html \{ redirect_to admin_posts_path, notice: "Post was successfully destroyed\." \}}, m
assert_match %r{format\.html \{ redirect_to admin_posts_path, status: :see_other, notice: "Post was successfully destroyed\." \}}, m
end
end
end
Expand Down

0 comments on commit acf44b8

Please sign in to comment.