diff --git a/app/constraints/domain_constraint.rb b/app/constraints/domain_constraint.rb new file mode 100644 index 000000000..2d4aebf74 --- /dev/null +++ b/app/constraints/domain_constraint.rb @@ -0,0 +1,7 @@ +class DomainConstraint + def matches?(request) + return false unless request.domain + + !Rails.configuration.events_hosts.match?(request.domain) + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8261c8030..6314d84d4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -116,10 +116,6 @@ def require_event end end - def require_website - redirect_to not_found_path and return unless current_website - end - def require_proposal @proposal = @event.proposals.find_by!(uuid: params[:proposal_uuid] || params[:uuid]) end diff --git a/config/application.rb b/config/application.rb index fd4266936..822cb66c3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -26,5 +26,9 @@ class Application < Rails::Application config.active_record.time_zone_aware_types = [:datetime] config.active_job.queue_adapter = :sidekiq + + config.events_hosts = ENV.fetch('EVENTS_HOSTS') do + 'localhost,example.com,herokuapp.com' + end end end diff --git a/config/initializers/domain_constraint.rb b/config/initializers/domain_constraint.rb deleted file mode 100644 index f5f113f56..000000000 --- a/config/initializers/domain_constraint.rb +++ /dev/null @@ -1,5 +0,0 @@ -class DomainConstraint - def matches?(request) - Website.domain_match(request.domain).exists? - end -end diff --git a/spec/features/website/configuration_spec.rb b/spec/features/website/configuration_spec.rb index 0b9f10d97..a45c5436e 100644 --- a/spec/features/website/configuration_spec.rb +++ b/spec/features/website/configuration_spec.rb @@ -20,9 +20,11 @@ website = create(:website, event: event) home_page = create(:page, website: website) - visit("/#{home_page.slug}") + with_domain('lvh.me') do + visit("/#{home_page.slug}") - expect(current_path).to eq(not_found_path) + expect(current_path).to eq(not_found_path) + end login_as(organizer) visit event_path(website.event) @@ -30,7 +32,7 @@ expect(page).to have_content("Edit Website") - fill_in('Domains', with: 'www.example.com') + fill_in('Domains', with: 'lvh.me') fill_in('Navigation links', with: "Home\n") click_on("Save") @@ -38,13 +40,15 @@ logout - visit("/#{home_page.slug}") + with_domain('lvh.me') do + visit("/#{home_page.slug}") - expect(page).to have_content(strip_tags(home_page.published_body)) + expect(page).to have_content(strip_tags(home_page.published_body)) - click_on(home_page.name, match: :first) + click_on(home_page.name, match: :first) - expect(current_path).to eq("/#{home_page.slug}") + expect(current_path).to eq("/#{home_page.slug}") + end end scenario "Organizer fails to add font file correctly", :js do diff --git a/spec/features/website/page_viewing_spec.rb b/spec/features/website/page_viewing_spec.rb index 35f74bb6a..ffbe1b2fa 100644 --- a/spec/features/website/page_viewing_spec.rb +++ b/spec/features/website/page_viewing_spec.rb @@ -20,25 +20,27 @@ expect(page).to have_content('Home Content') end - context 'when using a custom domain' do - scenario 'Public views the landing page from custom domain' do - website.update(domains: 'www.example.com') + scenario 'Public views the landing page from custom domain', js: true do + with_domain('lvh.me') do + website.update(domains: 'www.lvh.me') create(:page, published_body: 'Home Content', landing: true) visit root_path expect(page).to have_content('Home Content') end + end - scenario 'Public views the landing page for an older website on custom domain' do - website.update(domains: 'www.example.com') + scenario 'Public views the landing page for an older website on custom domain', js: true do + with_domain('lvh.me') do + website.update(domains: 'www.lvh.me') old_home_page = create(:page, published_body: 'Old Website', landing: true) website.update(navigation_links: [old_home_page.slug]) - new_website = create(:website, domains: 'www.example.com') + new_website = create(:website, domains: 'www.lvh.me') new_home_page = create(:page, - website: new_website, - published_body: 'New Website', - landing: true) + website: new_website, + published_body: 'New Website', + landing: true) new_website.update(navigation_links: [new_home_page.slug]) visit root_path @@ -53,12 +55,12 @@ click_on(old_home_page.name, match: :first) expect(page).to have_content('Old Website') end + end - scenario 'Public gets not found message for wrong path on subdomain' do - website.update(domains: 'www.example.com') + scenario 'Public gets not found message for wrong path on subdomain' do + website.update(domains: 'www.example.com') - visit landing_path(slug: website.event.slug) - expect(page).to have_content("Page Not Found") - end + visit landing_path(slug: website.event.slug) + expect(page).to have_content("Page Not Found") end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 692c78f28..cb8da395e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -93,3 +93,5 @@ def save_timestamped_screenshot(page) page.save_screenshot(screenshot_path) end + +Capybara.always_include_port = true diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 4b4eadeb2..17dddb62a 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -1,7 +1,9 @@ require 'support/helpers/session_helpers' require 'support/helpers/form_helpers' +require 'support/helpers/domain_helpers' RSpec.configure do |config| config.include Features::SessionHelpers, type: :feature config.include Features::FormHelpers, type: :feature + config.include Features::DomainHelpers, type: :feature end diff --git a/spec/support/helpers/domain_helpers.rb b/spec/support/helpers/domain_helpers.rb new file mode 100644 index 000000000..0107ed3a8 --- /dev/null +++ b/spec/support/helpers/domain_helpers.rb @@ -0,0 +1,12 @@ +module Features + module DomainHelpers + def with_domain(host) + original_host = Capybara.app_host + Capybara.app_host = "http://#{host}" + yield + ensure + Capybara.app_host = original_host + end + end +end + diff --git a/spec/support/helpers/session_helpers.rb b/spec/support/helpers/session_helpers.rb index 98b9250c9..9b14a3883 100644 --- a/spec/support/helpers/session_helpers.rb +++ b/spec/support/helpers/session_helpers.rb @@ -21,6 +21,5 @@ def forgot_password(email) fill_in 'user_email', with: email click_button 'Send me reset password instructions' end - end end