Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Space: SpacesController#show works with BYODomain #1178

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/controllers/spaces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body>
<%= render 'layouts/header' %>

<main>
<main id="<%= current_space.present? ? dom_id(current_space) : nil %>">
<%= yield %>
</main>

Expand Down
2 changes: 1 addition & 1 deletion app/views/spaces/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

<%- if space.entrance.present? %>
<%= render space.entrance %>
<%- end %>
<%- end %>
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions spec/requests/spaces_controller_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions spec/support/dom_helpers.rb
Original file line number Diff line number Diff line change
@@ -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