From cac5f7672b1148505df956543e94641e7850dc29 Mon Sep 17 00:00:00 2001 From: Mattia Roccoberton Date: Sun, 5 Apr 2026 16:35:31 +0200 Subject: [PATCH] fix: Settings: preserve auth class when calling reset! --- lib/tiny_admin/settings.rb | 6 ++++- spec/features/standalone_spec.rb | 42 ++++++++++++++++++++++++++++++++ spec/rails_helper.rb | 5 ++++ spec/spec_helper.rb | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 spec/features/standalone_spec.rb diff --git a/lib/tiny_admin/settings.rb b/lib/tiny_admin/settings.rb index ed3b9b0..84b43ed 100644 --- a/lib/tiny_admin/settings.rb +++ b/lib/tiny_admin/settings.rb @@ -91,7 +91,11 @@ def load_settings end def reset! - @options = {} + saved_authorization_class = @options ? @options[:authorization_class] : nil + @options = { + sections: [], + authorization_class: saved_authorization_class + } @store = nil @loaded = false end diff --git a/spec/features/standalone_spec.rb b/spec/features/standalone_spec.rb new file mode 100644 index 0000000..ac93cd7 --- /dev/null +++ b/spec/features/standalone_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +RSpec.describe "Standalone TinyAdmin::Settings" do + subject(:settings) { TinyAdmin::Settings.instance } + + let(:app) { TinyAdmin::Router } + + describe "#root=" do + it "stores and returns the root hash" do + settings.root = { title: "Admin", content: "Some content" } + expect(settings.root).to include(title: "Admin") + end + end + + describe "#sections=" do + it "stores a list of section hashes" do + sections = [{ slug: "a", name: "A", type: "content", content: "" }] + settings.sections = sections + expect(settings.sections).to eq(sections) + end + + it "defaults to an empty collection when not set" do + settings.reset! + expect(settings.sections).to be_empty + end + end + + describe "#authentication=" do + it "accepts a plugin hash" do + settings.authentication = { plugin: TinyAdmin::Plugins::NoAuth } + expect(settings.authentication[:plugin]).to eq(TinyAdmin::Plugins::NoAuth) + end + end + + describe "#reset" do + it "clears previously set values" do + settings.root = { title: "Before reset" } + settings.reset! + expect(settings.root).to be_nil + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f55ec4e..85e21ef 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -29,4 +29,9 @@ config.include_context "with some data" config.include_context "Capybara helpers" + + config.before(:each, type: :feature) do + TinyAdmin.settings.reset! + TinyAdmin.configure_from_file(Rails.root.join("config/tiny_admin.yml")) + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 68cd170..d99f68f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require "pry" require "simplecov" +require "tiny_admin" SimpleCov.start do enable_coverage :branch