comfy / comfortable-mexican-sofa

ComfortableMexicanSofa is a powerful Ruby on Rails 5.2+ CMS (Content Management System) Engine
MIT License
2.72k stars 637 forks source link

cms_site_detect fails if request is nil #940

Open catmando opened 3 years ago

catmando commented 3 years ago

Expected behavior

cms_site_detect should just return nil if there is no request object

Actual behavior

If there is no rails request object (request == nil) cms_site_detect raises an error

Steps to reproduce

Try it in a server side test spec for example, where perhaps there is no CMS environment. Old behavior (comfy v 1.12 for example) was just to return a blank string when rendering if there was no site. Comfy > v 1.12 no raises an error.

Here is a patch:

module Comfy
  module CmsHelper
    def cms_site_detect
      return nil unless request

      host = request.host_with_port.downcase
      path = request.fullpath
      Comfy::Cms::Site.find_site(host, path)
    end
  end
end

System configuration

CMS version:

1.13