From c4bab02f9055d5e1d92a0e4f58eece6a6dfe9404 Mon Sep 17 00:00:00 2001 From: kiyoto-akazawa Date: Wed, 10 Sep 2025 15:06:11 +0900 Subject: [PATCH 1/2] test: Add test cases for different action and template names --- test/dummy_app/app/controllers/api/posts_controller.rb | 6 ++++++ test/dummy_app/config/routes.rb | 1 + test/features/action_controller_api_test.rb | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/test/dummy_app/app/controllers/api/posts_controller.rb b/test/dummy_app/app/controllers/api/posts_controller.rb index 3722553..a0f0a9b 100644 --- a/test/dummy_app/app/controllers/api/posts_controller.rb +++ b/test/dummy_app/app/controllers/api/posts_controller.rb @@ -8,6 +8,12 @@ class PostsController < ActionController::API def show(id) @post = Post.find id end + + def renamed_show(id) + @post = Post.find id + + render :show + end end end end diff --git a/test/dummy_app/config/routes.rb b/test/dummy_app/config/routes.rb index f95f929..87c4299 100644 --- a/test/dummy_app/config/routes.rb +++ b/test/dummy_app/config/routes.rb @@ -20,6 +20,7 @@ if Rails::VERSION::MAJOR >= 5 namespace :api do resources :posts, only: :show + get '/renamed_posts/:id', to: 'posts#renamed_show' end end # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html diff --git a/test/features/action_controller_api_test.rb b/test/features/action_controller_api_test.rb index 76871f0..cb72c13 100644 --- a/test/features/action_controller_api_test.rb +++ b/test/features/action_controller_api_test.rb @@ -12,6 +12,14 @@ class ActionControllerAPITest < ActionDispatch::IntegrationTest assert_equal json, { 'title' => 'post 1' } end + + test 'The renamed template correctly renders a JSON' do + get '/api/renamed_posts/1.json' + + json = response.parsed_body + + assert_equal json, { 'title' => 'post 1' } + end end end From bcdbbc7909f71db7c10bf013fd80a770d49a5a6c Mon Sep 17 00:00:00 2001 From: kiyoto-akazawa Date: Wed, 10 Sep 2025 16:07:51 +0900 Subject: [PATCH 2/2] fix: Fix MissingTemplate error after Rails 8 upgrade --- lib/simple_json/simple_json_renderable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_json/simple_json_renderable.rb b/lib/simple_json/simple_json_renderable.rb index eaff277..c583e63 100644 --- a/lib/simple_json/simple_json_renderable.rb +++ b/lib/simple_json/simple_json_renderable.rb @@ -29,7 +29,7 @@ def render_to_body(options) # use super when any of [:body, :plain, :html] exist in options return super if self.class::RENDER_FORMATS_IN_PRIORITY.any? { |key| options.key? key } - template_name = template_name(options[:template] || action_name) + template_name = template_name(options[:template] || options[:action] || action_name) if options.key?(:json) process_options(options) @rendered_format = 'application/json; charset=utf-8'