diff --git a/app/models/alchemy/element.rb b/app/models/alchemy/element.rb index fe6a74f00c..d66f38afff 100644 --- a/app/models/alchemy/element.rb +++ b/app/models/alchemy/element.rb @@ -101,7 +101,7 @@ class Element < BaseRecord scope :excluded, ->(names) { where.not(name: names) } scope :fixed, -> { where(fixed: true) } scope :unfixed, -> { where(fixed: false) } - scope :from_current_site, -> { where(Language.table_name => {site_id: Current.site || Site.default}).joins(page: "language") } + scope :from_current_site, -> { where(Language.table_name => {site_id: Current.site}).joins(page: "language") } scope :folded, -> { where(folded: true) } scope :expanded, -> { where(folded: false) } scope :not_nested, -> { where(parent_element_id: nil) } diff --git a/app/models/alchemy/page/page_scopes.rb b/app/models/alchemy/page/page_scopes.rb index 9a3700f5bb..fbe42cd27e 100644 --- a/app/models/alchemy/page/page_scopes.rb +++ b/app/models/alchemy/page/page_scopes.rb @@ -98,7 +98,7 @@ module PageScopes # scope :from_current_site, -> { - where(Language.table_name => {site_id: Current.site || Site.default}).joins(:language) + where(Language.table_name => {site_id: Current.site}).joins(:language) } # All pages for xml sitemap diff --git a/app/models/alchemy/site.rb b/app/models/alchemy/site.rb index da8837c7d8..807c90b783 100644 --- a/app/models/alchemy/site.rb +++ b/app/models/alchemy/site.rb @@ -69,15 +69,14 @@ def current end deprecate current: :"Alchemy::Current.site", deprecator: Alchemy::Deprecation - def default - Site.first - end + alias_method :default, :first + deprecate default: :first, deprecator: Alchemy::Deprecation def find_for_host(host) # These are split up into two separate queries in order to run the # fastest query first (selecting the domain by its primary host name). # - find_by(host: host) || find_in_aliases(host) || default + find_by(host: host) || find_in_aliases(host) || first end def find_in_aliases(host) diff --git a/lib/alchemy/seeder.rb b/lib/alchemy/seeder.rb index 580489faee..fa9e8828c6 100644 --- a/lib/alchemy/seeder.rb +++ b/lib/alchemy/seeder.rb @@ -31,7 +31,7 @@ def try_seed_pages log "There are already pages present in your database. " \ "Please use `rake db:reset' if you want to rebuild your database.", :skip else - create_default_site! unless Alchemy::Site.default + create_default_site! unless Alchemy::Site.first create_default_language! unless Alchemy::Language.default seed_pages if contentpages.present? seed_layoutpages if layoutpages.present? @@ -126,7 +126,7 @@ def create_default_language! page_layout: default_language["page_layout"], public: true, default: true, - site: Alchemy::Site.default + site: Alchemy::Site.first ) else raise DefaultLanguageNotFoundError diff --git a/lib/alchemy/test_support/factories/language_factory.rb b/lib/alchemy/test_support/factories/language_factory.rb index bb976016f9..a26fb5a830 100644 --- a/lib/alchemy/test_support/factories/language_factory.rb +++ b/lib/alchemy/test_support/factories/language_factory.rb @@ -10,7 +10,7 @@ public { true } - site { Alchemy::Site.default || create(:alchemy_site, :default) } + site { Alchemy::Site.first || create(:alchemy_site, :default) } trait :klingon do name { "Klingon" } diff --git a/spec/features/admin/site_select_feature_spec.rb b/spec/features/admin/site_select_feature_spec.rb index 50a22fde28..af219c61f7 100644 --- a/spec/features/admin/site_select_feature_spec.rb +++ b/spec/features/admin/site_select_feature_spec.rb @@ -30,8 +30,8 @@ %w[admin_pages_path admin_layoutpages_path admin_languages_path].each do |module_path| visit send(module_path) expect(page).to have_select("change_site", - options: [Alchemy::Site.default.name, a_site.name], - selected: Alchemy::Site.default.name) + options: [Alchemy::Site.first.name, a_site.name], + selected: Alchemy::Site.first.name) end end end @@ -48,7 +48,7 @@ context "when site id is not found" do it "stores the default site in session" do visit admin_pages_path(site_id: "") - expect(page).to have_select("change_site", selected: Alchemy::Site.default.name) + expect(page).to have_select("change_site", selected: Alchemy::Site.first.name) end end end diff --git a/spec/helpers/alchemy/pages_helper_spec.rb b/spec/helpers/alchemy/pages_helper_spec.rb index 6ef5c0c9fa..80f28572e0 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -22,7 +22,7 @@ module Alchemy end describe "#render_site_layout" do - let(:default_site) { Alchemy::Site.default } + let(:default_site) { Alchemy::Site.first } it "renders the partial for current site" do expect(helper).to receive(:current_alchemy_site).and_return(default_site) diff --git a/spec/models/alchemy/site_spec.rb b/spec/models/alchemy/site_spec.rb index 20836011e5..3270bad6f8 100644 --- a/spec/models/alchemy/site_spec.rb +++ b/spec/models/alchemy/site_spec.rb @@ -28,29 +28,11 @@ module Alchemy end end - describe ".default" do - subject { Site.default } - - context "when no default site is present" do - before do - Site.delete_all - end - - it { is_expected.to be nil } - end - - context "when default site is present" do - it "returns it" do - is_expected.to eq(Site.default) - end - end - end - describe ".find_for_host" do # No need to create a default site, as it has already been added through the seeds. # But let's add some more: # - let(:default_site) { Site.default } + let(:default_site) { Site.first } let!(:magiclabs_site) { create(:alchemy_site, host: "www.magiclabs.de", aliases: "magiclabs.de magiclabs.com www.magiclabs.com") } subject { Site.find_for_host(host) } diff --git a/spec/requests/alchemy/admin/site_requests_spec.rb b/spec/requests/alchemy/admin/site_requests_spec.rb index 2cd5abcf1c..3c2826a544 100644 --- a/spec/requests/alchemy/admin/site_requests_spec.rb +++ b/spec/requests/alchemy/admin/site_requests_spec.rb @@ -9,7 +9,7 @@ context "a site with host" do let!(:site) { create(:alchemy_site, :public, host: "alchemy-cms.com") } - let(:another_site) { Alchemy::Site.default } + let(:another_site) { Alchemy::Site.first } context "in params" do it "loads dashboard of another site by id and stores it in the session" do