Permalink
Browse files

Merge pull request #41 from ebeigarts/fix-falsy-settings

Fix dynamic settings with falsy values
  • Loading branch information...
2 parents 184afc7 + 3420a83 commit ea15363811fad493c90596007b592ed0d7322ae2 @binarylogic committed Dec 30, 2012
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/settingslogic.rb
  2. +12 −0 spec/settingslogic_spec.rb
View
@@ -163,7 +163,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
@@ -130,6 +130,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"

0 comments on commit ea15363

Please sign in to comment.