Permalink
Browse files

Fix dynamic settings with falsy values

  • Loading branch information...
ebeigarts committed Oct 25, 2012
1 parent 6be535a commit 3420a8310f24468ec28920502ba382b1da46c3f2
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/settingslogic.rb
  2. +12 −0 spec/settingslogic_spec.rb
View
@@ -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
@@ -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"

0 comments on commit 3420a83

Please sign in to comment.