From 36f9e5682777512da1936ee6d3f872553dce151f Mon Sep 17 00:00:00 2001 From: Kim Burgestrand Date: Mon, 27 Nov 2023 10:43:01 +0100 Subject: [PATCH] Add failing test for rendering explicit template This is documented in e.g: https://guides.rubyonrails.org/layouts_and_rendering.html#rendering-an-action-s-template-from-another-controller --- spec/internal/app/controllers/articles_controller.rb | 4 ++++ spec/internal/app/views/articles/preview_view.rb | 7 +++++++ spec/internal/config/routes.rb | 1 + spec/layout_spec.rb | 6 ++++++ 4 files changed, 18 insertions(+) create mode 100644 spec/internal/app/views/articles/preview_view.rb diff --git a/spec/internal/app/controllers/articles_controller.rb b/spec/internal/app/controllers/articles_controller.rb index e051da06..6a6e73e4 100644 --- a/spec/internal/app/controllers/articles_controller.rb +++ b/spec/internal/app/controllers/articles_controller.rb @@ -8,4 +8,8 @@ def index end def show; end + + def preview + render Articles::PreviewView + end end diff --git a/spec/internal/app/views/articles/preview_view.rb b/spec/internal/app/views/articles/preview_view.rb new file mode 100644 index 00000000..7ae2b990 --- /dev/null +++ b/spec/internal/app/views/articles/preview_view.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class Articles::PreviewView < Phlex::HTML + def template + render(template: "articles/show") + end +end diff --git a/spec/internal/config/routes.rb b/spec/internal/config/routes.rb index 8d573aa9..9aa73534 100644 --- a/spec/internal/config/routes.rb +++ b/spec/internal/config/routes.rb @@ -9,4 +9,5 @@ get "articles/index", to: "articles#index" get "articles/show", to: "articles#show" + get "articles/preview", to: "articles#preview" end diff --git a/spec/layout_spec.rb b/spec/layout_spec.rb index 95f049ef..200c48f1 100644 --- a/spec/layout_spec.rb +++ b/spec/layout_spec.rb @@ -14,4 +14,10 @@ expect(response.body).to eq %(Article
\n

Article

\n
) end + + it "supports rendering templates" do + get "/articles/preview" + + expect(response.body).to eq %(Article
\n

Article

\n
) + end end