Refactor TurboStreamable spec to use an anonymous controller
This commit is contained in:
parent
0aac4caf45
commit
4dc88fe1ef
|
@ -171,11 +171,5 @@ Rails.application.routes.draw do
|
|||
|
||||
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}"
|
||||
end
|
||||
|
|
|
@ -2,31 +2,39 @@
|
|||
|
||||
require "rails_helper"
|
||||
|
||||
class TurboStreamableTestController < ApplicationController
|
||||
include TurboStreamable
|
||||
describe ApplicationController, type: :controller do
|
||||
controller do
|
||||
include TurboStreamable
|
||||
|
||||
turbo_stream_actions :create, :blocked, :not_found
|
||||
turbo_stream_actions :create, :blocked, :not_found
|
||||
|
||||
def create
|
||||
params.require :message
|
||||
def create
|
||||
params.require :message
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
render turbo_stream: render_toast("success!")
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
render turbo_stream: render_toast("success!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def blocked
|
||||
raise Errors::Blocked
|
||||
end
|
||||
|
||||
def not_found
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
def blocked
|
||||
raise Errors::Blocked
|
||||
before do
|
||||
routes.draw do
|
||||
get "create" => "anonymous#create"
|
||||
get "blocked" => "anonymous#blocked"
|
||||
get "not_found" => "anonymous#not_found"
|
||||
end
|
||||
end
|
||||
|
||||
def not_found
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
describe TurboStreamableTestController, type: :controller do
|
||||
render_views
|
||||
|
||||
shared_examples_for "it returns a toast as Turbo Stream response" do |action, message|
|
||||
|
|
|
@ -60,6 +60,10 @@ RSpec.configure do |config|
|
|||
# arbitrary gems may also be filtered via:
|
||||
# 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: :helper
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue