Skip to content

Commit

Permalink
Merge pull request #290 from spree/feature/use_runtime_configuration_…
Browse files Browse the repository at this point in the history
…for_admin_path

Use runtime configuration for admin_path
  • Loading branch information
rafalcymerys authored Nov 27, 2023
2 parents 35809cb + 9b5a58a commit cc15a46
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/_version.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if can?(:admin, current_store) && Spree::Backend::Config[:admin_show_version] %>
<% if can?(:admin, current_store) && Spree::Backend::RuntimeConfig[:admin_show_version] %>
<p
class="spree-version ml-3 my-3"
aria-label="Spree Commerce version">
Expand Down
2 changes: 0 additions & 2 deletions lib/spree/backend/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module Spree
module Backend
class Configuration < Preferences::Configuration
preference :admin_path, :string, default: '/admin'
preference :admin_products_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_orders_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_properties_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_promotions_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_customer_returns_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_users_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_show_version, :boolean, default: true
preference :locale, :string
preference :variants_per_page, :integer, default: Kaminari.config.default_per_page
preference :menus_per_page, :integer, default: Kaminari.config.default_per_page
Expand Down
2 changes: 2 additions & 0 deletions lib/spree/backend/engine.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'configuration'
require_relative 'runtime_configuration'

module Spree
module Backend
Expand All @@ -9,6 +10,7 @@ class Engine < ::Rails::Engine

initializer 'spree.backend.environment', before: :load_config_initializers do |app|
Spree::Backend::Config = Spree::Backend::Configuration.new
Spree::Backend::RuntimeConfig = Spree::Backend::RuntimeConfiguration.new
app.config.spree_backend = Environment.new
end

Expand Down
8 changes: 8 additions & 0 deletions lib/spree/backend/runtime_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Spree
module Backend
class RuntimeConfiguration < ::Spree::Preferences::RuntimeConfiguration
preference :admin_path, :string, default: '/admin'
preference :admin_show_version, :boolean, default: true
end
end
end
4 changes: 2 additions & 2 deletions lib/spree_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
def self.admin_path
Spree::Backend::Config[:admin_path]
Spree::Backend::RuntimeConfig[:admin_path]
end

# Used to configure admin_path for Spree
Expand All @@ -13,6 +13,6 @@ def self.admin_path
# Spree.admin_path = '/custom-path'

def self.admin_path=(path)
Spree::Backend::Config[:admin_path] = path
Spree::Backend::RuntimeConfig[:admin_path] = path
end
end
2 changes: 1 addition & 1 deletion spec/features/admin/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

context 'if turned off' do
before { Spree::Backend::Config[:admin_show_version] = false }
before { Spree::Backend::RuntimeConfig[:admin_show_version] = false }

it 'is not displayed' do
visit spree.admin_path
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/spree/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Spree do
describe '.admin_path' do
it { expect(described_class.admin_path).to eq(Spree::Backend::Config[:admin_path]) }
it { expect(described_class.admin_path).to eq(Spree::Backend::RuntimeConfig[:admin_path]) }
end

describe '.admin_path=' do
Expand All @@ -18,6 +18,6 @@
end

it { expect(described_class.admin_path).to eq(new_admin_path) }
it { expect(Spree::Backend::Config[:admin_path]).to eq(new_admin_path) }
it { expect(Spree::Backend::RuntimeConfig[:admin_path]).to eq(new_admin_path) }
end
end

0 comments on commit cc15a46

Please sign in to comment.