Refactor TurboStreamable spec to use an anonymous controller

This commit is contained in:
Andreas Nedbal 2023-02-12 01:12:52 +01:00 committed by Andreas Nedbal
parent 0aac4caf45
commit 4dc88fe1ef
3 changed files with 28 additions and 22 deletions

View file

@ -171,11 +171,5 @@ Rails.application.routes.draw do
get "/nodeinfo/2.1", to: "well_known/node_info#nodeinfo", as: :node_info get "/nodeinfo/2.1", to: "well_known/node_info#nodeinfo", as: :node_info
if Rails.env.test?
get "turbo_streamable" => "turbo_streamable_test#create"
get "turbo_streamable_blocked" => "turbo_streamable_test#blocked"
get "turbo_streamable_not_found" => "turbo_streamable_test#not_found"
end
puts "processing time of routes.rb: #{"#{(Time.zone.now - start).round(3).to_s.ljust(5, '0')}s".light_green}" puts "processing time of routes.rb: #{"#{(Time.zone.now - start).round(3).to_s.ljust(5, '0')}s".light_green}"
end end

View file

@ -2,7 +2,8 @@
require "rails_helper" require "rails_helper"
class TurboStreamableTestController < ApplicationController describe ApplicationController, type: :controller do
controller do
include TurboStreamable include TurboStreamable
turbo_stream_actions :create, :blocked, :not_found turbo_stream_actions :create, :blocked, :not_found
@ -26,7 +27,14 @@ class TurboStreamableTestController < ApplicationController
end end
end end
describe TurboStreamableTestController, type: :controller do before do
routes.draw do
get "create" => "anonymous#create"
get "blocked" => "anonymous#blocked"
get "not_found" => "anonymous#not_found"
end
end
render_views render_views
shared_examples_for "it returns a toast as Turbo Stream response" do |action, message| shared_examples_for "it returns a toast as Turbo Stream response" do |action, message|

View file

@ -60,6 +60,10 @@ RSpec.configure do |config|
# arbitrary gems may also be filtered via: # arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name") # config.filter_gems_from_backtrace("gem name")
# anonymous controllers will infer ApplicationController instead of the
# described class
config.infer_base_class_for_anonymous_controllers = false
config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :helper config.include Devise::Test::ControllerHelpers, type: :helper
end end