From 53130397f50b27c73cdcfacc0ce53133dc20db3b Mon Sep 17 00:00:00 2001
From: Zee <50284+zspencer@users.noreply.github.com>
Date: Fri, 3 Mar 2023 15:22:55 -0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20`Space`:=20`SpacesController#sho?=
=?UTF-8?q?w`=20works=20with=20`BYODomain`=20(#1178)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- https://github.com/zinc-collective/convene/issues/74
I introduced this bug in b65a233c4d98c1304a744deb522aa75c8b451a13,
basically the `SpaceController#show` was not finding by domain, so it
would give an empty page.
This also adds support for using
[`assert_select`](http://api.rubyonrails.org/classes/ActionDispatch/IntegrationTest.html)
in request specs, so long as the `subject` is a `TestResponse`.
---
app/controllers/spaces_controller.rb | 2 ++
app/views/layouts/application.html.erb | 2 +-
app/views/spaces/show.html.erb | 2 +-
spec/rails_helper.rb | 1 +
.../spaces_controller_request_spec.rb | 29 ++++++++++++++++---
spec/support/dom_helpers.rb | 16 ++++++++++
6 files changed, 46 insertions(+), 6 deletions(-)
create mode 100644 spec/support/dom_helpers.rb
diff --git a/app/controllers/spaces_controller.rb b/app/controllers/spaces_controller.rb
index 7e9d911fd..97a680225 100644
--- a/app/controllers/spaces_controller.rb
+++ b/app/controllers/spaces_controller.rb
@@ -60,6 +60,8 @@ def space_params
policy_scope(Space).friendly.find(params[:id])
elsif params[:space]
policy_scope(Space).new(space_params)
+ elsif BrandedDomainConstraint.new(space_repository).space_for_request(request).present?
+ BrandedDomainConstraint.new(space_repository).space_for_request(request)
else
policy_scope(Space).new
end.tap do |space|
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 7e4ea34d7..9a23fa5e2 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -12,7 +12,7 @@
<%= render 'layouts/header' %>
-
+
<%= yield %>
diff --git a/app/views/spaces/show.html.erb b/app/views/spaces/show.html.erb
index 60c728e1f..dc4cd40bc 100644
--- a/app/views/spaces/show.html.erb
+++ b/app/views/spaces/show.html.erb
@@ -2,4 +2,4 @@
<%- if space.entrance.present? %>
<%= render space.entrance %>
-<%- end %>
\ No newline at end of file
+<%- end %>
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index 8ee9bb0f3..918de011b 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -63,6 +63,7 @@
# config.filter_gems_from_backtrace("gem name")
config.include(AuthHelpers, type: :request)
+ config.include(DomHelpers, type: :request)
config.include ViewComponent::TestHelpers, type: :component
end
diff --git a/spec/requests/spaces_controller_request_spec.rb b/spec/requests/spaces_controller_request_spec.rb
index d76876fce..d4dce0e13 100644
--- a/spec/requests/spaces_controller_request_spec.rb
+++ b/spec/requests/spaces_controller_request_spec.rb
@@ -2,17 +2,38 @@
require "swagger_helper"
-RSpec.describe SpacesController, type: :request do
+RSpec.describe SpacesController do
include ActiveJob::TestHelper
describe "#show" do
+ subject(:perform_request) do
+ get url
+ test_response
+ end
+
+ let(:space) { create(:space) }
+ let(:url) { polymorphic_url(space) }
+
+ it { is_expected.to be_ok }
+ specify { perform_request && assert_select("##{dom_id(space)}") }
+
context "with a branded domain" do
let(:space) { create(:space, branded_domain: "beta.example.com") }
- it "redirects to the domain" do
- get polymorphic_path(space)
+ context "when accessing via the neighborhood url" do
+ it { is_expected.to redirect_to "http://beta.example.com" }
+ end
+
+ context "when accessing via domain" do
+ before do
+ space
+ host! "beta.example.com"
+ end
+
+ let(:url) { "http://beta.example.com" }
- expect(response).to redirect_to "http://beta.example.com"
+ it { is_expected.to be_ok }
+ specify { perform_request && assert_select("##{dom_id(space)}") }
end
end
end
diff --git a/spec/support/dom_helpers.rb b/spec/support/dom_helpers.rb
new file mode 100644
index 000000000..08e25f8c5
--- /dev/null
+++ b/spec/support/dom_helpers.rb
@@ -0,0 +1,16 @@
+module DomHelpers
+ def record_identifier
+ ActionView::RecordIdentifier
+ end
+ delegate :dom_id, to: :record_identifier
+
+ def test_response
+ TestResponse.new(response)
+ end
+
+ class TestResponse < SimpleDelegator
+ def media_type?(expected_media_type)
+ media_type == Mime[expected_media_type]
+ end
+ end
+end