Skip to content

Commit cac5f76

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

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
describe "#root=" do
9+
it "stores and returns the root hash" do
10+
settings.root = { title: "Admin", content: "Some content" }
11+
expect(settings.root).to include(title: "Admin")
12+
end
13+
end
14+
15+
describe "#sections=" do
16+
it "stores a list of section hashes" do
17+
sections = [{ slug: "a", name: "A", type: "content", content: "" }]
18+
settings.sections = sections
19+
expect(settings.sections).to eq(sections)
20+
end
21+
22+
it "defaults to an empty collection when not set" do
23+
settings.reset!
24+
expect(settings.sections).to be_empty
25+
end
26+
end
27+
28+
describe "#authentication=" do
29+
it "accepts a plugin hash" do
30+
settings.authentication = { plugin: TinyAdmin::Plugins::NoAuth }
31+
expect(settings.authentication[:plugin]).to eq(TinyAdmin::Plugins::NoAuth)
32+
end
33+
end
34+
35+
describe "#reset" do
36+
it "clears previously set values" do
37+
settings.root = { title: "Before reset" }
38+
settings.reset!
39+
expect(settings.root).to be_nil
40+
end
41+
end
42+
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)