Commit 794a03be91f732fef7519894dd5866853cc91189
Exists in
master
Merge pull request #19 from goosetav/master
fix for issue #11 - ZenTest conflict with .name property of Settingslogic class
Showing
2 changed files
with
18 additions
and
1 deletions
Show diff stats
lib/settingslogic.rb
... | ... | @@ -7,7 +7,7 @@ class Settingslogic < Hash |
7 | 7 | |
8 | 8 | class << self |
9 | 9 | def name # :nodoc: |
10 | - instance.key?("name") ? instance.name : super | |
10 | + self.superclass != Hash && instance.key?("name") ? instance.name : super | |
11 | 11 | end |
12 | 12 | |
13 | 13 | # Enables Settings.get('nested.key.name') for dynamic access | ... | ... |
spec/settingslogic_spec.rb
... | ... | @@ -137,9 +137,26 @@ describe "Settingslogic" do |
137 | 137 | Settings.get('setting1.deep.child.value').should == 2 |
138 | 138 | end |
139 | 139 | |
140 | + # If .name is not a property, delegate to superclass | |
141 | + it "should respond with Module.name" do | |
142 | + Settings2.name.should == "Settings2" | |
143 | + end | |
144 | + | |
145 | + # If .name is called on Settingslogic itself, handle appropriately | |
146 | + # by delegating to Hash | |
147 | + it "should have the parent class always respond with Module.name" do | |
148 | + Settingslogic.name.should == 'Settingslogic' | |
149 | + end | |
150 | + | |
151 | + # If .name is a property, respond with that instead of delegating to superclass | |
152 | + it "should allow a name setting to be overriden" do | |
153 | + Settings.name.should == 'test' | |
154 | + end | |
155 | + | |
140 | 156 | # Put this test last or else call to .instance will load @instance, |
141 | 157 | # masking bugs. |
142 | 158 | it "should be a hash" do |
143 | 159 | Settings.send(:instance).should be_is_a(Hash) |
144 | 160 | end |
161 | + | |
145 | 162 | end | ... | ... |