Skip to content

Commit 47852ac

Browse files
committed
fix: Settings: preserve auth class when calling reset!
1 parent 6beee64 commit 47852ac

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

lib/tiny_admin/settings.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ def load_settings
9191
end
9292

9393
def reset!
94-
@options = {}
94+
saved_authorization_class = @options ? @options[:authorization_class] : nil
95+
@options = {
96+
sections: [],
97+
authorization_class: saved_authorization_class
98+
}
9599
@store = nil
96100
@loaded = false
97101
end

spec/features/standalone_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.describe "Standalone TinyAdmin::Settings" do
4+
subject(:settings) { TinyAdmin::Settings.instance }
5+
6+
let(:app) { TinyAdmin::Router }
7+
8+
# Convenience: merge additional settings on top of the baseline.
9+
def configure(&block)
10+
TinyAdmin.configure(&block)
11+
end
12+
13+
describe "#root=" do
14+
it "stores and returns the root hash" do
15+
settings.root = { title: "Admin", content: "Some content" }
16+
expect(settings.root).to include(title: "Admin")
17+
end
18+
end
19+
20+
describe "#sections=" do
21+
it "stores a list of section hashes" do
22+
sections = [{ slug: "a", name: "A", type: "content", content: "" }]
23+
settings.sections = sections
24+
expect(settings.sections).to eq(sections)
25+
end
26+
27+
it "defaults to an empty collection when not set" do
28+
settings.reset!
29+
expect(settings.sections).to be_empty
30+
end
31+
end
32+
33+
describe "#authentication=" do
34+
it "accepts a plugin hash" do
35+
settings.authentication = { plugin: TinyAdmin::Plugins::NoAuth }
36+
expect(settings.authentication[:plugin]).to eq(TinyAdmin::Plugins::NoAuth)
37+
end
38+
end
39+
40+
describe "#reset" do
41+
it "clears previously set values" do
42+
settings.root = { title: "Before reset" }
43+
settings.reset!
44+
expect(settings.root).to be_nil
45+
end
46+
end
47+
end

spec/rails_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@
2929

3030
config.include_context "with some data"
3131
config.include_context "Capybara helpers"
32+
33+
config.before(:each, type: :feature) do
34+
TinyAdmin.settings.reset!
35+
TinyAdmin.configure_from_file(Rails.root.join("config/tiny_admin.yml"))
36+
end
3237
end

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require "pry"
44
require "simplecov"
5+
require "tiny_admin"
56

67
SimpleCov.start do
78
enable_coverage :branch

0 commit comments

Comments
 (0)