Permalink
Browse files

name was returning "" instead of nil when not set

  • Loading branch information...
1 parent 9276b0d commit 1b0252045ab19afa63229bd4333e3a1ddafab8a6 Mark Evans committed Dec 19, 2011
Showing with 11 additions and 3 deletions.
  1. +1 −0 lib/dragonfly/hash_with_name.rb
  2. +10 −3 spec/dragonfly/hash_with_name_spec.rb
@@ -22,6 +22,7 @@ def []=(key, value)
attr_accessor :basename, :ext
def name
+ return nil unless basename || ext
[basename, ext].compact.join('.')
end
@@ -7,19 +7,26 @@
end
describe "name" do
- before(:each) do
- @hash[:name] = 'long.pigs'
+ it "should default to nil" do
+ @hash[:name].should be_nil
end
- it "should allow reading via normal hash access" do
+ it "should allow setting via normal hash access" do
+ @hash[:name] = 'long.pigs'
@hash[:name].should == 'long.pigs'
end
it "should allow reading via an accessor" do
+ @hash[:name] = 'long.pigs'
@hash.name.should == 'long.pigs'
end
it "should allow setting via an accessor" do
@hash.name = 'john.doe'
@hash[:name].should == 'john.doe'
end
+ it "should allow setting to nil" do
+ @hash[:name] = 'long.pigs'
+ @hash[:name] = nil
+ @hash[:name].should be_nil
+ end
end
describe "ext" do

0 comments on commit 1b02520

Please sign in to comment.