Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix dynamic settings with falsy values

  • Loading branch information...
commit 3420a8310f24468ec28920502ba382b1da46c3f2 1 parent 6be535a
@ebeigarts ebeigarts authored
Showing with 13 additions and 1 deletion.
  1. +1 −1  lib/settingslogic.rb
  2. +12 −0 spec/settingslogic_spec.rb
View
2  lib/settingslogic.rb
@@ -158,7 +158,7 @@ def create_accessors!
# http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/
def create_accessor_for(key, val=nil)
return unless key.to_s =~ /^\w+$/ # could have "some-setting:" which blows up eval
- instance_variable_set("@#{key}", val) if val
+ instance_variable_set("@#{key}", val)
self.class.class_eval <<-EndEval
def #{key}
return @#{key} if @#{key}
View
12 spec/settingslogic_spec.rb
@@ -126,6 +126,18 @@ class NoSource < Settingslogic; end
Settings.language['some-dash-setting#'].should == 'dashtastic'
end
+ it "should handle settings with nil value" do
+ Settings["flag"] = true
+ Settings["flag"] = nil
+ Settings.flag.should == nil
+ end
+
+ it "should handle settings with false value" do
+ Settings["flag"] = true
+ Settings["flag"] = false
+ Settings.flag.should == false
+ end
+
it "should support instance usage as well" do
settings = SettingsInst.new(Settings.source)
settings.setting1.setting1_child.should == "saweet"
Please sign in to comment.
Something went wrong with that request. Please try again.