Skip to content

Commit 3420a83

Browse files
committed
Fix dynamic settings with falsy values
1 parent 6be535a commit 3420a83

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/settingslogic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def create_accessors!
158158
# http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/
159159
def create_accessor_for(key, val=nil)
160160
return unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval
161-
instance_variable_set("@#{key}", val) if val
161+
instance_variable_set("@#{key}", val)
162162
self.class.class_eval <<-EndEval
163163
def #{key}
164164
return @#{key} if @#{key}

spec/settingslogic_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ class NoSource < Settingslogic; end
126126
Settings.language['some-dash-setting#'].should == 'dashtastic'
127127
end
128128

129+
it "should handle settings with nil value" do
130+
Settings["flag"] = true
131+
Settings["flag"] = nil
132+
Settings.flag.should == nil
133+
end
134+
135+
it "should handle settings with false value" do
136+
Settings["flag"] = true
137+
Settings["flag"] = false
138+
Settings.flag.should == false
139+
end
140+
129141
it "should support instance usage as well" do
130142
settings = SettingsInst.new(Settings.source)
131143
settings.setting1.setting1_child.should == "saweet"

0 commit comments

Comments
 (0)