mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 18:19:52 +01:00
Refactor TurboStreamable spec to use an anonymous controller
This commit is contained in:
parent
0aac4caf45
commit
4dc88fe1ef
3 changed files with 28 additions and 22 deletions
|
@ -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
|
||||||
|
|
|
@ -2,31 +2,39 @@
|
||||||
|
|
||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
class TurboStreamableTestController < ApplicationController
|
describe ApplicationController, type: :controller do
|
||||||
include TurboStreamable
|
controller do
|
||||||
|
include TurboStreamable
|
||||||
|
|
||||||
turbo_stream_actions :create, :blocked, :not_found
|
turbo_stream_actions :create, :blocked, :not_found
|
||||||
|
|
||||||
def create
|
def create
|
||||||
params.require :message
|
params.require :message
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.turbo_stream do
|
format.turbo_stream do
|
||||||
render turbo_stream: render_toast("success!")
|
render turbo_stream: render_toast("success!")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def blocked
|
||||||
|
raise Errors::Blocked
|
||||||
|
end
|
||||||
|
|
||||||
|
def not_found
|
||||||
|
raise ActiveRecord::RecordNotFound
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def blocked
|
before do
|
||||||
raise Errors::Blocked
|
routes.draw do
|
||||||
|
get "create" => "anonymous#create"
|
||||||
|
get "blocked" => "anonymous#blocked"
|
||||||
|
get "not_found" => "anonymous#not_found"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_found
|
|
||||||
raise ActiveRecord::RecordNotFound
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe TurboStreamableTestController, type: :controller do
|
|
||||||
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|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue