Skip to content

Commit 25b5481

Browse files
committed
Fix for inheritable settings in initializer
When trying to set inheritable settings on a namespace that was already initialized, the block would not be run. In the end, this just meant that you couldn't update settings on the default namespace. This fixes the issue and adds specs to ensure it won't happen again.
1 parent 0bb1cc7 commit 25b5481

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

lib/active_admin/application.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,17 @@ def register(resource, options = {}, &block)
113113
# @returns [Namespace] the new or existing namespace
114114
def find_or_create_namespace(name)
115115
name ||= :root
116-
return namespaces[name] if namespaces[name]
117-
namespace = Namespace.new(self, name)
118-
namespaces[name] = namespace
119-
ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
116+
117+
if namespaces[name]
118+
namespace = namespaces[name]
119+
else
120+
namespace = Namespace.new(self, name)
121+
namespaces[name] = namespace
122+
ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
123+
end
124+
120125
yield(namespace) if block_given?
126+
121127
namespace
122128
end
123129

spec/unit/application_spec.rb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,8 @@
9393
end
9494
end
9595

96-
describe "adding an inheritable setting" do
97-
98-
it "should add a setting to Application and Namespace" do
99-
ActiveAdmin::Application.inheritable_setting :inheritable_setting, "inheritable_setting"
100-
app = ActiveAdmin::Application.new
101-
app.inheritable_setting.should == "inheritable_setting"
102-
ns = ActiveAdmin::Namespace.new(app, :admin)
103-
ns.inheritable_setting.should == "inheritable_setting"
104-
end
105-
106-
end
96+
describe "#namespace (or #find_or_create_namespace)" do
10797

108-
describe "#namespace" do
10998
it "should yield a new namespace" do
11099
application.namespace :new_namespace do |ns|
111100
ns.name.should == :new_namespace
@@ -114,9 +103,16 @@
114103

115104
it "should return an instantiated namespace" do
116105
admin = application.find_or_create_namespace :admin
117-
application.namespace :admin do |ns|
118-
ns.should == admin
119-
end
106+
admin.should == application.namespaces[:admin]
107+
end
108+
109+
it "should yield an existing namespace" do
110+
expect {
111+
application.namespace :admin do |ns|
112+
ns.should == application.namespaces[:admin]
113+
raise "found"
114+
end
115+
}.to raise_error("found")
120116
end
121117
end
122118

0 commit comments

Comments
 (0)