refactored DomainConstraint and conference_controller_spec
use params id instead of OSEM_HOSTNAME to load conference
This commit is contained in:
parent
66b48be968
commit
835859e350
3 changed files with 18 additions and 9 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
class ConferencesController < ApplicationController
|
class ConferencesController < ApplicationController
|
||||||
protect_from_forgery with: :null_session
|
protect_from_forgery with: :null_session
|
||||||
before_action :respond_to_options
|
before_action :respond_to_options
|
||||||
load_and_authorize_resource find_by: :short_title
|
load_and_authorize_resource find_by: :short_title, except: :show
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc)
|
@current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc)
|
||||||
|
|
@ -9,15 +9,19 @@ class ConferencesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
# have to change "localhost" to ENV['OSEM_HOSTNAME'] in production
|
@conference = if params[:id]
|
||||||
check_custom_domain if request.host != 'localhost'
|
Conference.find_by_short_title(params[:id])
|
||||||
|
else
|
||||||
|
load_conference_by_domain
|
||||||
|
end
|
||||||
|
authorize! :show, @conference
|
||||||
@program = @conference.program
|
@program = @conference.program
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_custom_domain
|
def load_conference_by_domain
|
||||||
@conference = @conference.nil? ? Conference.find_by(custom_domain: request.domain) : @conference
|
Conference.find_by(custom_domain: request.domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_to_options
|
def respond_to_options
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class DomainConstraint
|
class DomainConstraint
|
||||||
def self.matches?(request)
|
def self.matches?(request)
|
||||||
@domains = Conference.pluck(:custom_domain).compact
|
domains = Conference.where.not(custom_domain: nil).pluck(:custom_domain)
|
||||||
@domains.include?(request.domain)
|
domains.include?(request.domain)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -23,12 +23,17 @@ describe ConferencesController do
|
||||||
get :show, id: conference.short_title
|
get :show, id: conference.short_title
|
||||||
expect(response).to render_template :show
|
expect(response).to render_template :show
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it 'assigns correct conference from a custom domain' do
|
context 'accessing conference via custom domain' do
|
||||||
|
before do
|
||||||
conference.update_attribute(:custom_domain, 'lvh.me')
|
conference.update_attribute(:custom_domain, 'lvh.me')
|
||||||
@request.host = 'lvh.me'
|
@request.host = 'lvh.me'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'assigns correct conference' do
|
||||||
get :show
|
get :show
|
||||||
|
|
||||||
expect(response).to render_template :show
|
expect(response).to render_template :show
|
||||||
expect(assigns(:conference)).to eq conference
|
expect(assigns(:conference)).to eq conference
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue