Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

Fix dynamic settings with falsy values
  • Loading branch information...
commit ea15363811fad493c90596007b592ed0d7322ae2 2 parents 184afc7 + 3420a83
@binarylogic 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
@@ -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
12 spec/settingslogic_spec.rb
@@ -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"
Please sign in to comment.
Something went wrong with that request. Please try again.