diff options
author | Jerry Cheung <jollyjerry@gmail.com> | 2013-02-12 15:55:41 -0800 |
---|---|---|
committer | Jerry Cheung <jollyjerry@gmail.com> | 2013-02-12 15:55:41 -0800 |
commit | 58ebe3393263355cd714490d86192741d26a34d2 (patch) | |
tree | 3b3c1ec93b40eac97873748faa56f1a5bc897cc7 | |
parent | 5c598156c7a2cb38bab9d00cb6d9ed04e431611d (diff) | |
parent | f2090d35e764c640d9436eeefd015717f2df05c9 (diff) | |
download | hashie-58ebe3393263355cd714490d86192741d26a34d2.tar.gz |
Merge pull request #63 from ohrite/dash_default
Fix Hashie::Dash Defaults
-rw-r--r-- | lib/hashie/dash.rb | 6 | ||||
-rw-r--r-- | spec/hashie/dash_spec.rb | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/hashie/dash.rb b/lib/hashie/dash.rb index 34228c7..bdc256d 100644 --- a/lib/hashie/dash.rb +++ b/lib/hashie/dash.rb @@ -90,7 +90,11 @@ module Hashie super(&block) self.class.defaults.each_pair do |prop, value| - self[prop] = value + self[prop] = begin + value.dup + rescue TypeError + value + end end initialize_attributes(attributes) diff --git a/spec/hashie/dash_spec.rb b/spec/hashie/dash_spec.rb index 5922a3f..1267651 100644 --- a/spec/hashie/dash_spec.rb +++ b/spec/hashie/dash_spec.rb @@ -22,6 +22,10 @@ class Subclassed < DashTest property :last_name, :required => true end +class DashDefaultTest < Hashie::Dash + property :aliases, :default => ["Snake"] +end + describe DashTest do subject { DashTest.new(:first_name => 'Bob', :email => 'bob@example.com') } @@ -120,6 +124,12 @@ describe DashTest do expect { DashTest.new }.to raise_error(ArgumentError) end + it "does not overwrite default values" do + obj1 = DashDefaultTest.new + obj1.aliases << "El Rey" + obj2 = DashDefaultTest.new + obj2.aliases.should_not include "El Rey" + end end describe 'properties' do |