Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/tiny_admin/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions spec/features/standalone_spec.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "pry"
require "simplecov"
require "tiny_admin"

SimpleCov.start do
enable_coverage :branch
Expand Down
Loading