Skip to content

Commit

Permalink
Deprecate Site.default
Browse files Browse the repository at this point in the history
This is an alias for `Site.first`. Use that instead.
  • Loading branch information
tvdeyen committed Jan 20, 2024
1 parent 2f7de75 commit 70fe1ea
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/models/alchemy/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/page/page_scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions app/models/alchemy/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/alchemy/seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/test_support/factories/language_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
6 changes: 3 additions & 3 deletions spec/features/admin/site_select_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 1 addition & 19 deletions spec/models/alchemy/site_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/alchemy/admin/site_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 70fe1ea

Please sign in to comment.